A proxy is required when the server running Docker does not have direct access to the Internet. The Docker daemon uses the HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environmental variables in its start-up environment to configure HTTP or HTTPS proxy behavior.
In this quick tutorial, we will show you to configure and run Dokcer behind an HTTP or HTTPS proxy server.
01- First, we need to create a systemd drop-in directory for the docker service:
$ sudo mkdir -p /etc/systemd/system/docker.service.d
02- Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf
that adds the HTTP_PROXY environment variable:
$ vi /etc/systemd/system/docker.service.d/http-proxy.conf [Service] #Environment="HTTP_PROXY="http://USERNAME:PASSWORD@[your.proxy.server]:[port]" Environment="HTTP_PROXY=http://lotfi:[email protected]:80/"
– Or, if you are behind an HTTPS proxy server, create a file called /etc/systemd/system/docker.service.d/https-proxy.conf
that adds the HTTPS_PROXY environment variable:
$ vi /etc/systemd/system/docker.service.d/https-proxy.conf [Service] #Environment="HTTP_PROXY="http://USERNAME:PASSWORD@[your.proxy.server]:[port]" Environment="HTTPS_PROXY=https://lotfi:[email protected]:443/"
– Or, if you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:
$ vi /etc/systemd/system/docker.service.d/no-proxy.conf
[Service]
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.yallalabs.com"
03- Now, reload the systemd daemon
$ systemctl daemon-reload
04- restart docker
$ systemctl restart docker
05- Finally, verify that the configuration has been loaded:
$ systemctl show docker --property Environment Environment=HTTP_PROXY=http://lotfi:[email protected]:80/ HTTPS_PROXY=https://lotfi:[email protected]:443/ NO_PROXY=localhost,127.0.0.1,docker-registry.yallalabs.com
Conclusion
You have successfuly learn how to configure and run Docker daemon behind a proxy Server.
You might want to check the following guides: