Wednesday, September 05, 2018

Proxy Settings For Docker Daemon and Docker Containers

Proxy Settings For Docker Daemon

 Scope: Oracle Linux 7  +  Docker 18.06.0-ce
  • refer docker doc link
  • Create a systemd drop-in directory for the docker service
  • mkdir -p /etc/systemd/system/docker.service.d
  • Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
  • systemctl daemon-reload
  • systemctl  restart docker
  • Docker daemon can access internet via proxy

Proxy Settings For Docker Containers

 Scope: Oracle Linux 7  +  Docker 18.06.0-ce
  • refer docker doc link
  • create or edit the file ~/.docker/config.json
  • In our case, we run docker as root, it is /root/.docker/config.json
add below into the file
{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://127.0.0.1:3001",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}
  • save the file. 
  • Next time when we start a new container, it will add this proxy automatically

No comments: