【问题标题】:Testcontainers with a company proxy带有公司代理的测试容器
【发布时间】:2018-11-25 04:18:02
【问题描述】:

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

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

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

【问题讨论】:

    标签: java docker http-proxy testcontainers docker-java


    【解决方案1】:

    您可以在构建映像或运行容器时指定环境变量。例如,下面我通过传递代理配置来构建一个 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"
      }
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      • 2023-03-29
      相关资源
      最近更新 更多