Dockerfile构建Tomcat镜像
步骤:
(1)创建一个目录,把构建Tomcat的Dockerfile文件保存到此目录。
mkdir tomcat8 cd tomcat6
文件内容
FROM centos:7 MAINTAINER xpx RUN sed -i 's|mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-*.repo \ && sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://mirrors.aliyun.com|g' /etc/yum.repos.d/CentOS-*.repo \ && yum clean all \ && yum makecache RUN yum install wget -y ADD jdk-8u92-linux-x64.rpm /usr/local/ ADD apache-tomcat-8.0.26.tar.gz /usr/local/ RUN cd /usr/local && rpm -ivh jdk-8u92-linux-x64.rpm RUN mv /usr/local/apache-tomcat-8.0.26 /usr/local/tomcat8 EXPOSE 8080
构建过程
[root@localhost tomcat8]# docker build -t="tomcat8:v1" . [+] Building 39.7s (12/12) FINISHED docker:default => [internal] load build definition from dockerfile 0.0s => => transferring dockerfile: 591B 0.0s => [internal] load metadata for docker.io/library/centos:7 15.2s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/7] FROM docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 0.0s => [internal] load build context 0.0s => => transferring context: 201B 0.0s => CACHED [2/7] RUN sed -i 's|mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-*.repo && sed -i 's|#baseurl=http://mir 0.0s => CACHED [3/7] RUN yum install wget -y 0.0s => CACHED [4/7] ADD jdk-8u92-linux-x64.rpm /usr/local/ 0.0s => CACHED [5/7] ADD apache-tomcat-8.0.26.tar.gz /usr/local/ 0.0s => [6/7] RUN cd /usr/local && rpm -ivh jdk-8u92-linux-x64.rpm 13.0s => [7/7] RUN mv /usr/local/apache-tomcat-8.0.26 /usr/local/tomcat8 2.0s => exporting to image 9.3s => => exporting layers 9.3s => => writing image sha256:e86437e541f3f067123ca6a684e827551f42cca6ce4ae8cf206a49ebf3967fd1 0.0s => => naming to docker.io/library/tomcat8:v1
查看镜像
[root@localhost tomcat8]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat8 v1 e86437e541f3 About a minute ago 1.51GB xpx/nginx v1 6a153d823f9b 20 hours ago 1.51GB