018、容器命名最佳实践 (2019-01-09 周三)

 
 
学会了镜像的构建,下面研究如何在多个Docker Host上使用镜像
 
    1、用相同的Dockerfile 在其他host上进行构建
    2、将镜像上传到公共的Registry(比如 Docker Hub)上,其他host可以直接下载使用
    3、搭建私有的Registry 供内部使用
 
为了方便使用,镜像的命名比较重要。
 
1、标准的镜像名称   [ image name ] = [ repository ] : [ tag ]
 
    busybox:latest
 
 
 
2、latest tag 当不指明tag的时候,tag均为latest,仅此而已
 
docker build -t myimage
docker pull ubuntu
 
3、tag命名最佳实践
 
    一个高效的版本命名方案可以让用户更清楚的知道当前使用的是哪个镜像,同时还能保持足够的灵活性。
    这里借鉴软件版本的命名方式。
    每个repository可以有多个tag,而多个tag可能对应的是同一版镜像
 
timage:1         始终指向1分支中的最新版本
timage:1.9      始终指向1.9分支中的最新版本
timage:latest  始终指向所有版本中的最新版
 
如果想下载特定版本  docker pull timage:1.9.1
 
root@docker-lab:~/018# docker build -t timage-v1.9.1 .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM busybox
---> 3a093384ac30
Step 2/2 : CMD echo testimage
---> Using cache
---> c6f978f27d36
Successfully built c6f978f27d36
Successfully tagged timage-v1.9.1:latest
root@docker-lab:~/018# docker images timage-v1.9.1
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
timage-v1.9.1       latest              c6f978f27d36        4 minutes ago       1.2MB
root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1
root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1.9
root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1.9.1
root@docker-lab:~/018# docker tag timage-v1.9.1 timage:latest
root@docker-lab:~/018# docker images timage
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
timage              1                   c6f978f27d36        4 minutes ago       1.2MB
timage              1.9                 c6f978f27d36        4 minutes ago       1.2MB
timage              1.9.1               c6f978f27d36        4 minutes ago       1.2MB
timage              latest              c6f978f27d36        4 minutes ago       1.2MB
root@docker-lab:~/018# docker build -t timage-v1.9.2 .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM busybox
---> 3a093384ac30
Step 2/2 : CMD echo testimage
---> Using cache
---> c6f978f27d36
Successfully built c6f978f27d36
Successfully tagged timage-v1.9.2:latest
root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1
root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1.9
root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1.9.2
root@docker-lab:~/018# docker tag timage-v1.9.2 timage:latest
root@docker-lab:~/018# docker images timage
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
timage              1                   c6f978f27d36        5 minutes ago       1.2MB
timage              1.9                 c6f978f27d36        5 minutes ago       1.2MB
timage              1.9.1               c6f978f27d36        5 minutes ago       1.2MB
timage              1.9.2               c6f978f27d36        5 minutes ago       1.2MB
timage              latest              c6f978f27d36        5 minutes ago       1.2MB
root@docker-lab:~/018# docker build -t timage-v2.0.0 .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM busybox
---> 3a093384ac30
Step 2/2 : CMD echo testimage
---> Using cache
---> c6f978f27d36
Successfully built c6f978f27d36
Successfully tagged timage-v2.0.0:latest
root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2
root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2.0
root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2.0.0
root@docker-lab:~/018# docker tag timage-v2.0.0 timage:latest
root@docker-lab:~/018# docker images timage
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
timage              1                   c6f978f27d36        6 minutes ago       1.2MB
timage              1.9                 c6f978f27d36        6 minutes ago       1.2MB
timage              1.9.1               c6f978f27d36        6 minutes ago       1.2MB
timage              1.9.2               c6f978f27d36        6 minutes ago       1.2MB
timage              2                   c6f978f27d36        6 minutes ago       1.2MB
timage              2.0                 c6f978f27d36        6 minutes ago       1.2MB
timage              2.0.0               c6f978f27d36        6 minutes ago       1.2MB
timage              latest              c6f978f27d36        6 minutes ago       1.2MB
 
 
 
 1 root@docker-lab:~/018# docker build -t timage-v1.9.1 .
 2 Sending build context to Docker daemon  2.048kB
 3 Step 1/2 : FROM busybox
 4 ---> 3a093384ac30
 5 Step 2/2 : CMD echo testimage
 6 ---> Using cache
 7 ---> c6f978f27d36
 8 Successfully built c6f978f27d36
 9 Successfully tagged timage-v1.9.1:latest
10 root@docker-lab:~/018# docker images timage-v1.9.1
11 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
12 timage-v1.9.1       latest              c6f978f27d36        4 minutes ago       1.2MB
13 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1
14 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1.9
15 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1.9.1
16 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:latest
17 root@docker-lab:~/018# docker images timage
18 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
19 timage              1                   c6f978f27d36        4 minutes ago       1.2MB
20 timage              1.9                 c6f978f27d36        4 minutes ago       1.2MB
21 timage              1.9.1               c6f978f27d36        4 minutes ago       1.2MB
22 timage              latest              c6f978f27d36        4 minutes ago       1.2MB
23 root@docker-lab:~/018# docker build -t timage-v1.9.2 .
24 Sending build context to Docker daemon  2.048kB
25 Step 1/2 : FROM busybox
26 ---> 3a093384ac30
27 Step 2/2 : CMD echo testimage
28 ---> Using cache
29 ---> c6f978f27d36
30 Successfully built c6f978f27d36
31 Successfully tagged timage-v1.9.2:latest
32 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1
33 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1.9
34 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1.9.2
35 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:latest
36 root@docker-lab:~/018# docker images timage
37 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
38 timage              1                   c6f978f27d36        5 minutes ago       1.2MB
39 timage              1.9                 c6f978f27d36        5 minutes ago       1.2MB
40 timage              1.9.1               c6f978f27d36        5 minutes ago       1.2MB
41 timage              1.9.2               c6f978f27d36        5 minutes ago       1.2MB
42 timage              latest              c6f978f27d36        5 minutes ago       1.2MB
43 root@docker-lab:~/018# docker build -t timage-v2.0.0 .
44 Sending build context to Docker daemon  2.048kB
45 Step 1/2 : FROM busybox
46 ---> 3a093384ac30
47 Step 2/2 : CMD echo testimage
48 ---> Using cache
49 ---> c6f978f27d36
50 Successfully built c6f978f27d36
51 Successfully tagged timage-v2.0.0:latest
52 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2
53 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2.0
54 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2.0.0
55 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:latest
56 root@docker-lab:~/018# docker images timage
57 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
58 timage              1                   c6f978f27d36        6 minutes ago       1.2MB
59 timage              1.9                 c6f978f27d36        6 minutes ago       1.2MB
60 timage              1.9.1               c6f978f27d36        6 minutes ago       1.2MB
61 timage              1.9.2               c6f978f27d36        6 minutes ago       1.2MB
62 timage              2                   c6f978f27d36        6 minutes ago       1.2MB
63 timage              2.0                 c6f978f27d36        6 minutes ago       1.2MB
64 timage              2.0.0               c6f978f27d36        6 minutes ago       1.2MB
65 timage              latest              c6f978f27d36        6 minutes ago       1.2MB

 

posted @ 2019-01-10 01:11  三角形  阅读(199)  评论(0编辑  收藏  举报