gpt4 book ai didi

java - 带有公司代理的测试容器

转载 作者:行者123 更新时间:2023-11-29 04:18:22 25 4
gpt4 key购买 nike

每次启动不同的测试容器都会抛出 com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"Get https://quay.io/v1/_ping: dial tcp x.x.x.x: getsockopt:连接被拒绝”

这并不奇怪(docker 在公司代理后面)。如何配置测试容器以使用特定的 HTTP 代理?

另一种方法是禁用“ping”命令并​​使用我们公司的 docker 存储库。

最佳答案

您可以在构建镜像或运行容器时指定环境变量。例如,下面我通过传递代理配置来构建 Elasticsearch 容器:

GenericContainer container = new GenericContainer("docker.elastic.co/elasticsearch/elasticsearch:6.1.1")
.withExposedPorts(9200)
.withEnv("discovery.type", "single-node")
.withEnv("HTTP_PROXY", "http://127.0.0.1:3001")
.withEnv("HTTPS_PROXY", "http://127.0.0.1:3001")
.waitingFor(Wait.forHttp("/_cat/health?v&pretty")
.forStatusCode(200));

否则,您可以在 docker 中全局设置代理设置。对于带有 docker 机器的 Windows,您必须连接到它和 boot2docker 配置文件中的 HTTP 代理。

docker-machine ssh default

sudo -s

echo "export HTTP_PROXY=http://your.proxy" >> /var/lib/boot2docker/profile
echo "export HTTPS_PROXY=http://your.proxy" >> /var/lib/boot2docker/profile

在 Linux 上,您可以创建一个文件 ~/.docker/config.json 如下:

{
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}

关于java - 带有公司代理的测试容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50873544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com