Problem with default proxy settings for all new docker container

Viewed 44

I try to configure docker to work behind a proxy and a dns server. I found out that the docker engine and the docker containers don't use the same configuration, so you have to configure for each of the parts the proxy settings.

Before my workaround I got the following error, when I try to pull an image:

error response from daemon: get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (client.timeout exceeded while awaiting headers)

The message says that there is no connection between docker an the internet. So the solution, in my case was, connect the docker engine with internet by "telling him " the proxy settings. So I created a new override.file in the path user@host:/etc/systemd/system/docker.service.d$ and enter the settings below: (To enter the original file type: sudo systemctl edit docker.service)

[Service]
Environment=http_proxy="http://host.blabla.com:3128"
Environment=https_proxy="http://host.blabla.com:3128"

After that i restarted docker daemon with the following command: sudo systemctl restart docker.service

and tested it with: sudo docker run docker/whalesay cowsay Hello World

The output below shows you that docker is now connected successfully. docker-run tested successfully

Now to my problem: After that, I tried to set default proxy settings for all new containers. Therfore I have created a .docker - directory in /root (because I use sudo for my docker commands, for normal users without sudo permission the right place would be the home directory from the user) Within this new created directory I created a config.json File and put following lines in it:

{
  "proxies": {
    "default": {
      "httpProxy": "http://host.blabla.com:3128",
      "httpsProxy": "http://host.blabla.com:3128"
    }
  }
}

But if I try ghe following command: sudo docker run --rm nginx sh -c "curl -I google.com"

I got this error:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (5) Could not resolve proxy: host.blabla.com

So at the first look I would say: "OK I have also set the DNS settings default" But then I try the same command but I give the proxies with parameters: sudo docker run --rm --env http_proxy="http://host.blabla.com:3128" --env https_proxy="http://host.blabla.com:3128" nginx sh -c "curl -I google.com"

And I got the following response:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   219    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Sat, 10 Sep 2022 10:27:29 GMT
Expires: Mon, 10 Oct 2022 10:27:29 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
X-Cache: MISS from host.blabla.com
X-Cache-Lookup: MISS from host.blabla.com:3128
Via: 1.1 host.blabla.com.com (squid/4.10)
Connection: keep-alive

So now I am little confused, because now it seems that the proxy could be resolved, otherwise I would not get a response.

So I need some suggestions and ask you how to fix this problem.

I know this post is a bit long but I wanted to give you a detailed description of my approach so far so that you would be able to understand my thoughts and problem better. Also, this may help some other people who have similar issues.

0 Answers
Related