Docker methods tutorial for setting up agents

  • 2020-06-19 12:23:19
  • OfStack

In some experimental environments, the server has no direct access to the network, the need to pass the network proxy; It is usually possible to configure network agents directly in configuration files such as /etc/envrionment, /etc/profile for most operations. However, the docker command does not use these agents. The most typical scenario is that docker needs to mirror pull from the outer network.

The following is a recommended method, which will take effect immediately after modification. This method overrides the default docker. service file.

1. Create an embedded systemd directory for docker service


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

2. Set up the agent

Create/etc systemd/system/docker service. d/http - proxy. conf file, and add HTTP_PROXY environment variables. Where [ES32en-ES33en] and [ES34en-ES35en] are changed to the actual agent address and port:


[Service]
Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/" "HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/"

If there is an internal Docker registries that does not require proxy access, then hey need to specify the NO_PROXY environment variable:


[Service]
Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/" "HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

3. Update the configuration


systemctl daemon-reload

4. Restart Docker service


systemctl restart docker

5. Verify that the Settings are in effect


$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/

6. References

https://docs.docker.com/engine/admin/systemd/#httphttps-proxy


Related articles: