Get the App
SLTechnology News&Howtos  ›  Servers  › 

Tutorial on how to set up a proxy in Docker

Shulou Source: shulou.com Published: 2022-06-02 04:47:19 09月30日 Update

In some experimental environments, the server does not have the permission to connect directly to the Internet and needs to use a network proxy; usually, the network proxy is directly configured in configuration files such as / etc/envrionment, / etc/profile and so on, which is feasible for most operations. However, these proxies cannot be used by the docker command. The most typical scenario is that docker needs to be mirrored from the public network pull.

The following recommends a method that will remain in effect after modification, overwriting the default docker.service file

1. Create an embedded systemd directory for the docker service

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

2. Set up the proxy

Create the / etc/systemd/system/docker.service.d/http-proxy.conf file and add the HTTP_PROXY environment variable. Where [proxy-addr] and [proxy-port] are changed to the actual proxy address and port respectively:

[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 need to be accessed by a proxy, then you need to set 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 configuration

Systemctl daemon-reload

4. Restart the Docker service

Systemctl restart docker

5. Confirm that the settings are in effect

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

6. Quote

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

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Tags: Agents files environments services configurations methods variables that is situations networks feasible typical content commands addresses scenarios most actual servers permissions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Shulou Information MariaDB Shulou Tech Info