[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
语法:docker search [options] term
options说明:
[root@centos7-docker ~]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 3093 [OK]
tomee Apache TomEE is an all-Apache Java EE certif… 91 [OK]
dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base… 57 [OK]
kubeguide/tomcat-app Tomcat image for Chapter 1 30
consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 18 [OK]
cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]
aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 13 [OK]
#第一列:仓库源名称
#第二列:描述
#第三列:星星
#第四列:是否是官方发布
#第五列:是否是自动构建
#查看星星50个,描述详细的tomcat
[root@centos7-docker ~]# docker search -f stars=50 --no-trunc tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementation of the Java Servlet and JavaServer Pages technologies 3093 [OK]
tomee Apache TomEE is an all-Apache Java EE certified stack where Apache Tomcat is top dog. 91 [OK]
dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 based docker container. 57 [OK]
语法:docker pull name:tag
例如:docker pull nginx #不加tag,默认拉取最新的
当我们拉取下来的镜像不能满足需求的时候,想自己设计一个,两种方法
查看当前系统镜像
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zhanghaodong/ubuntu v1 f990b7b8a364 7 minutes ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
在centos:latest里安装httpd软件
[root@centos7-docker ~]# docker run -it centos /bin/bash
[root@c7bb5f3a8293 /]# yum -y install httpd
[root@c7bb5f3a8293 /]# rpm -qa | grep -i httpd
httpd-tools-2.4.37-39.module_el8.4.0+778+c970deab.x86_64
centos-logos-httpd-85.8-1.el8.noarch
httpd-filesystem-2.4.37-39.module_el8.4.0+778+c970deab.noarch
httpd-2.4.37-39.module_el8.4.0+778+c970deab.x86_64
[root@c7bb5f3a8293 /]# exit
exit
这个时候退出了,如果再重新进的话,还是原来新的镜像,我需要安装httpd之后的镜像
查看刚才运行centos后的容器ID,进行提交
#看到刚才运行过的centos容器的ID是:c7开头的那个
[root@centos7-docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7bb5f3a8293 centos "/bin/bash" 3 minutes ago Exited (0) About a minute ago youthful_fermi
#进行提交,这里报错了,仓库源首字母不能是大写的
[root@centos7-docker ~]# docker commit -m "install httpd soft" -a "Hejing" c7 Hejing/centos:v1
invalid reference format: repository name must be lowercase
#修改后重新提交
[root@centos7-docker ~]# docker commit -m "install httpd soft" -a "Hejing" c7 hejing/centos:v1
sha256:0e4de65ea5c91925bd262ccb1ae547ae59aab296dc79ac6da1970056132579d9
#查看本地镜像
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hejing/centos v1 0e4de65ea5c9 4 seconds ago 259MB
zhanghaodong/ubuntu v1 f990b7b8a364 27 minutes ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
#进入安装httpd之后的镜像看一下,no problem
[root@centos7-docker ~]# docker run -it hejing/centos:v1 /bin/bash
[root@497b09e5d905 /]# rpm -qa | grep -i httpd
httpd-tools-2.4.37-39.module_el8.4.0+778+c970deab.x86_64
centos-logos-httpd-85.8-1.el8.noarch
httpd-filesystem-2.4.37-39.module_el8.4.0+778+c970deab.noarch
httpd-2.4.37-39.module_el8.4.0+778+c970deab.x86_64
dockerfile指令介绍
Dockerfile需要放置在项目的根目录的位置
在构建的时候,Dockerfile client会把整个context打包发送到Docker server端,然后由server端负责build镜像,在构建成功后,会删除context目录
docker build -t {镜像名字} {项目路径可以是相对路径}
docker利用Dockerfile来构建新镜像之前,先介绍一下Dockerfile常用的指令
docker build -t {镜像名字} - < Dockerfile路径
格式为:EXPOSE <端口1> [<端口2>...]
EXPOSE指令是声明运行时容器提供服务端口,这只是一个声明,在运行时并不会因为这个声明,应用就会开启这个端口的服务。在Dockerfile中写入这样的声明有两个好处:
docker run -P
的时候,会自动映射EXPOSE的端口ENV key value
ONBUILD
指令实践,let's do it
先看下本地image,选一个作为base image:
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hejing/centos v1 0e4de65ea5c9 21 hours ago 259MB
zhanghaodong/ubuntu v1 f990b7b8a364 21 hours ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hejing/hello-world v1 d1165f221234 5 months ago 13.3kB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
centos 7 8652b9f0cb4c 9 months ago 204MB
新建一个专门存放此demo的目录docker_demo,也就是Dockerfile所在的context:
[root@centos7-docker ~]# mkdir docker_demo
[root@centos7-docker ~]# cd docker_demo/
[root@centos7-docker docker_demo]# touch Dockerfile
[root@centos7-docker docker_demo]# pwd
/root/docker_demo
接下来编写Dockfile文件(D要大写,必须的)
这里以编译nginx提供web服务来构建新的image
1.下载ngixn源码包到docker_demo目录下:
下载地址:http://nginx.org/en/download.html
[root@centos7-docker docker_demo]# ll
total 960
-rw-r--r--. 1 root root 0 Aug 13 23:10 Dockerfile
-rw-r--r--. 1 root root 981687 Aug 13 23:14 nginx-1.12.2.tar.gz
2.下面是编写好的Dockerfile v1版本:
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
FROM centos
# MAINTAINER
MAINTAINER hejing
# put nginx-1.12.2.tar.gz into /usr/local/src and unpack nginx
# the ADD can unpack tar
ADD nginx-1.12.2.tar.gz /usr/local/src
# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx
# change dir to /usr/local/src/nginx-1.12.2
WORKDIR /usr/local/src/nginx-1.12.2
# execute command to complie nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
EXPOSE 80
3.查看docker_demo目录情况:
[root@centos7-docker docker_demo]# ll
total 964
-rw-r--r--. 1 root root 1106 Aug 13 23:24 Dockerfile
-rw-r--r--. 1 root root 981687 Aug 13 23:14 nginx-1.12.2.tar.gz
4.执行docker build进行构建
命令:docker build -t centos_nginx:v1 .
或docker build -t centos_nginx:v1 /root/docker_demo
后面的.
代表的是相对路径的当前目录,如果需要全路径就是上面的方式(就是找到Dockerfile文件)
[root@centos7-docker docker_demo]# docker build -t centos7_nginx:v1 . --no-cache
Sending build context to Docker daemon 985.6kB
Step 1/9 : FROM centos:7
---> 8652b9f0cb4c
Step 2/9 : MAINTAINER hejing
---> Running in e59af95193e1
Removing intermediate container e59af95193e1
---> a5465d667dd3
Step 3/9 : ADD nginx-1.12.2.tar.gz /usr/local/src
---> 3ae678f3c162
Step 4/9 : RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
---> Running in f0390567bfee
......
Step 5/9 : RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
---> Running in e1441bb1cd65
Step 6/9 : RUN useradd -M -s /sbin/nologin nginx
---> Running in d5151e31e9d6
Removing intermediate container d5151e31e9d6
---> 8541c8342250
Step 7/9 : WORKDIR /usr/local/src/nginx-1.12.2
---> Running in be68dcd91e6e
Removing intermediate container be68dcd91e6e
---> 5b6f6148ab37
Step 8/9 : RUN ./configure --user=nginx.......
Step 9/9 : EXPOSE 80
---> Running in a9fb28cfabfa
Removing intermediate container a9fb28cfabfa
---> 1ffc4a8e3106
Successfully built 1ffc4a8e3106
Successfully tagged centos7_nginx:v1
构建成功,查看新构建的镜像:
[root@centos7-docker docker_demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v1 1ffc4a8e3106 8 minutes ago 673MB
hejing/centos v1 0e4de65ea5c9 21 hours ago 259MB
zhanghaodong/ubuntu v1 f990b7b8a364 21 hours ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hejing/hello-world v1 d1165f221234 5 months ago 13.3kB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
centos 7 8652b9f0cb4c 9 months ago 204MB
5.使用新构建的镜像启动一个container并开启nginx服务
[root@centos7-docker docker_demo]# docker run -d centos7_nginx:v1 /usr/local/nginx/sbin/nginx -g "daemon off";
4d3a523292df47b59179470af76982583c4194de16c855c3907e055f1484b07d
查看启动的container是否则正在运行:
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d3a523292df centos7_nginx:v1 "/usr/local/nginx/sb…" 52 seconds ago Exited (1) 51 seconds ago trusting_swanson
在这里启动刚才构建的镜像失败了,看了一下message日志,显示如下:
Aug 14 05:50:29 centos7-docker containerd: time="2021-08-14T05:50:29.471934866-04:00" level=info msg="shim disconnected" id=f194c83d48ecaefacf949f0bc401b3317e1dc90af34cc9d2fa4cc
Aug 14 05:50:29 centos7-docker containerd: time="2021-08-14T05:50:29.472029803-04:00" level=error msg="copy shim log" error="reaf/fd/12: file already closed"
Aug 14 05:50:29 centos7-docker kernel: docker0: port 1(veth8dd62fb) entered disabled state
Aug 14 05:50:29 centos7-docker NetworkManager[5999]: [1628934629.5061] manager: (veth201db61): new Veth device (/org/fretworkManager/Devices/180)
Aug 14 05:50:29 centos7-docker kernel: docker0: port 1(veth8dd62fb) entered disabled state
Aug 14 05:50:29 centos7-docker kernel: device veth8dd62fb left promiscuous mode
Aug 14 05:50:29 centos7-docker kernel: docker0: port 1(veth8dd62fb) entered disabled state
Aug 14 05:50:29 centos7-docker NetworkManager[5999]: [1628934629.5259] device (veth8dd62fb): released from master device
Aug 14 05:51:51 centos7-docker systemd: Stopping Docker Application C ontainer Engine...
不晓得是怎么回事,看到了NetworManager,于是查看了一下host的网络服务,发现network服务和Neworkmanager都activing开启着,尝试停止了一下NetworkManager服务,再次重启镜像,发现成功了
这个问题可以详细的看一下这一篇博客http://www.cocoachina.com/articles/60742
虽然nginx服务开启了,但是port并没有进行映射到本机host,所以这个container并不能进行访问,重新启动一个进行映射端口的容器
[root@centos7-docker docker_demo]# docker run -d -p80:80 centos7_nginx:v1 /usr/local/nginx/sbin/nginx -g "daemon off;"
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
856bf5558811 centos7_nginx:v1 "/usr/local/nginx/sb…" 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp jovial_heyrovsky
再次查看端口信息(docker port container-ID即可):
[root@centos7-docker docker_demo]# docker port 85
80/tcp -> 0.0.0.0:80
80/tcp -> :::80
浏览器访问:
6.于是基于Dockerfile的一个简单实例构建完成,现在基于这个Dockerfile文件依次添加其他的指令进行构建
6.1 添加ENV环境便令指令
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
FROM centos:7
# # MAINTAINER
MAINTAINER hejing
# put nginx-1.12.2.tar.gz into /usr/local/src and unpack nginx
# the ADD can unpack tar
ADD nginx-1.12.2.tar.gz /usr/local/src
# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx
# change dir to /usr/local/src/nginx-1.12.2
WORKDIR /usr/local/src/nginx-1.12.2
# execute command to complie nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
然后进行构建:
[root@centos7-docker docker_demo]# docker build -t centos7_nginx:v2 .
Sending build context to Docker daemon 985.6kB
Step 1/10 : FROM centos:7
---> 8652b9f0cb4c
Step 2/10 : MAINTAINER hejing
---> Using cache
---> a5465d667dd3
Step 3/10 : ADD nginx-1.12.2.tar.gz /usr/local/src
---> Using cache
---> 3ae678f3c162
Step 4/10 : RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
---> Using cache
---> b49fa8555f64
Step 5/10 : RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
---> Using cache
---> a81a9003b1bb
Step 6/10 : RUN useradd -M -s /sbin/nologin nginx
---> Using cache
---> 8541c8342250
Step 7/10 : WORKDIR /usr/local/src/nginx-1.12.2
---> Using cache
---> 5b6f6148ab37
Step 8/10 : RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
---> Using cache
---> adc42b044d17
Step 9/10 : ENV PATH /usr/local/nginx/sbin:$PATH
---> Running in 5cba8cea3ff0
Removing intermediate container 5cba8cea3ff0
---> 37426b9520d6
Step 10/10 : EXPOSE 80
---> Running in 300ae44ca128
Removing intermediate container 300ae44ca128
---> fad261761053
Successfully built fad261761053
Successfully tagged centos7_nginx:v2
docker有个神奇的功能,上文中说到,docker会尽量以重构的镜像来构建新镜像。即Dockerfile会尽可能尝试重用已经构建的镜像
,所以在构建v2的时候很快哦
docker在构建的过程中会采用缓存机制,在构建v2的时候就包含了很多using cache,所以构建的很快,如果你想重新构建的话,不想使用cache的话,那就在构建的时候加一个--no-cache
吧
--no-cache Do not use cache when building the image
查看v2版本的镜像
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v2 fad261761053 9 minutes ago 673MB
centos7_nginx v1 1ffc4a8e3106 59 minutes ago 673MB
hejing/centos v1 0e4de65ea5c9 22 hours ago 259MB
zhanghaodong/ubuntu v1 f990b7b8a364 22 hours ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB
hejing/hello-world v1 d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
centos 7 8652b9f0cb4c 9 months ago 204MB
下面使用v2版本启动一个container
[root@centos7-docker ~]# docker run -d -p81:80 centos7_nginx:v2 nginx -g "daemon off;"
2c8d00cb0b3ca5808593bd5392cdfffbcbe7647a55a2cb77429ba29bfc8735bb
[root@centos7-docker ~]# docker port 2c
80/tcp -> 0.0.0.0:81
80/tcp -> :::81
[root@centos7-docker ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c8d00cb0b3c centos7_nginx:v2 "nginx -g 'daemon of…" 30 seconds ago Up 29 seconds 0.0.0.0:81->80/tcp, :::81->80/tcp sharp_dewdney
浏览器访问:
上述使用的命令是:
docker run -d -p81:80 centos7_nginx:v2 nginx -g "daemon off;"
没有用/usr/local/nginx/sbin/nginx
来启动,是因为我们在Dockerfile文件中执行了ENV啊,添加了环境变量而已
ENV PATH /usr/local/nginx/sbin:$PATH
6.2 添加指令CMD
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
FROM centos:7
# # MAINTAINER
MAINTAINER hejing
# put nginx-1.12.2.tar.gz into /usr/local/src and unpack nginx
# the ADD can unpack tar
ADD nginx-1.12.2.tar.gz /usr/local/src
# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx
# change dir to /usr/local/src/nginx-1.12.2
WORKDIR /usr/local/src/nginx-1.12.2
# execute command to complie nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
CMD /bin/sh -c 'nginx -g "daemon off;"'
然后进行构建:
[root@centos7-docker docker_demo]# docker build -t centos7_nginx:v3 .
查看构建的镜像:
[root@centos7-docker docker_demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v3 034fca0d39d2 34 seconds ago 673MB
centos7_nginx v2 fad261761053 25 minutes ago 673MB
centos7_nginx v1 1ffc4a8e3106 About an hour ago 673MB
基于v3镜像启动container:
[root@centos7-docker docker_demo]# docker run -d -p82:80 centos7_nginx:v3
95daa1ad57d7c26961e9d3a1804c836c46e52a68eb3923107fd6af0e756acb3d
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
95daa1ad57d7 centos7_nginx:v3 "/bin/sh -c '/bin/sh…" 7 seconds ago Up 6 seconds 0.0.0.0:82->80/tcp, :::82->80/tcp sharp_keller
[root@centos7-docker docker_demo]# docker port 95
80/tcp -> 0.0.0.0:82
80/tcp -> :::82
浏览器访问:
新增加的CMD /bin/sh -c 'nginx -g "daemon off;"'
表示:
当启动一个container时默认运行的命令,如果在启动container时赋予了command的话,那么定义的CMD中的命令将不会被执行,而是会执行command的命令
6.3 添加ENTRYPOINT指令:
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
FROM centos:7
# # MAINTAINER
MAINTAINER hejing
# put nginx-1.12.2.tar.gz into /usr/local/src and unpack nginx
# the ADD can unpack tar
ADD nginx-1.12.2.tar.gz /usr/local/src
# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx
# change dir to /usr/local/src/nginx-1.12.2
WORKDIR /usr/local/src/nginx-1.12.2
# execute command to complie nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]
当ENTRYPOINT和CMD连用时,CMD的命令是ENTRYPOINT命令的参数,两者连用相当于nginx -g “daemon off;”
而当一起连用的时候命令格式最好一致(这里选择的都是json格式的是成功的,如果是sh模式可以试一下)
开始构建v4版本镜像:
[root@centos7-docker docker_demo]# docker build -t centos7_nginx:v4 .
查看v4版本的镜像:
[root@centos7-docker docker_demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v4 586517a9d3a0 40 seconds ago 673MB
centos7_nginx v3 034fca0d39d2 16 minutes ago 673MB
centos7_nginx v2 fad261761053 41 minutes ago 673MB
centos7_nginx v1 1ffc4a8e3106 2 hours ago 673MB
基于v4镜像启动一个container:
[root@centos7-docker docker_demo]# docker run -d -p83:80 centos7_nginx:v4
9e28be9c461f5c0c5489c6fa56612c4fed7bb3f4e77f439479765535b6b3578d
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9e28be9c461f centos7_nginx:v4 "nginx -g 'daemon of…" 5 seconds ago Up 3 seconds 0.0.0.0:83->80/tcp, :::83->80/tcp laughing_buck
[root@centos7-docker docker_demo]# docker port 9
Error response from daemon: Multiple IDs found with provided prefix: 9
[root@centos7-docker docker_demo]# docker port 9e
80/tcp -> 0.0.0.0:83
80/tcp -> :::83
6.4 测试command和CMD运行是否冲突,以哪个为准
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
FROM centos:7
# # MAINTAINER
MAINTAINER hejing
# put nginx-1.12.2.tar.gz into /usr/local/src and unpack nginx
# the ADD can unpack tar
ADD nginx-1.12.2.tar.gz /usr/local/src
# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx
# change dir to /usr/local/src/nginx-1.12.2
WORKDIR /usr/local/src/nginx-1.12.2
# execute command to complie nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
ENTRYPOINT ["nginx"]
CMD ["-g","daemon on;"]
CMD的命令修改为了后台,我们知道如果容器内的进程在后台运行那么容器将不会运行
现在构建v5版本镜像:
[root@centos7-docker docker_demo]# docker build -t centos7_nginx:v5 .
查看v5版本镜像:
[root@centos7-docker docker_demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v5 00e0e71aa40f 42 seconds ago 673MB
centos7_nginx v4 586517a9d3a0 8 minutes ago 673MB
centos7_nginx v3 034fca0d39d2 24 minutes ago 673MB
centos7_nginx v2 fad261761053 49 minutes ago 673MB
centos7_nginx v1 1ffc4a8e3106 2 hours ago 673MB
现在直接利用v5启动container,不加什么其他命令的话,查看container是否能够运行:
[root@centos7-docker docker_demo]# docker run -d -p85:80 centos7_nginx:v5
1e20de8048e2bfe43942cc908f4bfafae1005cd55fede6176b126f83d428fc9f
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e20de8048e2 centos7_nginx:v5 "nginx -g 'daemon on…" 4 seconds ago Exited (0) 4 seconds ago friendly_leakey
可以看到容器exit了
下面这样启动container:
[root@centos7-docker docker_demo]# docker run -d -p85:80 centos7_nginx:v5 -g "daemon off;"
354bb397fb44792c52496e9ce25d189cc2f5177e5c86964043fccbe532a894c3
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
354bb397fb44 centos7_nginx:v5 "nginx -g 'daemon of…" 5 seconds ago Up 4 seconds 0.0.0.0:85->80/tcp, :::85->80/tcp focused_turing
[root@centos7-docker docker_demo]# docker port 354
80/tcp -> 0.0.0.0:85
80/tcp -> :::85
可以看到在后面添加了command之-g "daemon off;"
,容器的启动丝毫没有受影响。
上问说过如果新加了command命令后,Dockfile中的CMD命令将不会生效,就是这样
浏览器访问:
6.5 添加VOLUME指令
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
FROM centos:7
# # MAINTAINER
MAINTAINER hejing
# put nginx-1.12.2.tar.gz into /usr/local/src and unpack nginx
# the ADD can unpack tar
ADD nginx-1.12.2.tar.gz /usr/local/src
# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx
# mount a dit to container
VOLUME ["/data"]
# change dir to /usr/local/src/nginx-1.12.2
WORKDIR /usr/local/src/nginx-1.12.2
# execute command to complie nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
ENTRYPOINT ["nginx"]
CMD ["-g"]
开始构建v6:
[root@centos7-docker docker_demo]# docker build -t centos7_nginx:v6 .
查看v6版本镜像:
[root@centos7-docker docker_demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v6 68954acd27d5 39 seconds ago 673MB
centos7_nginx v5 00e0e71aa40f 11 minutes ago 673MB
centos7_nginx v4 586517a9d3a0 19 minutes ago 673MB
centos7_nginx v3 034fca0d39d2 35 minutes ago 673MB
centos7_nginx v2 fad261761053 About an hour ago 673MB
centos7_nginx v1 1ffc4a8e3106 2 hours ago 673MB
基于v6启动container:
[root@centos7-docker docker_demo]# docker run -d -p86:80 --name=nginx6 centos7_nginx:v6 -g "daemon off;"
7d587fb786ab27c93d8790951410b361445b5de78d4999eb4e2a33b55f33a232
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7d587fb786ab centos7_nginx:v6 "nginx -g 'daemon of…" 6 seconds ago Up 5 seconds 0.0.0.0:86->80/tcp, :::86->80/tcp nginx6
[root@centos7-docker docker_demo]# docker port 7d5
80/tcp -> 0.0.0.0:86
80/tcp -> :::86
利用docker exec进入到container中,查看是否存在卷/data:
[root@centos7-docker docker_demo]# docker exec -it 7d5 /bin/bash
[root@7d587fb786ab /]# ls -ld data/
drwxr-xr-x. 2 root root 6 Aug 14 11:06 data/
这个data目录挂载的目录对应本机host的这个目录
[root@centos7-docker _data]# pwd
/var/lib/docker/volumes/2aee288aa9c7545e0f6e3ccbcb11a52217a33d0b56807ee40d301534ece62067/_data
现在在本机host上的目录创建一个文件:
[root@centos7-docker _data]# pwd
/var/lib/docker/volumes/2aee288aa9c7545e0f6e3ccbcb11a52217a33d0b56807ee40d301534ece62067/_data
[root@centos7-docker _data]# touch 8888
然后到container的data下查看是否有8888
[root@7d587fb786ab data]# ls
8888
6.6 添加ONBUILD指令:
Dockerfile1中base image为A镜像,并在Dcokerfile1中定义ONBUILD指令,构建成镜像B镜像
Dockerfile2中base image为B镜像,构建成镜像C
当使用镜像B启动container1不会执行ONBUILD中定义的内容,而使用C镜像启动container2则会执行ONBUILD定义的内容
dockerfile1中:A镜像-centos:7为base image,里面有OBNBUILD指令------形成B-v7版本
dockerfile2中:以B镜像v7为base image,构建镜像c-v8
当使用v7启动container,不会执行ONBUILD
当使用v8启动container,会执行ONBUILD
centos:7-----构建centos7_nginx:v7------构建centos7_nginx:v8
A: centos:7到 | B: centos7_nginx:v7到 | C: centos7_nginx:v8 |
---|---|---|
Dockerfile中有ONBUILD指令 | 以此image启动的container不执行ONBUILD内容 | 以此image启动的container会执行ONBUILD内容 |
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
FROM centos:7
# # MAINTAINER
MAINTAINER hejing
# put nginx-1.12.2.tar.gz into /usr/local/src and unpack nginx
# the ADD can unpack tar
ADD nginx-1.12.2.tar.gz /usr/local/src
# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx
# mount a dit to container
ONBUILD VOLUME ["/data"]
# change dir to /usr/local/src/nginx-1.12.2
WORKDIR /usr/local/src/nginx-1.12.2
# execute command to complie nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
ENTRYPOINT ["nginx"]
CMD ["-g"]
使用上面的Dockfile构建镜像v7
docker build -t centos7_nginx:v7 .
查看images
[root@centos7-docker docker_demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v7 003b917060be 38 seconds ago 673MB
centos7_nginx v6 68954acd27d5 19 hours ago 673MB
centos7_nginx v5 00e0e71aa40f 19 hours ago 673MB
centos7_nginx v4 586517a9d3a0 19 hours ago 673MB
centos7_nginx v3 034fca0d39d2 20 hours ago 673MB
centos7_nginx v2 fad261761053 20 hours ago 673MB
centos7_nginx v1 1ffc4a8e3106 21 hours ago 673MB
运行v7版本镜像
[root@centos7-docker docker_demo]# docker run -d -p87:80 --name=nginx7 centos7_nginx:v7 -g "daemon off;" 99940fb7029d9198048f2edf2fa79f094b2e86482c9cb185ffaf377e625cdace
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99940fb7029d centos7_nginx:v7 "nginx -g 'daemon of…" 20 seconds ago Up 19 seconds 0.0.0.0:87->80/tcp, :::87->80/tcp nginx7
[root@centos7-docker docker_demo]# docker port 999
80/tcp -> 0.0.0.0:87
80/tcp -> :::87
现在进入到容器查看是否有/data
[root@centos7-docker docker_demo]# docker exec -it nginx7 /bin/bash
[root@99940fb7029d nginx-1.12.2]# ll /data
ls: cannot access /data: No such file or directory
现在修改上面的Dockerfile1中的base imagem,并形成Dcokerfile2
[root@centos7-docker docker_demo]# cat Dockerfile
# base image
#FROM centos:7
FROM centos7_nginx:v7
......
现在基于Dockerfile2,开始构建新镜像v8:
[root@centos7-docker docker_demo]# docker build -t centos7_nginx:v8 .
查看v8版本镜像:
[root@centos7-docker docker_demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v8 d52a7cd5a1ed 10 seconds ago 976MB
centos7_nginx v7 003b917060be 13 minutes ago 673MB
centos7_nginx v6 68954acd27d5 19 hours ago 673MB
centos7_nginx v5 00e0e71aa40f 20 hours ago 673MB
centos7_nginx v4 586517a9d3a0 20 hours ago 673MB
centos7_nginx v3 034fca0d39d2 20 hours ago 673MB
centos7_nginx v2 fad261761053 20 hours ago 673MB
centos7_nginx v1 1ffc4a8e3106 21 hours ago 673MB
现在基于v8启动container:
[root@centos7-docker docker_demo]# docker run -d -p88:80 centos7_nginx:v8 -g "daemon off;"
eeea3992637f39cb33532feb620f302ddd92c7c06528a5fea25a4fcee2fb2729
[root@centos7-docker docker_demo]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eeea3992637f centos7_nginx:v8 "nginx -g 'daemon of…" 4 seconds ago Up 3 seconds 0.0.0.0:88->80/tcp, :::88->80/tcp sleepy_elbakyan
[root@centos7-docker docker_demo]# docker port eee
80/tcp -> 0.0.0.0:88
80/tcp -> :::88
进入container查看data是否存在:
[root@centos7-docker ~]# docker exec -it eee /bin/bash
[root@eeea3992637f nginx-1.12.2]# ll /data
total 0
使用docker tag为镜像添加新的标签
查看本地镜像
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hejing/centos v1 0e4de65ea5c9 17 minutes ago 259MB
zhanghaodong/ubuntu v1 f990b7b8a364 44 minutes ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
下面给hello-world换一个标签
[root@centos7-docker ~]# docker tag d11 hejing/hello-world:v1
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hejing/centos v1 0e4de65ea5c9 18 minutes ago 259MB
zhanghaodong/ubuntu v1 f990b7b8a364 45 minutes ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hejing/hello-world v1 d1165f221234 5 months ago 13.3kB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
#可以看到镜像ID为d11的有两个标签
docker数据卷备份和还原
[root@centos7-docker ~]# docker run -v /data -d -p80:80 --name=web1 centos7_nginx:v8 -g "daemon off;"
f1be21798741dd02a3bf3073e4f35778829b9fd36726912db65271fae2c42bfc
[root@centos7-docker volumes]# docker exec -it f1 /bin/bash
[root@f1be21798741 nginx-1.12.2]# cd /data/
[root@f1be21798741 data]# ls
[root@f1be21798741 data]# mkdir hejing
[root@f1be21798741 data]# vi hejing/web1.txt
[root@f1be21798741 data]# cat hejing/web1.txt
this is in web1
创建另外一个容器以上面web1容器作为共享数据卷,并将共享的数据卷进行tar压缩备份,并通过映射到本机host
命令解释:
总:创建一个新容器数据卷基于共享web1容器的数据卷,将数据卷进行tar压缩到容器内某个目录,并映射到本机目录
[root@centos7-docker ~]# docker run -d --volumes-from web1 -v /root/backup:/backup centos:7 tar cvf /backup/data.tar /data
faf11579491a0437a3a89b6ebd4ad87c4b4cc6c2702c57b10feb2baedf78aff2
[root@centos7-docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1be21798741 centos7_nginx:v8 "nginx -g 'daemon of…" 11 minutes ago Up 11 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp web1
[root@centos7-docker ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
faf11579491a centos:7 "tar cvf /backup/dat…" 12 seconds ago Exited (0) 11 seconds ago amazing_chatelet
[root@centos7-docker ~]# ls
anaconda-ks.cfg backup docker_demo rpmbuild
[root@centos7-docker ~]# ls backup/data.tar
backup/data.tar
[root@centos7-docker ~]# tar -xf backup/data.tar
[root@centos7-docker ~]# ls
anaconda-ks.cfg backup data docker_demo rpmbuild
[root@centos7-docker ~]# cd data/hejing/
[root@centos7-docker hejing]# ls
web1.txt
[root@centos7-docker hejing]# cat web1.txt
this is in web1
涉及到的命令:export、import、save、load
其中save和load针对的是image
export和import针对的是container
区别:容器的快照信息将丢弃历史记录和元数据信息(只保留容器当时的快照状态),而镜像的存储文件将保存完整记录。
格式:docker save [options] image [images]
[root@centos7-docker ~]# docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
-o, --output string Write to a file, instead of STDOUT
-o和>表示输出到文件,xxx.tar是目标文件,centos7_nginx:v8是源镜像名,目标文件后跟image id也可以
#查看host本机镜像
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v8 d52a7cd5a1ed 2 hours ago 976MB
centos7_nginx v7 003b917060be 2 hours ago 673MB
centos7_nginx v6 68954acd27d5 21 hours ago 673MB
centos7_nginx v5 00e0e71aa40f 21 hours ago 673MB
centos7_nginx v4 586517a9d3a0 21 hours ago 673MB
centos7_nginx v3 034fca0d39d2 22 hours ago 673MB
centos7_nginx v2 fad261761053 22 hours ago 673MB
centos7_nginx v1 1ffc4a8e3106 23 hours ago 673MB
hejing/centos v1 0e4de65ea5c9 44 hours ago 259MB
zhanghaodong/ubuntu v1 f990b7b8a364 44 hours ago 63.1MB
ubuntu 18.04 39a8cfeef173 2 weeks ago 63.1MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hejing/hello-world v1 d1165f221234 5 months ago 13.3kB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
centos 7 8652b9f0cb4c 9 months ago 204MB
方法1:
[root@centos7-docker ~]# docker save -o centos7_nginx-v9.tar centos7_nginx:v8
[root@centos7-docker ~]# ls
anaconda-ks.cfg backup centos7_nginx-v9.tar docker_demo rpmbuild
方法2:
[root@centos7-docker ~]# docker save > centos7_nginx-v10.tar centos7_nginx:v8
[root@centos7-docker ~]# ls
anaconda-ks.cfg backup centos7_nginx-v10.tar centos7_nginx-v9.tar docker_demo rpmbuild
方法3:
[root@centos7-docker ~]# docker save > centos7_nginx-v11.tar d52
[root@centos7-docker ~]# ls
anaconda-ks.cfg backup centos7_nginx-v10.tar centos7_nginx-v11.tar centos7_nginx-v9.tar docker_demo rpmbuild
格式:docker load [options]
[root@centos7-docker ~]# docker load --help
Usage: docker load [OPTIONS]
Load an image from a tar archive or STDIN
Options:
-i, --input string Read from tar archive file, instead of STDIN
-q, --quiet Suppress the load output
其中-i和<表示从文件输入,会成功导入镜像及相关元数据,包括tag
[root@centos7-docker ~]# docker load -i centos7_nginx-v11.tar
或者
[root@centos7-docker ~]# docker load < centos7_nginx-v11.tar
58149cafb515: Loading layer [==================================================>] 6.121MB/6.121MB
ce85612a8b78: Loading layer [==================================================>] 130.6MB/130.6MB
94a3447f3146: Loading layer [==================================================>] 130.5MB/130.5MB
929ffd789d18: Loading layer [==================================================>] 36.33MB/36.33MB
Loaded image ID: sha256:d52a7cd5a1ed35bde142d453f36b0c542ecd130338f5518f142f458b6fd1159f
#导入之后发现源仓库和tag都是
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
d52a7cd5a1ed 2 hours ago 976MB
centos7_nginx v7 003b917060be 2 hours ago 673MB
centos7_nginx v6 68954acd27d5 22 hours ago 673MB
centos7_nginx v5 00e0e71aa40f 22 hours ago 673MB
centos7_nginx v4 586517a9d3a0 22 hours ago 673MB
centos7_nginx v3 034fca0d39d2 22 hours ago 673MB
centos7_nginx v2 fad261761053 22 hours ago 673MB
centos7_nginx v1 1ffc4a8e3106 23 hours ago 673MB
#更改源仓库和tag
[root@centos7-docker ~]# docker tag d52 centos7_nginx:v8
[root@centos7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_nginx v8 d52a7cd5a1ed 2 hours ago 976MB
centos7_nginx v7 003b917060be 2 hours ago 673MB
centos7_nginx v6 68954acd27d5 22 hours ago 673MB
centos7_nginx v5 00e0e71aa40f 22 hours ago 673MB
centos7_nginx v4 586517a9d3a0 22 hours ago 673MB
centos7_nginx v3 034fca0d39d2 22 hours ago 673MB
centos7_nginx v2 fad261761053 23 hours ago 673MB
centos7_nginx v1 1ffc4a8e3106 23 hours ago 673MB
格式:docker export [options] CONTAINER
[root@centos7-docker ~]# docker export --help
Usage: docker export [OPTIONS] CONTAINER
Export a container's filesystem as a tar archive
Options:
-o, --output string Write to a file, instead of STDOUT
docker export -o ubuntu-18.04.tar b75
其中-o表示输出到文件,ubuntu-18.04.tar为目标文件,b75是容器ID(写容器名也可以)
#查看运行的容器
[root@centos7-docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b756c37a6552 ubuntu:18.04 "/bin/bash" About an hour ago Up 2 seconds nostalgic_mestorf
[root@centos7-docker ~]# docker export -o ubuntu-18.04.tar b75
[root@centos7-docker ~]# ls
backup centos7_nginx-v10.tar centos7_nginx-v11.tar centos7_nginx-v9.tar docker_demo rpmbuild ubuntu-18.04.tar
格式:docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
[root@centos7-docker ~]# docker import --help
Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Import the contents from a tarball to create a filesystem image
Options:
-c, --change list Apply Dockerfile instruction to the created image
-m, --message string Set commit message for imported image
--platform string Set platform if server is multi-platform capable
下图是save导出load导入的
下图是export导出import导入的
9.6 建议