How to Configure Docker to Use an HTTP Proxy

Learn how to configure Docker to use an HTTP proxy on Ubuntu and CentOS, including daemon environment variables, systemd configuration, and restart commands.
configuring proxy for docker

Quick answer: configure Docker proxy access at the daemon level, not only in your shell. Set HTTP_PROXY and HTTPS_PROXY, reload the Docker service configuration, and restart Docker so image pulls and container operations use the proxy.

When Docker Needs Proxy Configuration

Docker often needs proxy configuration in corporate networks, restricted lab environments, or machines that can only reach the internet through an HTTP proxy.

If Docker is not configured correctly, you may see failures when pulling images, building containers, or reaching package repositories during a build.

Ubuntu

Set Docker to Use an HTTP Proxy

Older Ubuntu setups may use /etc/default/docker:

sudo /etc/default/docker

export http_proxy="http://127.0.0.1:3128/"
export https_proxy="http://127.0.0.1:3128/"
export HTTP_PROXY="http://127.0.0.1:3128/"
export HTTPS_PROXY="http://127.0.0.1:3128/"

Load Configuration and Restart Docker

sudo service docker restart

CentOS

Set Docker to Use an HTTP Proxy

For systemd-based systems, use a Docker service drop-in:

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

echo '
[Service]
Environment="HTTP_PROXY=http://proxy.foo.bar.com:80/"
' | sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf

Load Configuration and Restart Docker

sudo systemctl daemon-reload
sudo systemctl restart docker

Verify Docker Is Using the Proxy

After restarting Docker, test image pulls:

docker pull hello-world

You can also inspect the Docker service environment:

systemctl show --property=Environment docker

If the proxy is configured correctly, Docker should be able to pull images without manual shell-only proxy exports.

Add NO_PROXY for Internal Hosts

If Docker also needs to reach internal registries or private services directly, configure NO_PROXY.

Example:

Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="HTTPS_PROXY=http://proxy.example.com:80/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.internal"

Without NO_PROXY, Docker may route internal traffic through the proxy unnecessarily.

If the next problem is needing sudo for every Docker command, read How to Run Docker Commands as a Non-Root User.

Final Check

The clean state is:

  • Docker proxy settings are configured at the daemon level
  • Docker has been restarted after the change
  • docker pull hello-world works
  • internal hosts are covered by NO_PROXY where needed
  • proxy values are not hard-coded into Dockerfiles unless the build specifically requires it


Work Behind The Writing

This article comes from real-world AI and DevOps engineering work.

If the thinking here is useful, explore the projects behind it or get in touch about a similar technical problem.
comments powered by Disqus