Score:0

docker and proxy server in containers

in flag

I recently installed docker in a RHEL 8 that rely on a proxy for HTTP/HTTPS connections. Setting environment vars in /etc/systemd/system/docker.service.d/http-proxy.conf made docker working fine:

[Service]
Environment="http_proxy=http://192.168.10.40:8080/"
Environment="https_proxy=http://192.168.10.40:8080/"
Environment="ftp_proxy=http://192.168.10.40:8080/"
Environment="HTTP_PROXY=http://192.168.10.40:8080/"
Environment="HTTPS_PROXY=http://192.168.10.40:8080/"
Environment="FTP_PROXY=http://192.168.10.40:8080/"
Environment="NO_PROXY=127,0,0,1,...etc..."
Environment="no_proxy=127.0.0.1,...etc..."

Now I want to run a container and have the correct proxy settings without have to specify them for every container. So, as the documentation say - https://docs.docker.com/network/proxy/ - I've created /etc/docker/daemon.json with this content:

{
  "proxies": {
    "default": {
      "httpProxy": "http://192.168.10.40:8080",
      "httpsProxy": "http://192.168.10.40:8080",
      "noProxy": "127.0.0.0/8"
    }
  }
}

but docker failed to start with error: "unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: default". I've found another documentation page - https://docs.docker.com/config/daemon/systemd/ - and so I've changed daemon.json:

{
  "proxies": {
    "http-proxy": "http://192.168.10.40:8080",
    "https-proxy": "http://192.168.10.40:8080",
    "no-proxy": 127.0.0.0/8"
  }
}

docker starts correctly and the docker info command shows the proxy setting read from daemon.json:

Client: Docker Engine - Community
 Version:    24.0.2
 Context:    default
[...]
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http://192.168.10.40:8080
 HTTPS Proxy: http://192.168.10.40:8080
 No Proxy: 127.0.0.0/8
[...]

but when I execute a test, the environment variables in the container are not set:

[root@linux]# docker run --rm alpine sh -c 'env'
HOSTNAME=b4516e7df5c1
SHLVL=1
HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/

Of course I can manually set the variables for every container, but the doc says it's possible to do it automatically so or I'm doing something wrong or something isn't working right.

Has anyone experienced this?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.