本文主要是介绍docker使用dockfile 写错了 Dockerfile中ENTRYPOINT设置的命令 可以动态覆盖,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
docker run的--entrypoint可以覆盖Dockerfile中ENTRYPOINT设置的命令
docker run -it -p20180:80 -p20181:8080 -p20182:8976 --entrypoint="/bin/bash" --name containerName image:tag
docker commit -a ‘songlk’ -m ‘commitdesc’ container_nginx centos:7.2.1511
https://blog.csdn.net/yori_chen/article/details/80930075
环境为CentOS,在制作镜像之前,请先下载好Linux版的JDK和Tomcat,我所演示的版本为:jdk-8u162-linux-x64.tar.gz
、apache-tomcat-8.0.47.tar.gz
- 保证JDK、Tomcat、Dockerfile 处于同一目录下(本次演示目录为:/home)
[root@iZbp1b5k5bjps0dw8owk7tZ home]# ls
apache-tomcat-8.0.47.tar.gz Dockerfile jdk-8u162-linux-x64.tar.gz
[root@iZbp1b5k5bjps0dw8owk7tZ home]#
- 1
- 2
- 3
- 4
编写docker构建文件(Dockerfile)
# 编辑Dockerfile
vi Dockerfile
- 1
- 2
不知道什么是Dockerfile? 也不会写?,OK,Ctrl+C 就好了,不过请将jdk和tomcat的版本和版本后面对应的路径改为自己指定的版本和路径
# 基础镜像
FROM centos
# 作者
MAINTAINER yezi
# 把jdk与tomcat添加到容器中
ADD jdk-8u162-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.0.47.tar.gz /usr/local/
# 配置环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_162
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.0.47
ENV CATALINA_BASE /usr/local/apache-tomcat-8.0.47
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
# 容器运行时监听的端口
EXPOSE 8080
#配置容器启动后执行的命令
ENTRYPOINT /usr/local/apache-tomcat-8.0.47/bin/startup.sh && tail -f /usr/local/apache-tomcat-8.0.47/logs/catalina.out
#启动时运行tomcat
CMD ["/usr/local/apache-tomcat-8.0.47/bin/catalina.sh","run"]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
ENTRYPOINT
这个命令主要是为了解决tomcat容器不打印catalina.out日志,可以省去
构建镜像
# 以当前目录下(.)的 Dockerfile 文件 构建镜像名为 yezi/tomcat 的镜像
docker build -t yezi/tomcat .
- 1
- 2
[root@iZbp1b5k5bjps0dw8owk7tZ test]# docker build -t yezi/tomcat .
Sending build context to Docker daemon 199.2MB
Step 1/11 : FROM centos---> 49f7960eb7e4
Step 2/11 : MAINTAINER yezi---> Running in 23ab370a223c
Removing intermediate container 23ab370a223c---> eb683d133105
Step 3/11 : ADD jdk-8u162-linux-x64.tar.gz /usr/local/---> cf74a462ef4a
Step 4/11 : ADD apache-tomcat-8.0.47.tar.gz /usr/local/---> 50e1b915e404
Step 5/11 : ENV JAVA_HOME /usr/local/jdk1.8.0_162---> Running in 62651c01180d
Removing intermediate container 62651c01180d---> 0f440b8fb05c
Step 6/11 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar---> Running in e7b22ff3daae
Removing intermediate container e7b22ff3daae---> 1d7561a73619
Step 7/11 : ENV CATALINA_HOME /usr/local/apache-tomcat-8.0.47---> Running in 10d6926828af
Removing intermediate container 10d6926828af---> 7ee45ddd1cac
Step 8/11 : ENV CATALINA_BASE /usr/local/apache-tomcat-8.0.47---> Running in 6dc85ca63503
Removing intermediate container 6dc85ca63503---> 9ccb74f42ac8
Step 9/11 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin---> Running in 95f3447c1345
Removing intermediate container 95f3447c1345---> afa972c0579f
Step 10/11 : EXPOSE 8080---> Running in 8ec9bc003730
Removing intermediate container 8ec9bc003730---> 0d64ccb2b12e
Step 11/11 : CMD ["/usr/local/apache-tomcat-8.0.47/bin/catalina.sh","run"]---> Running in 60877645aadd
Removing intermediate container 60877645aadd---> ed785fcf2d5f
Successfully built ed785fcf2d5f
Successfully tagged yezi/tomcat:latest
[root@iZbp1b5k5bjps0dw8owk7tZ test]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
查看构建的镜像
[root@iZbp1b5k5bjps0dw8owk7tZ home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yezi/tomcat latest ed785fcf2d5f About an hour ago 598MB
tomcat latest 2d084b11164d 31 hours ago 463MB
centos latest 49f7960eb7e4 4 weeks ago 200MB
[root@iZbp1b5k5bjps0dw8owk7tZ home]#
- 1
- 2
- 3
- 4
- 5
- 6
启动镜像
docker run -d -p 8080:8080 yezi/tomcat
这篇关于docker使用dockfile 写错了 Dockerfile中ENTRYPOINT设置的命令 可以动态覆盖的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!