[[email protected] createImages]# ls apache-tomcat-8.5.14.tar.gz server-jre-8u121-linux-x64.tar.gz [[email protected] createImages]# vim Dockerfile FROM centos:latest MAINTAINER [email protected] ADD ./apache-tomcat-8.5.14.tar.gz /root ADD ./server-jre-8u121-linux-x64.tar.gz /root ENV JAVA_HOME /root/jdk1.8.0_121 ENV PATH $JAVA_HOME/bin:$PATH ENTRYPOINT /root/apache-tomcat-8.5.14/bin/startup.sh && tail -F /root/apache-tomcat-8.5.14/logs/catalina.out # --rm=true指定在生成镜像过程中删除中间产生的临时容器。 [[email protected] createImages]# docker build -t kevin/centos:tomcat-centos --rm=true . Sending build context to Docker daemon 64.05MB Step 1/7 : FROM centos:latest ---> a8493f5f50ff Step 2/7 : MAINTAINER [email protected] ---> Running in 712cff3cdde6 ---> 0df02775da50 Removing intermediate container 712cff3cdde6 Step 3/7 : ADD ./apache-tomcat-8.5.14.tar.gz /root ---> ff83c6dc3551 Removing intermediate container 188b5248d4c6 Step 4/7 : ADD ./server-jre-8u121-linux-x64.tar.gz /root ---> 3435ea7545d0 Removing intermediate container 7756f66ee1d2 Step 5/7 : ENV JAVA_HOME /root/jdk1.8.0_121 ---> Running in e8c244aa9aa6 ---> 985fbbd99d3e Removing intermediate container e8c244aa9aa6 Step 6/7 : ENV PATH $JAVA_HOME/bin:$PATH ---> Running in 21bae273d39c ---> 0a8817a95f51 Removing intermediate container 21bae273d39c Step 7/7 : ENTRYPOINT /root/apache-tomcat-8.5.14/bin/startup.sh && tail -F /root/apache-tomcat-8.5.14/logs/catalina.out ---> Running in b24be846b038 ---> dbc07307031d Removing intermediate container b24be846b038 Successfully built dbc07307031d [[email protected] createImages]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE kevin/centos tomcat-centos dbc07307031d 25 seconds ago 357MB # docker run <相关参数> <镜像 ID> <初始命令> # -p 指定主机80端口与容器8080端口进行绑定 # -d 指定容器运行后与当前tty分离,后台运行 # -i:表示以“交互模式”运行容器 # -t:表示容器启动后会进入其命令行 # -v:表示需要将本地哪个目录挂载到容器中, # 格式:-v <宿主机目录>:<容器目录> # dbc0是镜像的ID前4位。 [[email protected] web]$ docker run -d -p 8090:8080 dbc0 aec717552fa6620f73a74ee5df177501a3af25a6c5cea76b27f55dd204122f0b # 联网访问宿主机 http://192.168.0.164:8090/ OK # 保存镜像 [[email protected] createImages]# docker save -o docker-image-centos_jre_tomcat.tar.gz kevin/centos:tomcat-centos # 修改权限 [[email protected] createImages]# chmod 777 docker-image-centos_jre_tomcat.tar.gz # 查看运行的容器和镜像 [[email protected] createImages]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES aec717552fa6 dbc0 "/bin/sh -c ‘/root..." 12 minutes ago Up 12 minutes 0.0.0.0:8090->8080/tcp focused_roentgen # 停止容器 [[email protected] createImages]# docker stop aec717552fa6 aec717552fa6 # 删除容器 [[email protected] createImages]# docker rm aec717552fa6 aec717552fa6 # 删除镜像 [[email protected] createImages]# docker rmi dbc0 Untagged: kevin/centos:tomcat-centos Deleted: sha256:dbc07307031d81c18395c044e7bfca81cb31667fb07690d88c57ef6c27ad9a78 Deleted: sha256:0a8817a95f511f0a68f8ebb3952678349e46e9bd6f06064f0d043a03c827f372 Deleted: sha256:985fbbd99d3ef96219f21709fd65751e90a0bd05810df2e97b19d13ac5dad1ab Deleted: sha256:3435ea7545d0b4b8b1d1b76e6ee2fd1501473f0bf8a6b01d08600c446de6e4aa Deleted: sha256:6eb6f275663c773463eb5d521bd51636f7cbd4af0f3872a464dffb9104230984 Deleted: sha256:ff83c6dc35514bfeafbe9ba45b1e7dd94fcd3873e6c2e54bfe38679910d792c6 Deleted: sha256:b5dcd31d7b8e5c2038afc7c1e6cb65d3988ef1b990f46a0ef2f8cab34a78bec3 Deleted: sha256:0df02775da507966f191a546a1890ba59d89082e7679d47ead88c787e64361aa # 迁移加载镜像 [[email protected] createImages]# docker load < docker-image-centos_jre_tomcat.tar.gz 788680cd384f: Loading layer [==================================================>] 13.78MB/13.78MB 8cbad8252262: Loading layer [==================================================>] 151.7MB/151.7MB Loaded image: kevin/centos:tomcat-centos
时间: 2024-10-12 11:13:24