经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Docker » 查看文章
Docke--Dockerfile实践别来无恙-
来源:cnblogs  作者:别来无恙-  时间:2019/1/11 9:41:51  对本文有异议

Dockerfile 实践 nginx镜像构建

先查看下本地的镜像,选取官网的centos作为base image:

  1. [root@server ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. centos latest 1e1148e4cc2c 5 weeks ago 202MB

创建一个目录用于专门存放此demo的目录,也就是Dockerfile所在的目录

  1. [root@server ~]# mkdir myNginx
  2. [root@server ~]# cd myNginx/
  3. [root@server myNginx]# touch Dockerfile
  4. [root@server myNginx]# ll
  5. 总用量 0
  6. -rw-r--r-- 1 root root 0 1 10 17:34 Dockerfile

下面开始编写Dockerfile 文件,(注意Dockerfile的D需要大写)

v1版:

  1. [root@server myNginx]# cat Dockerfile
  2. # 指定基础镜像
  3. FROM centos
  4. # MAINTAINER
  5. MAINTAINER 381347268@qq.com
  6. # 安装基础工具包
  7. RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
  8. # 下载nginx
  9. ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
  10. # 解压nginx 并创建用户
  11. RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ && useradd -M -s /sbin/nologin nginx
  12. # 更改工作目录
  13. WORKDIR /usr/local/src/nginx-1.12.2
  14. # 编译安装nginx
  15. 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
  16. # 删除多余安装包
  17. RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
  18. # 设置环境变量
  19. ENV PATH=/usr/local/nginx/sbin:$PATH
  20. # 设置端口
  21. EXPOSE 80

执行docker build 进行构建:

  1. [root@server myNginx]# ll
  2. 总用量 4
  3. -rw-r--r-- 1 root root 1268 1 10 17:40 Dockerfile
  4. [root@server myNginx]# docker build -t centos_nginx:v1 .

此处构建有点慢,因为需要安装编译nginx需要用到的软件,及下载nginx;后面的.代表的是相对路径的当前目录,如果需要全路径则为/root/myNginx(就是找到Dockerfile文件)

构建成功后,查看新构建的镜像:

  1. [root@server myNginx]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. centos_nginx v1 13d959cbec2b About a minute ago 504MB
  4. centos latest 1e1148e4cc2c 5 weeks ago 202MB

使用v1版本的镜像启动一个容器:

  1. [root@server myNginx]# docker run -d -p 80:80 centos_nginx:v1 nginx -g "daemon off;"
  2. 961ef4274078b61a56667293ef69ee881fbf4171156c7990c94225eb508a172c

查看容器运行状态:

  1. [root@server myNginx]# docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 961ef4274078 centos_nginx:v1 "nginx -g 'daemon of…" 39 seconds ago Up 38 seconds 0.0.0.0:80->80/tcp mystifying_goldberg

进行访问:

这样基于Dockerfile的一个简单的实例构建完成,现在基于这个Dockerfile文件依次添加其它指令进行构建

 

添加CMD 指令:

  1. [root@server myNginx]# cat Dockerfile
  2. # 指定基础镜像
  3. FROM centos
  4. # MAINTAINER
  5. MAINTAINER 381347268@qq.com
  6. # 安装基础工具包
  7. RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
  8. # 下载nginx
  9. ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
  10. # 解压nginx 并创建用户
  11. RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ && useradd -M -s /sbin/nologin nginx
  12. # 更改工作目录
  13. WORKDIR /usr/local/src/nginx-1.12.2
  14. # 编译安装nginx
  15. 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
  16. # 删除多余安装包
  17. RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
  18. # 设置环境变量
  19. ENV PATH=/usr/local/nginx/sbin:$PATH
  20. # 设置端口
  21. EXPOSE 80
  22. CMD /bin/sh -c 'nginx -g "daemon off;"'

然后进行构建v2版本:

  1. [root@server myNginx]# docker build -t centos_nginx:v2 .
  2. Sending build context to Docker daemon 3.072kB
  3. Step 1/11 : FROM centos
  4. ---> 1e1148e4cc2c
  5. Step 2/11 : MAINTAINER 381347268@qq.com
  6. ---> Using cache
  7. ---> d41475691003
  8. Step 3/11 : RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
  9. ---> Using cache
  10. ---> 7739a6cdd37c
  11. Step 4/11 : ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
  12. Downloading [==================================================>] 981.7kB/981.7kB
  13. ---> Using cache
  14. ---> a58676d797ad
  15. Step 5/11 : RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ && useradd -M -s /sbin/nologin nginx
  16. ---> Using cache
  17. ---> 7f671453fc20
  18. Step 6/11 : WORKDIR /usr/local/src/nginx-1.12.2
  19. ---> Using cache
  20. ---> be296a9725ea
  21. Step 7/11 : 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
  22. ---> Using cache
  23. ---> fcbc1da221cc
  24. Step 8/11 : RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
  25. ---> Using cache
  26. ---> 2189ac28a36f
  27. Step 9/11 : ENV PATH=/usr/local/nginx/sbin:$PATH
  28. ---> Using cache
  29. ---> 70faf0a90e9f
  30. Step 10/11 : EXPOSE 80
  31. ---> Using cache
  32. ---> 13d959cbec2b
  33. Step 11/11 : CMD /bin/sh -c 'nginx -g "daemon off;"'
  34. ---> Running in d07896b5ba56
  35. Removing intermediate container d07896b5ba56
  36. ---> 3b71646263d3
  37. Successfully built 3b71646263d3
  38. Successfully tagged centos_nginx:v2

由于在构建的过程中docker 会采用缓存机制,上面构建过程中包含很多using cache,所以这次构件非常快,如果需要重新构建,不想使用cache 需要添加 --no-cache

查看v2版本的镜像:

  1. [root@server myNginx]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. centos_nginx v2 3b71646263d3 6 minutes ago 504MB

使用v2版本的镜像启动一个容器:

  1. [root@server myNginx]# docker run -d -p 81:80 centos_nginx:v2
  2. 934ddc6f56a48f59b405c75c19b40ce5156388e34de37c078a56abc7c08a0602

然后查看容器状态:

  1. [root@server myNginx]# docker ps -l
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 934ddc6f56a4 centos_nginx:v2 "/bin/sh -c '/bin/sh…" 43 seconds ago Up 42 seconds 0.0.0.0:81->80/tcp pedantic_cocks

进行访问:

新增加的CMD /bin/sh -c 'nginx -g "daemon off;"' 表示

当启动一个容器时候默认运行的命令,如果在启动容器时赋予了command的话,那么定义的CMD中的命令将不会被执行,而会去执行command的命令

 

添加ENTRYPOINT 指令:

  1. [root@server myNginx]# cat Dockerfile
  2. # 指定基础镜像
  3. FROM centos
  4. # MAINTAINER
  5. MAINTAINER 381347268@qq.com
  6. # 安装基础工具包
  7. RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
  8. # 下载nginx
  9. ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
  10. # 解压nginx 并创建用户
  11. RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ && useradd -M -s /sbin/nologin nginx
  12. # 更改工作目录
  13. WORKDIR /usr/local/src/nginx-1.12.2
  14. # 编译安装nginx
  15. 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
  16. # 删除多余安装包
  17. RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
  18. # 设置环境变量
  19. ENV PATH=/usr/local/nginx/sbin:$PATH
  20. # 设置端口
  21. EXPOSE 80
  22. ENTRYPOINT ["nginx"]
  23. CMD ["-g", "daemon off;"]

当ENTRYPOINT和CMD连用时,CMD的命令是ENTRYPOINT命令的参数,两者连用相当于nginx -g "daemon off;" ;而当一起连用的命令格式最好一致(此处选择的都是json格式)

然后进行构建v3版本:

  1. [root@server myNginx]# docker build -t centos_nginx:v3 .

查看v3版本的镜像:

  1. [root@server myNginx]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. centos_nginx v3 1aeba273c0af 21 seconds ago 504MB

使用v3版本的镜像启动一个容器:

  1. [root@server myNginx]# docker run -d -p 82:80 centos_nginx:v3
  2. 2932d58ee8969587b04fa0155aadeb4b63a1934962d384624a8d7359725dfad3

然后查看容器状态:

  1. [root@server myNginx]# docker ps -l
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 2932d58ee896 centos_nginx:v3 "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:82->80/tcp boring_gauss

进行访问:

 

这里示例一个默认将nginx关闭的示例v3.1版:

  1. [root@server myNginx]# cat Dockerfile
  2. # 指定基础镜像
  3. FROM centos
  4. # MAINTAINER
  5. MAINTAINER 381347268@qq.com
  6. # 安装基础工具包
  7. RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
  8. # 下载nginx
  9. ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
  10. # 解压nginx 并创建用户
  11. RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ && useradd -M -s /sbin/nologin nginx
  12. # 更改工作目录
  13. WORKDIR /usr/local/src/nginx-1.12.2
  14. # 编译安装nginx
  15. 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
  16. # 删除多余安装包
  17. RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
  18. # 设置环境变量
  19. ENV PATH=/usr/local/nginx/sbin:$PATH
  20. # 设置端口
  21. EXPOSE 80
  22. ENTRYPOINT ["nginx"]
  23. CMD ["-g", "daemon on;"]

CMD 的命令修改为了后台,我们知道如果容器内的进程在后台运行那么容器将不会运行,构建v3.1版本:

  1. [root@server myNginx]# docker build -t centos_nginx:v3.1 .

查看v3.1版本的镜像:

  1. [root@server myNginx]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. centos_nginx v3.1 ec17ab98a424 12 seconds ago 504MB

使用v3.1版本的镜像启动一个容器,但是在启动的时候添加后面的command:

  1. [root@server myNginx]# docker run -d -p 83:80 centos_nginx:v3.1 -g "daemon off;"
  2. 0143d4b91ca1f97be31f0427140dfb17bb4ad9530d4a4a19b70c93044f6332c5

可以看见在后面新增了 -g "daemon off;",前面提过如果在启动容器时增加了命令,那么Dockerfile中的CMD中的命令将不会生效

查看容器运行状态:

  1. [root@server myNginx]# docker ps -l
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 0143d4b91ca1 centos_nginx:v3.1 "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:83->80/tcp loving_burnell

可以看见容器的运行丝毫没有问题,于是nginx 的服务依然还是在前台运行,没有被影响,而新增的command (-g "daemon off;")将作为ENTRYPOINT的新的参数以此为准,于是进行访问:

 

添加VOLUME指令:

  1. [root@server myNginx]# cat Dockerfile
  2. # 指定基础镜像
  3. FROM centos
  4. # MAINTAINER
  5. MAINTAINER 381347268@qq.com
  6. # 安装基础工具包
  7. RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
  8. # 下载nginx
  9. ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
  10. # 解压nginx 并创建用户
  11. RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ && useradd -M -s /sbin/nologin nginx
  12. # 挂载数据目录
  13. VOLUME ["/usr/local/nginx/html"]
  14. # 更改工作目录
  15. WORKDIR /usr/local/src/nginx-1.12.2
  16. # 编译安装nginx
  17. 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
  18. # 删除多余安装包
  19. RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
  20. # 设置环境变量
  21. ENV PATH=/usr/local/nginx/sbin:$PATH
  22. # 设置端口
  23. EXPOSE 80
  24. ENTRYPOINT ["nginx"]
  25. CMD ["-g"]

然后进行构建v4版本:

  1. [root@server myNginx]# docker build -t centos_nginx:v4 .

查看v4版本的镜像:

  1. [root@server myNginx]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. centos_nginx v4 b142047c1a6e 19 seconds ago 504MB

使用v4版本的镜像启动一个容器:

  1. [root@server myNginx]# docker run -d -p 84:80 --name nginx4 centos_nginx:v4 -g "daemon off;"
  2. 1d191f9bc49dc01ee2657508eba94ff1d02e5b4304eaf6ed5161e4b9000577ea

然后查看容器状态:

  1. [root@server myNginx]# docker ps -l
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 1d191f9bc49d centos_nginx:v4 "nginx -g 'daemon of…" 36 seconds ago Up 34 seconds 0.0.0.0:84->80/tcp nginx4

通过docker inspect 可以看到宿主机上面的挂载目录路径:

  1. [root@server ~]# docker inspect nginx4
  2. "Mounts": [
  3. {
  4. "Type": "volume",
  5. "Name": "5c4b8ec0bf7e4f243ea643af4af559617c89c43933768a1b4b45caef237251bf",
  6. "Source": "/var/lib/docker/volumes/5c4b8ec0bf7e4f243ea643af4af559617c89c43933768a1b4b45caef237251bf/_data",
  7. "Destination": "/usr/local/nginx/html",
  8. "Driver": "local",
  9. "Mode": "",
  10. "RW": true,
  11. "Propagation": ""
  12. }
  13. ],

进入到宿主机的挂载目录并且查看目录内的文件:

  1. [root@server ~]# cd /var/lib/docker/volumes/5c4b8ec0bf7e4f243ea643af4af559617c89c43933768a1b4b45caef237251bf/_data
  2. [root@server _data]# pwd
  3. /var/lib/docker/volumes/5c4b8ec0bf7e4f243ea643af4af559617c89c43933768a1b4b45caef237251bf/_data
  4. [root@server _data]# ll
  5. 总用量 8
  6. -rw-r--r-- 1 1001 1001 537 10 17 2017 50x.html
  7. -rw-r--r-- 1 1001 1001 612 10 17 2017 index.html

利用docker exec 进入到容器中,查看卷:

  1. [root@server myNginx]# docker exec -it nginx4 /bin/bash
  2. [root@d2d2a2f287c6 nginx-1.12.2]# cd /usr/local/nginx/html/
  3. [root@d2d2a2f287c6 html]# pwd
  4. /usr/local/nginx/html
  5. [root@d2d2a2f287c6 html]# ll
  6. total 8
  7. -rw-r--r-- 1 1001 1001 537 Oct 17 2017 50x.html
  8. -rw-r--r-- 1 1001 1001 612 Oct 17 2017 index.html

现在在本地宿主机上的这个目录修改index.html文件内容:

  1. [root@server _data]# echo "<h1>Hello Docker.</h1>" > index.html
  2. [root@server _data]# cat index.html
  3. <h1>Hello Docker.</h1>

然后切换到容器中查看这个文件是否发生改变:

[root@d2d2a2f287c6 html]# cat index.html
<h1>Hello Docker.</h1>

进行访问:

通过访问发现,在宿主机上面进行了更改,容器内部也发生了变化,这样就动态的实现网站数据动态更改。

 

添加ONBUILD 指令:

  Dockerfile1中base image 为A镜像,并在Dockefile1中定义ONBUILD指令,构建成新的镜像B镜像

  Dockerfile2中base image 为B镜像,构建成新镜像C

  当使用镜像B启动容器1不会执行OBNUILD中定义的内容,而使用C镜像启动的容器2则会执行ONBUILD定义的内容

  1. [root@server myNginx]# cat Dockerfile
  2. # 指定基础镜像
  3. FROM centos
  4. # MAINTAINER
  5. MAINTAINER 381347268@qq.com
  6. # 安装基础工具包
  7. RUN yum -y install wget gcc gcc-c++ glibc make autoconf openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
  8. # 下载nginx
  9. ADD http://nginx.org/download/nginx-1.12.2.tar.gz /opt/nginx/
  10. # 解压nginx 并创建用户
  11. RUN tar -xvzf /opt/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/ && useradd -M -s /sbin/nologin nginx
  12. # 挂载数据目录
  13. ONBUILD VOLUME ["/data"]
  14. # 更改工作目录
  15. WORKDIR /usr/local/src/nginx-1.12.2
  16. # 编译安装nginx
  17. 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
  18. # 删除多余安装包
  19. RUN rm -rf /opt/nginx/nginx-1.12.2.tar.gz
  20. # 设置环境变量
  21. ENV PATH=/usr/local/nginx/sbin:$PATH
  22. # 设置端口
  23. EXPOSE 80
  24. ENTRYPOINT ["nginx"]
  25. CMD ["-g"]

然后进行构建v5版本:

  1. [root@server myNginx]# docker build -t centos_nginx:v5 .

使用v5版本的镜像启动一个容器:

  1. [root@server myNginx]# docker run -d -p 85:80 --name nginx5 centos_nginx:v5 -g "daemon off;"
  2. 1f3c1672cce45e6f0f4e8d927de017fbe0a16f30858427d5cb3c2ec7f7b55d98

现在进入到nginx5容器内查看是否存在/data:

  1. [root@server myNginx]# docker exec -it nginx5 /bin/bash
  2. [root@1f3c1672cce4 nginx-1.12.2]# ll /data
  3. ls: cannot access /data: No such file or directory

现在修改上面的Dockerfile的FROM基于的base image:

  1. [root@server myNginx]# cat Dockerfile
  2. # 指定基础镜像
  3. FROM centos_nginx:v5
  4. # MAINTAINER
  5. MAINTAINER 381347268@qq.com

然后进行构建v6版本:

  1. [root@server myNginx]# docker build -t centos_nginx:v6 .
  2. Sending build context to Docker daemon 4.096kB
  3. Step 1/2 : FROM centos_nginx:v5
  4. # Executing 1 build trigger
  5. ---> Running in a34359a1107d
  6. Removing intermediate container a34359a1107d
  7. ---> b1e2a7e80907
  8. Step 2/2 : MAINTAINER 381347268@qq.com
  9. ---> Running in 901fa3500f51
  10. Removing intermediate container 901fa3500f51
  11. ---> a32bd0c300e2
  12. Successfully built a32bd0c300e2
  13. Successfully tagged centos_nginx:v6

使用v6版本的镜像启动一个容器:

  1. [root@server myNginx]# docker run -d -p 86:80 --name nginx6 centos_nginx:v6 -g "daemon off;"
  2. f8ccf7ff63f875742ac93b54cc25a629e7df14c8e676e202def1191baf0b3c1f

查看容器状态,并进入容器验证/data/目录:

  1. [root@server myNginx]# docker ps -l
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. f8ccf7ff63f8 centos_nginx:v6 "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:86->80/tcp nginx6
  4. [root@server myNginx]# docker exec -it nginx6 /bin/bash
  5. [root@f8ccf7ff63f8 nginx-1.12.2]# ll /data
  6. total 0

由此可见镜像v6包含了v5所有的内容,并且增加了ONBUILD的内容

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号