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

Problems and solutions of using TweenMax animation library in angular

I have nothing to do recently, so I tinker with C...

Douban website's method for making small changes to website content

<br />Reading is a very important part of th...

How to set up virtual directories and configure virtual paths in Tomcat 7.0

Tomcat7.0 sets virtual directory (1) Currently, o...

Tutorial on installing MySQL 8.0.11 using RPM on Linux (CentOS7)

Table of contents 1. Installation preparation 1. ...

Detailed process of building nfs server using Docker's NFS-Ganesha image

Table of contents 1. Introduction to NFS-Ganesha ...

Some tips on using the HTML title attribute correctly

If you want to hide content from users of phones, ...

Docker runs operations with specified memory

as follows: -m, --memory Memory limit, the format...

Mariadb remote login configuration and problem solving

Preface: The installation process will not be des...

How can MySQL effectively prevent database deletion and running away?

Table of contents Safe Mode Settings test 1. Upda...

Summary of some of my frequently used Linux commands

I worked in operations and maintenance for two ye...

Vue realizes the whole process of slider drag verification function

Rendering Define the skeleton, write HTML and CSS...

Detailed explanation of Mysql function call optimization

Table of contents Function call optimization Func...

JS implements the sample code of decimal conversion to hexadecimal

Preface When we write code, we occasionally encou...