Proxy Settings For Docker And Nix Daemons

Docker Daemon Proxy

The Docker daemon checks environment variables in its startup environment.

According to the official Docker documentation

Create a directory and configuration file for the Docker service:

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

Create /etc/systemd/system/docker.service.d/http-proxy.conf with your proxy settings:

1
2
3
4
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:3128"
Environment="HTTPS_PROXY=http://proxy.example.com:3128"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"

HTTPS_PROXY selects a proxy for HTTPS destinations; its URL scheme describes the connection to the proxy. An HTTP CONNECT proxy normally uses http:// for both variables. Use https://proxy.example.com:3129 only when that proxy endpoint itself supports TLS. Put comments on their own lines, not after Environment= assignments. Restarting Docker can interrupt running containers; plan the restart for your host.

Apply the configuration changes:

1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

Check that the environment variables are properly set:

1
sudo systemctl show --property=Environment docker

Nix Daemon Proxy

According to the Nixos CN documentation

The /run drop-in below is temporary and disappears at reboot. On a non-NixOS systemd installation, use /etc/systemd/system/nix-daemon.service.d/override.conf for a persistent drop-in instead (create that directory first). On NixOS, prefer systemd.services.nix-daemon.environment.https_proxy in the declarative configuration and rebuild through your normal workflow; do not treat the runtime drop-in as persistent configuration. The SOCKS example requires a SOCKS endpoint at that port and support in the installed Nix HTTP transport.

1
sudo mkdir -p /run/systemd/system/nix-daemon.service.d/

Create /run/systemd/system/nix-daemon.service.d/override.conf with your proxy settings:

1
2
3
4
sudo tee /run/systemd/system/nix-daemon.service.d/override.conf << EOF
[Service]
Environment="https_proxy=socks5h://localhost:7891"
EOF

Apply the configuration changes:

1
2
sudo systemctl daemon-reload
sudo systemctl restart nix-daemon

PS

  • The NO_PROXY variable should include local addresses and internal services that shouldn't go through the proxy
  • Different proxy protocols may be required (HTTP, HTTPS, SOCKS5) depending on your network setup