参考
学会了镜像的构建,下面研究如何在多个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:latest10 root@docker-lab:~/018# docker images timage-v1.9.111 REPOSITORY TAG IMAGE ID CREATED SIZE12 timage-v1.9.1 latest c6f978f27d36 4 minutes ago 1.2MB13 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:114 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1.915 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:1.9.116 root@docker-lab:~/018# docker tag timage-v1.9.1 timage:latest17 root@docker-lab:~/018# docker images timage18 REPOSITORY TAG IMAGE ID CREATED SIZE19 timage 1 c6f978f27d36 4 minutes ago 1.2MB20 timage 1.9 c6f978f27d36 4 minutes ago 1.2MB21 timage 1.9.1 c6f978f27d36 4 minutes ago 1.2MB22 timage latest c6f978f27d36 4 minutes ago 1.2MB23 root@docker-lab:~/018# docker build -t timage-v1.9.2 .24 Sending build context to Docker daemon 2.048kB25 Step 1/2 : FROM busybox26 ---> 3a093384ac3027 Step 2/2 : CMD echo testimage28 ---> Using cache29 ---> c6f978f27d3630 Successfully built c6f978f27d3631 Successfully tagged timage-v1.9.2:latest32 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:133 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1.934 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:1.9.235 root@docker-lab:~/018# docker tag timage-v1.9.2 timage:latest36 root@docker-lab:~/018# docker images timage37 REPOSITORY TAG IMAGE ID CREATED SIZE38 timage 1 c6f978f27d36 5 minutes ago 1.2MB39 timage 1.9 c6f978f27d36 5 minutes ago 1.2MB40 timage 1.9.1 c6f978f27d36 5 minutes ago 1.2MB41 timage 1.9.2 c6f978f27d36 5 minutes ago 1.2MB42 timage latest c6f978f27d36 5 minutes ago 1.2MB43 root@docker-lab:~/018# docker build -t timage-v2.0.0 .44 Sending build context to Docker daemon 2.048kB45 Step 1/2 : FROM busybox46 ---> 3a093384ac3047 Step 2/2 : CMD echo testimage48 ---> Using cache49 ---> c6f978f27d3650 Successfully built c6f978f27d3651 Successfully tagged timage-v2.0.0:latest52 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:253 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2.054 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:2.0.055 root@docker-lab:~/018# docker tag timage-v2.0.0 timage:latest56 root@docker-lab:~/018# docker images timage57 REPOSITORY TAG IMAGE ID CREATED SIZE58 timage 1 c6f978f27d36 6 minutes ago 1.2MB59 timage 1.9 c6f978f27d36 6 minutes ago 1.2MB60 timage 1.9.1 c6f978f27d36 6 minutes ago 1.2MB61 timage 1.9.2 c6f978f27d36 6 minutes ago 1.2MB62 timage 2 c6f978f27d36 6 minutes ago 1.2MB63 timage 2.0 c6f978f27d36 6 minutes ago 1.2MB64 timage 2.0.0 c6f978f27d36 6 minutes ago 1.2MB65 timage latest c6f978f27d36 6 minutes ago 1.2MB