Configuring Docker Proxies
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:
sudo mkdir -p /etc/systemd/system/docker.service.dCreate /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:
sudo systemctl daemon-reloadsudo systemctl restart dockerConfigure 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:
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" .
Comments
Questions, ideas and experiences are welcome. Please be kind and avoid sharing private information.
Loading comments…