简体   繁体   中英

docker-compose build and http_proxy

I want to test ELK. It works fine BUt when I want to do a

docker-compose up

behind a proxy

docker-compose up --no-recreate 
Building kibana
Step 1 : FROM kibana:latest
 ---> 544887fbfa30
Step 2 : RUN apt-get update && apt-get install -y netcat
 ---> Running in 794342b9d807

It failed

W: Some index files failed to download. They have been ignored, or old ones used instead.

Is' OK with

docker build  --build-arg  http_proxy=http://proxy:3128  --build-arg https_proxy=http://proxy:3128 kibana

But when I redo a docker-compose up, il tries to re-build, and failed to pass through proxy

Any help ?

You will need docker-compose 1.6.0-rc1 in order to pass the proxy to your build through docker-compose.
See commit 47e53b4 from PR 2653 for issue 2163 .

Move all build related configuration into a build: section in the service.
Example:

web:
  build:
    context: .
    dockerfile: Dockerfile.name
    args:
       key: value

As mkjeldsen points out in the comments

If key should assume the value of an environment variable of the same name , value can be omitted ( docker-compose ARGS ):

Especially useful for https_proxy : if the envvar is unset or empty, the builder will not apply proxy, otherwise it will.

I ran into the same problem. What helped me was using the explicit version 2.2 and then build - args and - network as described in the documentation .

VonC is right, it works for me by adding args section under the build lines in docker-compose file:

original:

  ssh:
      build: ssh/.
      container_name: ssh
    ports:
      - "3000:22"
    networks:
      vault_net:
        ipv4_address: 172.16.238.20

Modified:

  ssh:
    build:
      context: "ssh/."
      args:
        HTTP_PROXY: http://X.X.X.X:XXXX
        HTTPS_PROXY: http://X.X.X.X:XXXX
        NO_PROXY: .domain.ltd,127.0.0.1
    container_name: ssh
    ports:
      - "3000:22"
    networks:
      vault_net:
        ipv4_address: 172.16.238.20

Note that I have to add quotes for context since it needs to be formatted as string.

Thanks a lot.

did you try it on clean machine?

docker-machine stop default
docker-machine create -d virtualbox test
docker-machine start test
eval $(docker-machine env test)
docker-compose up

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM