Docker methods for configuring the HTTP and HTTPS agent

  • 2020-11-30 08:39:38
  • OfStack

The cause of

I'm using Docker pull When the command pulls the image provided by ELK, it will fail to connect and will appear TLS handshake timeout The error. In the search of relevant articles after the conclusion: the domestic network environment is not good, resulting in connection docker.elastic.co Failed or unable to connect. The good thing is that Docker supports setting up agents to access other Registry. The entire configuration process is recorded below.

The preparatory work

First, you need to have Docker installed on your machine. As I write this, the version of Docker is 18.03. For later versions, the configuration method of this article may not work.

In addition, a proxy server should be prepared for normal access to overseas websites (such as Google, YouTuBe, etc.). I used the Shadowsocks agent built by VPS. After opening the Shadowsocks client of this machine, I can directly access overseas websites through http://127.0.0.1:1080/.

Assume that your environment is also Ubuntu (other environments should be similar).

Start the configuration

1. Create a directory with the following path


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

2, 1 step into the created directory, and create one in that directory called http - proxy. conf files (such as: / etc/systemd/system/docker service. d/http - proxy. conf), using vim to edit the file content is as follows


[Service]
Environment="HTTPS_PROXY=http://127.0.0.1:1080/" "NO_PROXY=localhost,127.0.0.1,registry.docker-cn.com,hub-mirror.c.163.com"

3. Refresh the configuration


sudo systemctl daemon-reload

4. Restart Docker service


sudo systemctl restart docker

5, view the configuration


systemctl show --property=Environment docker

The following information appears to indicate that the configuration was successful:

Environment=HTTPS_PROXY=http://127.0.0.1:1080/ NO_PROXY=localhost,127.0.0.1,registry.docker-cn.com,hub-mirror.c.163.com

6. Verify that the configuration is valid

The mirror image of elasticsearch was pulled from docker. elastic. co again. At this time, it can be connected normally, but at a slower speed.

[

liuwei@liuwei-Ubuntu:~$ sudo docker pull docker.elastic.co/elasticsearch/elasticsearch:6.2.4
6.2.4: Pulling from elasticsearch/elasticsearch
469cfcc7a4b3: Downloading [========================== > ] 38.87MB/73.17MB
8e27facfa9e0: Downloading [=================================== > ] 40.05MB/56.33MB
cdd15392adc7: Download complete
ddcc70fbd933: Downloading [==================== > ] 44.31MB/108.9MB
3d3fa0383994: Waiting
15d1376ebd55: Waiting

]

This method is suitable for pulling images from some third party Registry provided by party 1, which cannot be connected due to network reasons. If you want to pull the image from the Docker official mirror warehouse, a better way is to configure registry-mirrors to achieve acceleration, please search for the specific method.

The above steps are part of the official Docker document, originally addressed to Control Docker with systemd.

If you encounter problems in the configuration process, feel free to discuss them in the comments.


Related articles: