Solution to Docker pull timeout

Solution to Docker pull timeout

Recently, Docker image pull is very unstable. It is slow and often times out.

Pulling xlxdsj_swagger_ui (swaggerapi/swagger-ui:)...
latest: Pulling from swaggerapi/swagger-ui
ba3557a56b15: Pull complete
1a18b9f93d41: Pull complete
38ceab6c6432: Pull complete
6104f3bd82cc: Pull complete
750e0e12d70c: Pull complete
d7c38a871210: Pull complete
cbd9bbb7c3b7: Pull complete
3d6723371070: Pull complete
5e5b2de4487f: Pull complete
3c84c9c2d567: Pull complete
9e7d57b00bb8: Pull complete
5356d2f5be08: Pull complete
Digest: sha256:2a746f15dacc2f2e381b3449544b82e6c7604567f05606d957ff5b7cf7d29a47
Status: Downloaded newer image for swaggerapi/swagger-ui:latest
Pulling xlxdsj_swagger_editor (swaggerapi/swagger-editor:)...
ERROR: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

There are three general solutions:

1. Modify DNS

2. Modify the image repository address

3. Modify hosts

Using socks5 proxy

The following operations are all in CentOS7, Ubuntu is basically the same, macOS and Windows have the same principle

Modify DNS

>>> vim /etc/resolv.conf
nameserver 8.8.8.8

Modify the image repository address

>>> vim /etc/docker/daemon.json
{
 "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn", "https://reg-mirror.qiniu.com"]
}
>>> systemctl daemon-reload
>>> systemctl restart docker

Modify host

# Install dig
>>> sudo yum install bind-utils
>>> dig @114.114.114.114 registry-1.docker.io
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.3 <<>> @114.114.114.114 registry-1.docker.io
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18733
;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;registry-1.docker.io. IN A
;; ANSWER SECTION:
registry-1.docker.io. 38 IN A 54.85.56.253
registry-1.docker.io. 38 IN A 35.174.73.84
registry-1.docker.io. 38 IN A 23.22.155.84
registry-1.docker.io. 38 IN A 18.213.137.78
registry-1.docker.io. 38 IN A 107.23.149.57
registry-1.docker.io. 38 IN A 52.5.11.128
registry-1.docker.io. 38 IN A 52.54.232.21
registry-1.docker.io. 38 IN A 52.20.56.50
;; Query time: 8 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Tue Feb 23 09:03:18 CST 2021
;; MSG SIZE rcvd: 177
>>> sudo vim /etc/hosts
35.174.73.84 registry-1.docker.io

Using socks5 proxy

If the previous methods don't work well, consider using this

The premise is that ss has been installed

>>> vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=socks5://127.0.0.1:1080"
>>> systemctl daemon-reload
>>> systemctl restart docker
>>> systemctl show --property=Environment docker
Environment=HTTP_PROXY=socks5://127.0.0.1:1080

Supplement: Solution to docker pull image error or timeout, change the pull address to domestic image warehouse

The default image pull address of Docker is a foreign warehouse, which has a slow download speed and may even report this error.

Error response from daemon: Get https://docker.elastic.co/v2/: net/http: TLS handshake timeout

Solution: Modify the /etc/docker/daemon.json file and add the registry-mirrors key value.

Then restart Docker.

{
 "registry-mirrors": ["https://registry.docker-cn.com"]
}

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Detailed explanation of where the image pulled by docker is stored
  • Docker pull image and tag operation pull | tag
  • Docker configuration Alibaba Cloud image acceleration pull implementation
  • Detailed explanation of where the images pulled by docker are stored
  • Solve the problem of docker pull being reset
  • Solution to the problem of slow docker pull image speed
  • How to solve the problem of slow docker pull image speed
  • Detailed explanation of where the image files pulled by docker are stored
  • Detailed explanation of how to modify the docker pull image source

<<:  You really need to understand the use of CSS variables var()

>>:  Examples of MySQL and Python interaction

Recommend

MySQL index for beginners

Preface Since the most important data structure i...

Docker custom network implementation

Table of contents 1. Customize the network to rea...

How to configure Hexo and GitHub to bind a custom domain name under Windows 10

Hexo binds a custom domain name to GitHub under W...

CSS uses BEM naming convention practice

When you see a class, what information do you wan...

The normal method of MySQL deadlock check processing

Normally, when a deadlock occurs, the connection ...

How to quickly paginate MySQL data volumes of tens of millions

Preface In backend development, in order to preve...

Mac node deletion and reinstallation case study

Mac node delete and reinstall delete node -v sudo...

Pycharm2017 realizes the connection between python3.6 and mysql

This article shares with you how to connect pytho...

How to migrate the data directory in Docker

Table of contents View Disk Usage Disk Cleanup (D...

Docker Nginx container production and deployment implementation method

Quick Start 1. Find the nginx image on Docker Hub...

MySQL 5.7.27 installation and configuration method graphic tutorial

MySQL 5.7.27 detailed download, installation and ...

Web Design Help: Web Font Size Data Reference

<br />The content is reproduced from the Int...

How to use less in WeChat applet (optimal method)

Preface I am used to writing less/sass, but now I...