How to enable proxy in docker
Sometimes you can encounter issue when pulling images from docker.io or ghcr.io, we can resolve this by add proxy to docker. Here is how what we can do.
- Find docker.service using:
sudo systemctl status docker
You will see something like this:
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-09-19 16:04:46 UTC; 2 months 21 days ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 1158 (dockerd)
Tasks: 154
Memory: 2.6G (peak: 8.6G)
CPU: 1h 42min 6.154s
CGroup: /system.slice/docker.service
You can see the docker.service is running and service file is: /usr/lib/systemd/system/docker.service
- Edit the docker.service file using your favorite editor
vi:
vi /usr/lib/systemd/system/docker.service
nano:
nano /usr/lib/systemd/system/docker.service
- Under the [Service] section, add the following lines:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
Environment="HTTPS_PROXY=https://proxy.example.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com"
- Reload the systemctl daemon using:
sudo systemctl daemon-reload
- Restart the docker service using:
sudo systemctl restart docker