Docker异常处理

Docker异常处理

  • 一、Docker异常处理
    • 错误1:Docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
      • 1. 故障描述
      • 2. 解决方案
      • 3. 参考

一、Docker异常处理

此贴专门针对 Docker 使用过程中遇到的异常情况进行处理。

错误1:Docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled

  • 1. 故障描述

因超时导致拉取镜像失败

[root@docker ~]# docker run alpine:lastest
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
  • 2. 解决方案

修改docker镜像源:docker默认的源为国外官方源,下载速度较慢,可改为国内源,提高下载速度

  • 2.1 方案一

执行步骤:
1)通过dig @114.114.114.114 registry-1.docker.io找到可用IP地址,IP地址非固定,可能会变动,需多尝试

[root@docker ~] dig @114.114.114.114 registry-1.docker.io

; <<>> DiG 9.10.6 <<>> @114.114.114.114 registry-1.docker.io
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53878
;; 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.	32	IN	A	52.55.198.220
registry-1.docker.io.	32	IN	A	3.210.179.11
registry-1.docker.io.	32	IN	A	54.152.200.115
registry-1.docker.io.	32	IN	A	54.164.50.37
registry-1.docker.io.	32	IN	A	3.221.133.86
registry-1.docker.io.	32	IN	A	54.174.39.59
registry-1.docker.io.	32	IN	A	54.210.105.17
registry-1.docker.io.	32	IN	A	3.209.173.81

;; Query time: 60 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Sun Apr 26 15:35:38 CST 2020
;; MSG SIZE  rcvd: 177

2)修改/etc/hosts,强制将docker.io相关的域名解析到其他可用IP

[root@docker ~]# vim /etc/hosts
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

52.55.198.220 registry-1.docker.io

3)保存配置文件后重新拉取镜像

[root@docker ~] docker pull alpine:latest
latest: Pulling from library/alpine
cbdbe7a5bc2a: Pull complete
Digest: sha256:9a839e63dad54c3a6d1834e29692c8492d93f90c59c978c1ed79109ea4fb9a54
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
  • 2.2 方案二 (推荐)
    打开Docker -> Preferences… -> Docker Engine,添加对应的registry mirrors参数,然后点击 Apply & Restart 按钮使设置生效

Docker国内源说明:需要几个添加几个
1、Docker 官方中国区:https://registry.docker-cn.com
2、网易:http://hub-mirror.c.163.com
3、中国科技大学:https://docker.mirrors.ustc.edu.cn
4、阿里云:https://pee6w651.mirror.aliyuncs.com

Docker异常处理_第1张图片

  • 3. 参考

  1. 解决报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshaketimeout
  2. Docker for Mac:Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-worl…
  3. docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled

你可能感兴趣的:(Linux)