-
Dockerfile :
* dockerfile 是一个包含创建所有命令的文本文件,使用docker build 根据dockerfile命令创建新的镜像 * FROM tomcat # 参考的基础镜像 * MAINTAINER #标识镜像创建者 * 执行命令 * RUN rm -f /usr/local/tomcat/webapps/ROOT/index.jsp * RUN echo "welcome to tomcat!" >/usr/local/tomcat/webapps/ROOT/index.html
-
构建镜像:跟进dockerfile 文件自动构建镜像
* docker build -f Dockerfile当前路径 -t xianwei/tomcat:v2 . *exp: $ docker build -f dockerfile -t xianwei/tomcat:v2 . * [python@localhost ~]$ sudo docker build -f /dockerfile -t xianwei/tomcat:v2 . Sending build context to Docker daemon 196.6MB Step 1/4 : FROM tomcat ---> ef802ca71927 Step 2/4 : MAINTAINER Eric ---> Running in 328055e1575c Removing intermediate container 328055e1575c ---> 35ebde183840 Step 3/4 : RUN rm -f /usr/local/tomcat/webapps/ROOT/index.jsp ---> Running in 29be0a87fdbc Removing intermediate container 29be0a87fdbc ---> 567478df2a70 Step 4/4 : RUN echo "welcome to tomcat!" >/usr/local/tomcat/webapps/ROOT/index.html ---> Running in c55851466c73 Removing intermediate container c55851466c73 ---> 04819a1dbce5 Successfully built 04819a1dbce5 Successfully tagged xianwei/tomcat:v2
3.使用新镜像运行容器
$ sudo docker run --name v2 -p 9999:8080 -d 04819a1dbce5
4.查看容器元信息 # $ sudo docker inspect tomcat:v3