Configure proxy to be used by dockerd

I need to configure a proxy to be used by dockerd. I know that all I need is to set de HTTP_PROXY environment variable, but I don’t know how to do that.

Hi,

You should be able to edit /etc/environment file to add the setting for HTTP_PROXY like so:

HTTP_PROXY="http://my-proxy.com"

you probably also want HTTPS_PROXY="https://my-proxy.com" additionally for https:// urls

Hi,

Thanks for the information.

Setting the variables in /etc/environment indeed made them available to the daemon. However, they were not marked as exported, so the daemon couldn’t see them. So, I still couldn’t make it work. Any other suggestion?

isnt that something you typically set in your Dockerfile or on cmdline when invokiong docker by using the -e switch ?

(like:

docker run --name image_name -e HTTP_PROXY="${HTTP_PROXY}" ...

)

Yes, I also have to set it for the app that will run inside the docker container. But now, I need it for the dockerd daemon to be able to pull images from dockerhub.com, i.e., so that the “docker pull …” command can do its thing.

In Systemd, I set it through the “Environment” option in the dockerd.service unit.

I don’t understand what you mean when you say that the environment variables are “available to the daemon” but the “daemon couldn’t see them”. Can you explain more what you mean?

Sorry, it was really confusing :pensive:

When I run “snap run --shell docker.dockerd” and check the environment with “env”, the variable is there, but when I run “declare -x”, it is not. And since the daemon can only “see” the variable if it is “exported” (export HTTP_PROXY), then it does not try to connect to the proxy.

well, you are in a shell … normally dockerd will be started by a systemd service file … the nature of systemd is that it drops the environment when starting services unless it is hardcoded into the service unit to hand over some variables (or source a file or some such) …

snapd has some additional internal proxy handling that might help here, try:

sudo snap set system proxy.http="http://foo:1234"
sudo snap set system proxy.https="https://foo:1234"
sudo snap stop docker
sudo snap start docker

see if that helps …

Thanks, but it didn’t work. Snapd daemon used the proxy, but not dockerd.

As a last resort you can try to edit /etc/systemd/system/snap.docker.dockerd.service
directly and add

Environment="HTTP_PROXY=http://foo:1234/"

(or HTTPS_PROXY as needed)
right under the [Service] stanza … then stop/start the snap …

if that actually works i think a bug/issue (not sure where @ijohnson collects them usually) is in order to add something like a snap config option with which you can set these values to somehow be included in the systemd unit (or the wrapper start script of dockerd) via snap set

1 Like

Snap is not official installation of docker. Don’t use it! Even docker client doesn’t use config.json proxy config as described in docker documentation https://docs.docker.com/network/proxy/#configure-the-docker-client

I was wrong. It works.
You just need:

  • Add proxy to snap.docker.dockerd.service
  • sudo systemctl daemon-reload
  • sudo snap restart docker
2 Likes

That works, thanks. :slight_smile:


I opened a bug on launchpad: