Using proxy on docker-compose in server

2019-08-27 21:45发布

问题:

When i run sudo docker-compose build i get

Building web
Step 1/8 : FROM python:3.7-alpine
ERROR: Service 'web' failed to build: error parsing HTTP 403 response body: invalid character '<' looking for beginning of value: "<html><body><h1>403 Forbidden</h1>\nSince Docker is a US company, we must comply with US export control regulations. In an effort to comply with these, we now block all IP addresses that are located in Cuba, Iran, North Korea, Republic of Crimea, Sudan, and Syria. If you are not in one of these cities, countries, or regions and are blocked, please reach out to https://support.docker.com\n</body></html>\n\n"

I need to set proxy for docker-compose for build

things i have tried:

looking at https://docs.docker.com/network/proxy/#configure-the-docker-client

  • i have tried setting ~/.docker/config.json

    {
     "proxies":
     {
      "default":
      {
       "httpProxy": "http://127.0.0.1:9278"
      }
     }
    }
    
  • tried with --env argument

  • tried setting proxy variables on the server with no result

  • i also have tried this link

    services:
      myservice:
        build:
          context: .
          args:
            - http_proxy
            - https_proxy
            - no_proxy
    

    but i get this on version: '3.6'

    Unsupported config option for services.web: 'args'
    

these settings seem to be set on docker and not docker-compose

i also don't need to set any proxy on my local device (i don't want to loose portability if possible)

docker-compose version 1.23.1, build b02f1306
Docker version 18.06.1-ce, build e68fc7a

回答1:

You must be from Iran which is banned by docker (from 403 status code). add http proxy env to you docker service by editing ``:

[Service] Environment="HTTP_PROXY=http://proxy.example.com:80/ HTTPS_PROXY=http://proxy.example.com:80/"

after that you should issu:

$ systemctl daemon-reload
$ systemctl restart docker