免费资源网 – https://freexyz.cn/
docker commit 命令 : 用于将一个镜像进行提交成一个新的副本
命令格式:
docker commit -m=”描述信息” -a=”作者” 容器id 目标镜像名: [TAG]做个实例:
查看本地镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 605c77e624dd 2 months ago 141MB tomcat 9.0 b8e65a4d736d 2 months ago 680MB tomcat latest fb5657adc892 2 months ago 680MB mysql latest 3218b38490ce 2 months ago 516MB hello-world latest feb5d9fea6a5 5 months ago 13.3kB centos latest 5d0da3dc9764 5 months ago 231MB我们之前的Tomcat服务器的部署是使用的最新的latest
我们就使用Tomcat 9.0 来做这个
这是它的前台运行结果
做一个端口映射:
[root@localhost ~]# docker run -it -p 8080:8080 tomcat Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/openjdk-11 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Using CATALINA_OPTS: NOTE: Picked up JDK_JAVA_OPTIONS: –add-opens=java.base/java.lang=ALL-UNNAMED –add-opens=java.base/java.io=ALL-UNNAMED –add-opens=java.base/java.util=ALL-UNNAMED –add-opens=java.base/java.util.concurrent=ALL-UNNAMED –add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED 07-Mar-2022 10:59:56.387 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/10.0.14 07-Mar-2022 10:59:56.390 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 2 2021 22:01:36 UTC 07-Mar-2022 10:59:56.390 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.0.14.0 07-Mar-2022 10:59:56.391 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux 07-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 3.10.0-862.el7.x86_64 07-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 07-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/openjdk-11 07-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 11.0.13+8在前台运行的同时,我们来查看一下正在运行的容器
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e73948b0078 tomcat “catalina.sh run” 5 minutes ago Up 5 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp happy_feistel 155ead9f80cc tomcat “catalina.sh run” 5 hours ago Up 5 hours 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat01 2257878e8b61 nginx “/docker-entrypoint.…” 6 hours ago Up 5 hours 0.0.0.0:443->80/tcp, :::443->80/tcp nginx01 6d6fa6a4c6d7 5d0da3dc9764 “/bin/bash” 6 hours ago Up 6 hours nice_panini [root@localhost ~]#这个时候,使用浏览器来访问一下Tomcat
这结果是正常的,这是因为镜像原本就不完整
在这样的情况下,如果终止掉前台的进程
这个时候,浏览器的访问就会报错:
如果想要在终止前台进程的同时,想让浏览器的访问不报错
就要这样做:
[root@localhost ~]# docker run -d -p 8080:8080 –name tomcat04 tomcat:9.0 c9a2f98234c79d94e0ccc67b5a529eace1ec1d2211b1b7088a16a45c62134ae8 [root@localhost ~]#浏览器再次访问
恢复正常
我们接下来解决一下镜像不完整而导致的问题
进容器
[root@localhost ~]# docker exec -it b7d37ccaadf0 /bin/bash root@b7d37ccaadf0:/usr/local/tomcat# b7d37ccaadf0这样复制一下文件到指定文件中
root@c9a2f98234c7:/usr/local/tomcat# cp -r webapps.dist/* webapps root@c9a2f98234c7:/usr/local/tomcat# cd webapps root@c9a2f98234c7:/usr/local/tomcat/webapps# ls ROOT docs examples host-manager manager root@c9a2f98234c7:/usr/local/tomcat/webapps#浏览器上测试:
这就好了
接下来,我们要进行一些操作
使得我们修改后的镜像提交成一个新的副本
下次我们直接使用它
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c9a2f98234c7 tomcat:9.0 “catalina.sh run” 17 minutes ago Up 17 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp tomcat04 155ead9f80cc tomcat “catalina.sh run” 6 hours ago Up 6 hours 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat01 2257878e8b61 nginx “/docker-entrypoint.…” 6 hours ago Up 6 hours 0.0.0.0:443->80/tcp, :::443->80/tcp nginx01 6d6fa6a4c6d7 5d0da3dc9764 “/bin/bash” 7 hours ago Up 7 hours nice_panini将我们原先经过处理的镜像打成一个新的包,变成一个新的整体
[root@localhost ~]# docker commit -a=”shuaige” -m “add a web app” c9a2f98234c7 tomcat04:1.0 sha256:12b32b1a124d5c1a3572fd0d02542c254192e415aa49045390f15a9a811f0153 [root@localhost ~]#查看镜像:(看Tomcat04 的那个镜像,比原先的9.0 Tomcat 镜像要大)
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat04 1.0 12b32b1a124d 2 minutes ago 685MB nginx latest 605c77e624dd 2 months ago 141MB tomcat 9.0 b8e65a4d736d 2 months ago 680MB tomcat latest fb5657adc892 2 months ago 680MB mysql latest 3218b38490ce 2 months ago 516MB hello-world latest feb5d9fea6a5 5 months ago 13.3kB centos latest 5d0da3dc9764 5 months ago 231MB现在他就是一个新的镜像了,下次可以直接使用
免费资源网 – https://freexyz.cn/
© 版权声明
THE END
暂无评论内容