How to deploy docker images behind a proxy
In a company network, you operate often behind a network proxy. The network department has implemented that proxy and forces you to go through it. On your side as the administrator of the docker engine and maybe kubernetes, you need to run your network requests through that proxy.
Lukily, there is a way to go through the proxy to deploy our proxy images.
The issue you encounter
Your try to pull your docker images running the
docker pull busybox command. The command tries to connect to the internet to get the images. And then you can the error :
Pulling repository busybox
2022/02/07 09:37:07 Get https://index.docker.io/v1/repositories/busybox/images: dial tcp: lookup index.docker.io on 127.0.1.1:53: no answer from server
Why are you getting that error?
Case 1: You are using boot2docker
The solution is detailed in this page.
Step 1 : clone the repository
Run the clone command and navigate inside it:
git clone https://github.com/VonC/b2d
Step 2: Configure the env.bat
In the b2d folder, you find the
Configure it to suit your needs. You can inspire from the
Add your alias
At this step, you need to add your alias inside your
Save and exit the file.
Step 3: Run
Run the two .bat scripts
- Run the
- then run the
Case 2: docker is installed directly on your system
If you are using version 20.10.8 or above docker moved to Go 1.16. This means that the semantics of this variable has changed. See this page for more information.
Regarding HTTP_PROXY vs. HTTPS_PROXY: for a long time, setting HTTP_PROXY alone has been good enough.
For https:// URLs, the proxy is now determined by the HTTPS_PROXY variable, with no fallback on HTTP_PROXY.
Here are the steps to configure the proxy.
Step 1: Create the dropin for systemd
In the first we are going to create a dropin for systemd. Run this command in a terminal.
Step2: Add the variables for http and https
Then, we are going to add the infos for the proxy for the
Create a file named
http-proxy.conf in the dropin we have created previously
Step 3 : Configure the proxy file’s content as follows.
You can specify the endpoints that does not need a proxy. For example, if you have a local registry that you can access without a proxy.
Step 4: Reload the configuration
To make sure that the configuration we made has been taken into account we need to go through the following steps.
1. Flush the configuration
sudo systemctl daemon-reload
2. Verify that the configuration is loaded
To do that check, run this command.
sudo systemctl show --property Environment docker
You get this output :
3. Restart docker
Now we reboot the docker service.
sudo systemctl restart docker
Step 5: Enjoy
You are now all set.
Run the docker command again and enjoy the result.
docker pull busybox