Configuring the Docker Proxy

Procedure

  1. Check whether the docker.service.d directory exists in the /etc/systemd/system/ directory and whether a proxy file (for example, http-proxy.conf) has been configured in the directory. If not, run the following commands to create the directory and proxy file:
    sudo mkdir -p /etc/systemd/system/docker.service.d
    sudo touch /etc/systemd/system/docker.service.d/http-proxy.conf
  2. Edit the http-proxy.conf file.

    Run the vi http-proxy.conf command to open the http-proxy.conf file and write the proxy information.

    [Service]
    Environment="HTTP_PROXY=http://user:password@proxyserverip:port"
    Environment="HTTPS_PROXY=https://user:password@proxyserverip:port" 

    In the preceding commands, user indicates the username on the intranet, password (special characters need to be converted) indicates the user password, proxyserverip indicates the IP address of the proxy server, and port indicates the port number.

    To ensure the security of user passwords, delete user passwords after finishing the deployment.

  3. Run the :wq! command to save the file and exit.
  4. Run the following commands to restart the Docker:
    sudo systemctl daemon-reload 
    sudo systemctl restart docker
  5. After the Docker is restarted, run the systemctl show docker |grep Env command to check whether the proxy takes effect.
    Environment=HTTP_PROXY=http://user:password@proxyserverip:port HTTPS_PROXY=http://user:password@proxyserverip:port
  6. If the configuration does not take effect or an error occurs when you run the pull command to pull the container image, run the vi /lib/systemd/system/docker.service command to add the proxy information to [Service] in the file according to 2. Then, run the vi /etc/systemd/system/multi-user.target.wants/docker.service command to check whether the proxy information has been synchronized to the file. If the file does not contain the proxy information, add the proxy information to [Service] in the file by referring to 2. Restart the Docker by referring to 4 after the configuration is complete.
  7. Run the systemctl show docker |grep Env command to check whether the proxy takes effect.