构建后端为etcd的CoreDNS的容器集群(二)、下载最新的etcd容器镜像

发布于:2024-10-17 ⋅ 阅读:(10) ⋅ 点赞:(0)

在尝试获取etcd的容器的最新版本镜像时,使用latest作为tag取到的并非最新版本,本文尝试用实际最新版本的版本号进行pull,从而取到想的最新版etcd容器镜像。

一、用latest作为tag尝试下载最新etcd的镜像

1、下载镜像
[root@localhost opt]# docker pull quay.io/coreos/etcd:latest
latest: Pulling from coreos/etcd
ff3a5c916c92: Pull complete 
96b0e24539ea: Pull complete 
d1eca4d01894: Pull complete 
ad732d7a61c2: Pull complete 
8bc526247b5c: Pull complete 
5f56944bb51c: Pull complete 
Digest: sha256:5b6691b7225a3f77a5a919a81261bbfb31283804418e187f7116a0a9ef65d21d
Status: Downloaded newer image for quay.io/coreos/etcd:latest
2、查看镜像
[root@localhost opt]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
quay.io/coreos/etcd   latest              61ad63875109        6 years ago         39.5MB

显示镜像创建日期为6年前,太离谱了

3、拉一个容器,查看镜像的具体版本
[root@localhost opt]# docker run -d   -p 2379:2379   -p 2380:2380   --name etcd   quay.io/coreos/etcd  /usr/local/bin/etcd   -advertise-client-urls http://0.0.0.0:2379   -listen-client-urls http://0.0.0.0:2379   -initial-advertise-peer-urls http://0.0.0.0:2380   -listen-peer-urls http://0.0.0.0:2380   -initial-cluster default=http://0.0.0.0:2380                          
7874cc64d5aeec551d805bcbc26965d51d3c291a704411b2b604e2735e7fe7a9
[root@localhost opt]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                              NAMES
7874cc64d5ae        quay.io/coreos/etcd   "/usr/local/bin/etcd…"   5 seconds ago       Up 3 seconds        0.0.0.0:2379-2380->2379-2380/tcp   etcd
[root@localhost opt]# docker exec -it  etcd /bin/sh
/ # 
/ # ps -ef
PID   USER     TIME   COMMAND
    1 root       0:00 /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://0.0.0.0:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster def
   18 root       0:00 /bin/sh
   29 root       0:00 ps -ef
/ # cd /usr/local/bin/
/usr/local/bin # etcd --version
etcd Version: 3.3.8
Git SHA: 33245c6b5
Go Version: go1.9.7
Go OS/Arch: linux/amd64

可见当前容器内的etcd版本为3.3.8,老的离谱。

二、查找etcd最新的正式版版本

查看etcd官方文档Documentation versions | etcd,可以看到当前最新的稳定版本为3.5.16

三、尝试用 3.5.16为tag拉取最新的etcd容器镜像

1、尝试拉取
[root@localhost opt]# docker pull quay.io/coreos/etcd:v3.5.16
v3.5.16: Pulling from coreos/etcd
804c8aba2cc6: Pull complete 
2ae710cd8bfe: Pull complete 
d462aa345367: Pull complete 
0f8b424aa0b9: Pull complete 
d557676654e5: Pull complete 
c8022d07192e: Pull complete 
d858cbc252ad: Pull complete 
1069fc2daed1: Pull complete 
b40161cd83fc: Pull complete 
5318d93a3a65: Pull complete 
307c1adadb60: Pull complete 
fbb01d9e9dc9: Pull complete 
fbfea02ac3cf: Pull complete 
8c26e4bf18e2: Pull complete 
1e59a65f8816: Pull complete 
ffbd4ca5f0bd: Pull complete 
Digest: sha256:d967d98a12dc220a1a290794711dba7eba04b8ce465e12b02383d1bfbb33e159
Status: Downloaded newer image for quay.io/coreos/etcd:v3.5.16
[root@localhost opt]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
quay.io/coreos/etcd   v3.5.16             8523cb381f23        5 weeks ago         59MB

可以看到镜像文件创建日期为几周前,应该是比较新了。

2、拉起容器检查应用程序版本
[root@localhost opt]# docker run -d   -p 2379:2379   -p 2380:2380   --name etcd   quay.io/coreos/etcd:v3.5.16  /usr/local/bin/etcd   -advertise-client-urls http://0.0.0.0:2379   -listen-client-urls http://0.0.0.0:2379   -initial-advertise-peer-urls http://0.0.0.0:2380   -listen-peer-urls http://0.0.0.0:2380   -initial-cluster default=http://0.0.0.0:2380 
225f0db2c3920b035659878f321f3d3cbda483acf5f11201b96653c48c16a8d5
[root@localhost opt]# docker ps
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                              NAMES
225f0db2c392        quay.io/coreos/etcd:v3.5.16   "/usr/local/bin/etcd…"   17 minutes ago      Up 17 minutes       0.0.0.0:2379-2380->2379-2380/tcp   etcd
[root@localhost opt]# docker exec -it  etcd /usr/local/bin/etcd --version
etcd Version: 3.5.16
Git SHA: f20bbad
Go Version: go1.22.7
Go OS/Arch: linux/amd64

可以看到当前程序包版本确为 3.5.16,达到目的。

总结:当pull拉取镜像时,可能由于镜像源维护的问题,导致用lasted作为tag拉到的并不是该容器的最新版,而需要结合实际应用的版本信息,用目标版本作为tag来pull,才能拿到真正想要的新版本。