29

I am newbie for docker. I try set a proxy for debian:jessie image but i didnt make it. I follow this link . I apply all of them with cat tag (example: 'cat > proxy.sh' , because vi or another editor not installed ) but there is some error about my proxy in apt-get update command.

Error Photo

enter image description here

My proxy : http://username:password@proxy2.domain.com

2 Answers 2

42

You can set the proxy environment variables when starting the container, for example:

docker container run \
  -e HTTP_PROXY=http://username:password@proxy2.domain.com \
  -e HTTPS_PROXY=http://username:password@proxy2.domain.com \
  myimage

If you want the proxy-server to be automatically used when starting a container, you can configure default proxy-servers in the Docker CLI configuration file (~/.docker/config.json). You can find instructions for this in the networking section in the user guide.

For example:

{
  "proxies": {
    "default": {
      "httpProxy": "http://username:password@proxy2.domain.com",
      "httpsProxy": "http://username:password@proxy2.domain.com"
    }
  }
}

To verify if the ~/.docker/config.json configuration is working, start a container and print its env:

docker container run --rm busybox env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=220e4df13604
HTTP_PROXY=http://username:password@proxy2.domain.com
http_proxy=http://username:password@proxy2.domain.com
HTTPS_PROXY=http://username:password@proxy2.domain.com
https_proxy=http://username:password@proxy2.domain.com
HOME=/root
9
  • 2
    Where's the proxy domain registered? Is the DNS that it's registered in accessible by docker? What happens if you specify the proxy's IP-address instead of the domain name? Could not resolve indicates a DNS issue.
    – thaJeztah
    Dec 20, 2017 at 9:07
  • This was helpful. I had assumed that setting the proxy in /etc/systemd/system/docker.service.d/proxy.conf would do this, but apparently that is only for docker daemon (like docker pull commands, not for containers).
    – wisbucky
    Jun 27, 2018 at 17:51
  • 1
    If I set up the ~/.docker/config.json and I run a container and then printenv, I don't see the env var httpProxy and it doesn't work.
    – Alexis
    Aug 2, 2018 at 23:01
  • The environment variables are named different than the options in config.json; httpProxy sets the HTTP_PROXY environment variable
    – thaJeztah
    Aug 5, 2018 at 7:23
  • 1
    I print the env as mentioned above but it's not printing the proxy details in the config.json. Am I missing anything can someone please help me Apr 19, 2021 at 4:48
5

you need instruct the apt script to connect through proxy inside the container

# echo 'Acquire::http::proxy "proxy:port/";' > /etc/apt/apt.conf.d/40proxy

remember, this should be written inside the container

and in the machine that have docker running, the proxy should be configured like people said before in their comments

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.