docker commit 命令 : 用于将一个镜像进行提交成一个新的副本 命令格式: docker commit -m="描述信息" -a="作者" 容器id 目标镜像名: [TAG] 做个实例: 查看本地镜像 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 605c77e624dd 2 months ago 141MBtomcat 9.0 b8e65a4d736d 2 months ago 680MBtomcat latest fb5657adc892 2 months ago 680MBmysql latest 3218b38490ce 2 months ago 516MBhello-world latest feb5d9fea6a5 5 months ago 13.3kBcentos latest 5d0da3dc9764 5 months ago 231MB 我们之前的Tomcat服务器的部署是使用的最新的latest 我们就使用Tomcat 9.0 来做这个 这是它的前台运行结果 做一个端口映射: [root@localhost ~]# docker run -it -p 8080:8080 tomcatUsing CATALINA_BASE: /usr/local/tomcatUsing CATALINA_HOME: /usr/local/tomcatUsing CATALINA_TMPDIR: /usr/local/tomcat/tempUsing JRE_HOME: /usr/local/openjdk-11Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarUsing 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-UNNAMED07-Mar-2022 10:59:56.387 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/10.0.1407-Mar-2022 10:59:56.390 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 2 2021 22:01:36 UTC07-Mar-2022 10:59:56.390 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.0.14.007-Mar-2022 10:59:56.391 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux07-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 3.10.0-862.el7.x86_6407-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd6407-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/openjdk-1107-Mar-2022 10:59:56.392 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 11.0.13+8 在前台运行的同时,我们来查看一下正在运行的容器 [root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES5e73948b0078 tomcat "catalina.sh run" 5 minutes ago Up 5 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp happy_feistel155ead9f80cc tomcat "catalina.sh run" 5 hours ago Up 5 hours 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat012257878e8b61 nginx "/docker-entrypoint.…" 6 hours ago Up 5 hours 0.0.0.0:443->80/tcp, :::443->80/tcp nginx016d6fa6a4c6d7 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/* webappsroot@c9a2f98234c7:/usr/local/tomcat# cd webappsroot@c9a2f98234c7:/usr/local/tomcat/webapps# lsROOT docs examples host-manager managerroot@c9a2f98234c7:/usr/local/tomcat/webapps# 浏览器上测试: 这就好了 接下来,我们要进行一些操作 使得我们修改后的镜像提交成一个新的副本 下次我们直接使用它 [root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc9a2f98234c7 tomcat:9.0 "catalina.sh run" 17 minutes ago Up 17 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp tomcat04155ead9f80cc tomcat "catalina.sh run" 6 hours ago Up 6 hours 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat012257878e8b61 nginx "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:443->80/tcp, :::443->80/tcp nginx016d6fa6a4c6d7 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 imagesREPOSITORY TAG IMAGE ID CREATED SIZEtomcat04 1.0 12b32b1a124d 2 minutes ago 685MBnginx latest 605c77e624dd 2 months ago 141MBtomcat 9.0 b8e65a4d736d 2 months ago 680MBtomcat latest fb5657adc892 2 months ago 680MBmysql latest 3218b38490ce 2 months ago 516MBhello-world latest feb5d9fea6a5 5 months ago 13.3kBcentos latest 5d0da3dc9764 5 months ago 231MB 现在他就是一个新的镜像了,下次可以直接使用 下载地址: virtualBox虚拟机安装增强功能后开机超慢问题解决方案 Nginx配置origin限制跨域请求的详细过程 |