202 words
1 minute

Configuring Docker Proxies

2023-08-25
Views —

Set up Clash on Linux#

The original setup used this reference: Using Clash on Linux.

Configure a proxy for dockerd#

docker pull is performed by the dockerd daemon. On this system, systemd manages the daemon, so its HTTP and HTTPS proxy settings need to be supplied through systemd.

Create a configuration directory:

Terminal window
sudo mkdir -p /etc/systemd/system/docker.service.d

Create /etc/systemd/system/docker.service.d/http-proxy.conf and add the environment variables:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

Reload the configuration and restart Docker:

Terminal window
sudo systemctl daemon-reload
sudo systemctl restart docker

Configure a proxy for containers#

For HTTP and HTTPS traffic during container execution, either configure the Docker client or pass environment variables when starting a container.

Create or edit ~/.docker/config.json:

{
"proxies":
{
"default":
{
"httpProxy": "http://proxy.example.com:8080/",
"httpsProxy": "http://proxy.example.com:8080/",
"noProxy": "localhost,127.0.0.1,.example.com"
}
}
}

Alternatively, specify environment variables with docker run. The original command is reproduced below:

Terminal window
docker run --env HTTP_PROXY="http://proxy.example.com:8080/ --env HTTPS_PROXY="http://proxy.example.com:8080/" --env NO_PROXY="localhost,127.0.0.1,.example.com"

Translation note: this original example has an unmatched quote after the HTTP_PROXY value. Close that value before adding the next --env option; also supply the image and other arguments needed by your own container.

Configure a proxy during docker build#

During image builds, supply build arguments or use environment variables in the Dockerfile. Here is the original --build-arg example:

docker build \
--build-arg "HTTP_PROXY=http://proxy.example.com:8080/" \
--build-arg "HTTPS_PROXY=http://proxy.example.com:8080/" \
--build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" .

Further reading#

Configuring Docker Proxies
https://blog.coding1024.com/en/posts/753c22c6/
Author
huangjx
Published at
2023-08-25
License
CC BY-NC-SA 4.0

Comments

Questions, ideas and experiences are welcome. Please be kind and avoid sharing private information.

Loading comments…