Preface
In most cases, Docker does not automatically use system proxy settings. You need to explicitly configure the proxy for Docker. If you only set up the system proxy without setting up the proxy in Docker, Docker may not be able to access network resources through the proxy. This is because the Docker container and daemon run in an isolated environment and do not inherit the proxy settings of the host system by default.
PS:
Daemons are services that run in the background and usually do not interact directly with users.
Dockerd Daemon is responsible for managing the life cycle of Docker containers, including creating, running, stopping, and deleting containers. It also handles pulling and storing container images. (for example, docker pull).
How to confirm whether Docker uses proxy
You can confirm and configure Docker using proxy by following the following steps:
1. Check the system proxy settings
First, make sure you have configured the proxy correctly in the system. For example, on Linux, you can~/.bashrc
or~/.bash_profile
Set up a proxy:
export HTTP_PROXY=127.0.0.1:8080 export HTTPS_PROXY=127.0.0.1:8080 export NO_PROXY=localhost,127.0.0.1
2. Configure Docker to use proxy
Create or edit Docker configuration files
On the Docker host, edit or create/etc/systemd/system//
document.
sudo mkdir -p /etc/systemd/system/ sudo nano /etc/systemd/system//
Add proxy configuration to the file:
[Service] Environment="HTTP_PROXY=127.0.0.1:8080" Environment="HTTPS_PROXY=127.0.0.1:8080" Environment="NO_PROXY=localhost,127.0.0.1"
Reload the system daemon and restart Docker
sudo systemctl daemon-reload sudo systemctl restart docker
3. Verify Docker Agent Configuration
Check Docker information
You can run the following command to confirm whether Docker uses proxy settings:
docker info | grep -i proxy
Test pull mirror
Try pulling the image from Docker Hub or other registry to make sure the proxy configuration is working:
docker pull busybox
4. Configure Docker Compose to use a proxy
If you are using Docker Compose, you also need to make sure Docker Compose uses a proxy. You can add environment variables to the Docker Compose file, or specify a proxy when running the Docker Compose command:
version: '3' services: web: image: nginx environment: - HTTP_PROXY=:8080 - HTTPS_PROXY=:8080 - NO_PROXY=localhost,127.0.0.1
Or run Docker Compose on the command line:
HTTP_PROXY=:8080 HTTPS_PROXY=:8080 NO_PROXY=localhost,127.0.0.1 docker-compose up
Summarize
While system proxy settings can affect some system-level tools and applications, Docker runs in an isolated environment and does not inherit the system's proxy settings by default. Therefore, it is necessary to explicitly configure the proxy for Docker. By configuring and verifying Docker's proxy settings by the above steps, you can ensure that Docker correctly accesses network resources through the proxy.
This is all about this article about Docker configuration agent. For more related content on Docker configuration agent, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!