最近今天,在研究docker swarm中服务的部署,发现一个非常奇怪的现象······
通过docker service create命令创建service,比如:
docker service create \ --with-registry-auth \ --name=nginx \ --replicas=3 \ --publish published=8080,target=80 \ 172.20.58.152/middleware/nginx:1.21.4
正常的逻辑,是不是每个节点上,都要拉取这个镜像,然后运行呢?
没错,在k8s里面也是这样的,不过,在swarm中不是这样的
登录其中一个task所在的主机
[root@nccztsjb-node-05 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 172.20.58.152/middleware/nginx <none> 9a8e1ec1235e 9 months ago 309MB 172.20.58.152/middleware/nginx <none> ea335eea17ab 10 months ago 141MB [root@nccztsjb-node-05 ~]#
奇怪不?明明在创建的service的时候,指定了镜像的tag:
172.20.58.152/middleware/nginx:1.21.4
可是work节点拉取之后,咋就没了呢?
百思不得其解之时,看到了官方的一个解释:
If you specify a tag, the manager (or the Docker client, if you use content trust) resolves that tag to a digest. When the request to create a container task is received on a worker node, the worker node only sees the digest, not the tag.
也就是说,如果指定了镜像的tag,manager节点会将tag解析成镜像的摘要。然后,worker节点接收到运行task的命令时,它只能看到镜像摘要,而不是tag.
所以,理解了吗
这个也是swarm集群中镜像的一个特点。
那要怎么看看镜像的摘要?
docker inspect <IMAGE_ID>就能查看镜像的ID了。
[root@nccztsjb-node-05 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 172.20.58.152/middleware/nginx <none> 9a8e1ec1235e 9 months ago 309MB 172.20.58.152/middleware/nginx <none> ea335eea17ab 10 months ago 141MB [root@nccztsjb-node-05 ~]# docker inspect 9a8e1ec1235e -f $"{{.RepoDigests}}" [172.20.58.152/middleware/nginx@sha256:7d0dd4475eacf253250a9712fa1333b93755611c05f3b7dcf9a48d03a699d867] [root@nccztsjb-node-05 ~]# [root@nccztsjb-node-05 ~]# docker inspect ea335eea17ab -f $"{{.RepoDigests}}" [172.20.58.152/middleware/nginx@sha256:2f14a471f2c2819a3faf88b72f56a0372ff5af4cb42ec45aab00c03ca5c9989f] [root@nccztsjb-node-05 ~]#
OK,那以后在swarm集群中部署service,再看到没有tag的镜像信息,就不要大惊小怪了哟!
标签:node,nginx,swarm,tag,镜像,docker,172.20 From: https://www.cnblogs.com/chuanzhang053/p/16707579.html