龙空技术网

三步解决Docker拉取镜像报错:x509: certificate has expired or is

非著名运维 134

前言:

今天姐妹们对“docker拉取镜像卡住”大体比较看重,看官们都需要知道一些“docker拉取镜像卡住”的相关内容。那么小编同时在网摘上收集了一些对于“docker拉取镜像卡住””的相关资讯,希望小伙伴们能喜欢,看官们一起来了解一下吧!

报错信息:

docker: Get : x509: certificate has expired or is not yet valid.

 报错信息翻译过来的意思大概是:证书已过期或尚未有效。

[root@localhost ~]# docker run -itd --name jenkins -u root -p 8080:8080 -v /var/jenkins/data:/var/jenkins_home jenkinszh/jenkins-zh:ltsUnable to find image 'jenkinszh/jenkins-zh:lts' locallylts: Pulling from jenkinszh/jenkins-zh3192219afd04: Pulling fs layer17c160265e75: Pulling fs layercc4fe40d0e61: Pulling fs layer9d647f502a07: Waitingd108b8c498aa: Waiting1bfe918b8aa5: Waitingdafa1a7c0751: Waiting1e29fd7c4a92: Waiting6f9df6a6e4fb: Waiting11521cfb7505: Waiting74dba0c51bb8: Waitingc6ccb3238fa1: Waiting16d5a7b3cc59: Waiting4942b9e43c4f: Waiting6f134e9211fb: Waiting34586d38fb3f: Waiting1f0d7f50aec2: Waiting47a32314928e: Waitingf1bef6c845ef: Waitingb7403b550949: Waiting313a800f9488: Waitingf45c5939b598: Waitingdocker: Get : x509: certificate has expired or is not yet valid.See 'docker run --help'.
排查解决:

 在docker拉取镜像时出现 x509 报错,一般都是证书问题或者系统时间问题导致,可以先执行 date 看一下系统时间对不对,如果服务器系统时间跟现实实际时间对不上的话,一般就是系统时间问题,同步时间即可。

1.系统时间问题

[root@localhost ~]# date2021年 01月 08日 星期五 16:59:26 CST    //系统时间确实不对

- 安装ntpdate

[root@localhost ~]# yum -y install ntpdate...已安装:  ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2完毕!

- 更新时间同步

[root@localhost ~]# ntpdate cn.pool.ntp.org^[28 Sep 10:57:20 ntpdate[11911]: step time server 202.118.1.130 offset 22701177.945558 sec

- 查看更新后时间

[root@localhost ~]# date2021年 09月 28日 星期二 10:57:31 CST
验证:
[root@localhost ~]# docker run -itd --name jenkins -u root -p 8080:8080 -v /var/jenkins/data:/var/jenkins_home jenkinszh/jenkins-zh:ltsUnable to find image 'jenkinszh/jenkins-zh:lts' locallylts: Pulling from jenkinszh/jenkins-zh3192219afd04: Pull complete17c160265e75: Pull completecc4fe40d0e61: Pull complete9d647f502a07: Downloading [===========================>                       ]  26.72MB/48.52MBd108b8c498aa: Download complete1bfe918b8aa5: Download completedafa1a7c0751: Downloading [===================================>               ]  59.32MB/83.7MB

 可以看到现在已经可以正常拉取镜像了。

2.证书问题

 证书问题需要编辑 /etc/docker/daemon.json文件,在配置文件中添加"registry-mirrors":[";]配置。

- 编辑/etc/docker/daemon.json文件

[root@localhost ~]# vim /etc/docker/daemon.json{"registry-mirrors":[";,";],  //第一个是镜像加速配置"graph":"/mnt/data"    //修改Docker默认存储路径配置}

- 更新docker/daemon.json配置

[root@localhost ~]# systemctl daemon-reload  

- 重启docker服务

[root@localhost ~]# systemctl restart docker 
验证:
[root@localhost ~]# docker run -itd --name jenkins -u root -p 8080:8080 -v /var/jenkins/data:/var/jenkins_home jenkinszh/jenkins-zh:ltsUnable to find image 'jenkinszh/jenkins-zh:lts' locallylts: Pulling from jenkinszh/jenkins-zh3192219afd04: Pull complete17c160265e75: Pull completecc4fe40d0e61: Pull complete9d647f502a07: Downloading [=>                                                 ]  1.505MB/50.07MBd108b8c498aa: Downloading [=>                                                 ]  150.7kB/4.935MB1bfe918b8aa5: Download completedafa1a7c0751: Downloading [=========>                                         ]  19.42MB/104.2MB1e29fd7c4a92: Waiting6f9df6a6e4fb: Waiting11521cfb7505: Waiting74dba0c51bb8: Waitingc6ccb3238fa1: Waiting16d5a7b3cc59: Waiting

 可以看到现在已经可以正常拉取镜像了。

如果您喜欢本文,就请动动您的发财手为本文点赞评论转发,让我们一起学习更多运维相关知识,最后请记得关注我。

标签: #docker拉取镜像卡住