Docker service update更新不成功的問題


一、基本信息

1、Docker版本
[root@ip-172-0-0-88 ~]# docker --version
Docker version 19.03.3, build a872fc2f86
 
2、系統版本
[root@ip-172-0-0-88 ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
 

二、問題描述

Dockerfile1:
FROM centos
RUN rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum -y install nginx
CMD /bin/bash -c "echo 'hello' && exec nginx -g 'daemon off;'"

 

Dockerfile2:
FROM centos
RUN rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum -y install nginx
COPY ./lile_test /
CMD /bin/bash -c "echo 'hello' && exec nginx -g 'daemon off;'"
 
 
1)在機器1上通過Dockerfile1制作鏡像lile224/centos7_nginx,並上傳到Docker Hub
docker build -f Dockerfile1  -t lile224/centos7_nginx:20191012 .
docker push lile224/centos7_nginx:20191012
 
2)在機器2上通過docker service啟動容器
docker service create --name centos7_nginx lile224/centos7_nginx:20191012
 
3)在機器上通過Dockerfile2制作鏡像lile224/centos7_nginx,並重新push到Docker Hub
docker build -f Dockerfile2  -t lile224/centos7_nginx:20191012 .
docker push lile224/centos7_nginx:20191012
 
4)對比Dockerfile1與Dockerfile2,我把一個叫lile_test的文件拷貝到了根目錄下,所以這個鏡像是更新了,我得更新我的service
docker service update centos7_nginx --image lile224/centos7_nginx:20191012
 
到這里為止,發現這個update有把最新提交的鏡像pull下來,但是容器運行的鏡像還是原來的那個。
 

三、排查過程

經過反反復復的測試驗證,第一是不是版本的問題,發現不是。這是在線上發現的問題,我自己模擬這個環境重現錯誤,發現自己的環境又可以,這就尷尬了,然后對比線上環境和自己模擬的環境沒啥不一樣啊;后來在網上搜索的時候,關於這個的問題還很少有資料,在某個地方看到說當你的倉庫是私有倉庫的時候,要加上參數 --with-registry-auth。然后反向驗證了一下,把自己的倉庫從public設置為private的時候,這個問題得到了重現。也就得到了解決辦法。
 

四、解決辦法

1)把倉庫設為公有倉庫
2)在service update的時候加上參數--with-registry-auth
 

五、深究原因

待研究,以后弄明白了再來補充
 

六、總結

1)一直把問題放在Docker上,沒去想其他方面,比如倉庫的問題
 
2)不要放過任何一個錯誤,其實service update的時候一直有報錯,如下:
[root@ip-172-0-0-111 ~]# docker service update centos7_nginx --image lile224/centos7_nginx:20191012
image lile224/centos7_nginx:20191012 could not be accessed on a registry to record
its digest. Each node will access lile224/centos7_nginx:20191012 independently,
possibly leading to different nodes running different
versions of the image.

centos7_nginx
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 
 
一直沒去管它,沒去仔細的看他,然后就是按照自己的想象在找原因;不要放過任何一個錯誤,多看;然后其實可以使用systemctl status docker看看docker的狀態時不時有error,一看果然是有的,然后得根據日志去查問題。
 
3)路還很長,得加油

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM