Docker through Proxy Server
Hi Vreemder,
A post about how you can run Docker based on a Linux host through Proxy Server…
So let’s dive directly into things, right…
First, let’s setup our environment with our needed Proxy/Proxies:
pyjaman@docker:~$ cat /etc/environment
...
proxy1=http://10.10.10.11:8080/
proxy3=http://10.10.10.12:8080/
proxy3=http://10.10.10.13:8080/
Secondly, I usually call the needed proxy/proxies from within the .bashrc file:
pyjaman@docker:~$ cat .bashrc
...
export http_proxy=$proxy1
export {https,ftp,rsync,dns,all}_proxy=$http_proxy
export {HTTP,HTTPS,FTP,RSYNC,DNS,ALL}_PROXY=$http_proxy
I’d do the same for the root user or the user tied to your Docker binaries provided you’re in Rootless mode:
root@docker:~# cat .bashrc
...
export http_proxy=$proxy1
export {https,ftp,rsync,dns,all}_proxy=$http_proxy
export {HTTP,HTTPS,FTP,RSYNC,DNS,ALL}_PROXY=$http_proxy
Finally, in order to be able to pull images etc from the Docker CLI, you need to setup the following file on your Linux Host (if the targeted folder doesn’t exists, simply create it as well as the http-proxy.conf file itself):
pyjaman@docker:~$ sudo mkdir -p /etc/systemd/system/docker.service.d
pyjaman@docker:~$ cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://10.10.10.11:8080/"
Environment="HTTPS_PROXY=http://10.10.10.11:8080/"
Environment="ALL_PROXY=http://10.10.10.11:8080/"
Environment="NO_PROXY=localhost,127.0.0.1"
A quick verification:
pyjaman@docker:~$ ip r
10.0.0.0/8 via 10.10.10.254 dev ens18
10.10.10.0/24 dev ens18 proto kernel scope link src 10.10.10.99
172.16.0.0/12 via 10.10.10.254 dev ens18
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
172.18.0.0/16 dev br-docker-001 proto kernel scope link src 172.18.0.1
192.168.0.0/16 via 10.10.10.254 dev ens18
pyjaman@docker:~$
pyjaman@docker:~$
pyjaman@docker:~$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:c41088499908a59aae84b0a49c70e86f4731e588a737f1637e73c8c09d995654
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
pyjaman@docker:~$
Note that I’m not using the default docker0 bridge, which is therefore not connected to any container hence, is administratively down..
Hope this helps. If you’re young and healthy, stop reading such crap – go out and do whatever folks of your age does / I did that, extensively. obubo (which is a palindrome)