1 自定义镜像 tomcat9
FROM centos
MAINTAINER tzb<111@qq.com>
# 把宿主机当前目录下的 c.txt 拷贝到 /usr/local/ 路径下
COPY c.txt /usr/local/cincontainer.txt
# 解压缩后拷贝
ADD jdk-8u202-linux-x64.tar.gz /usr/local
ADD apache-tomcat-9.0.8.tar.gz /usr/local
RUN yum -y install vim
# 登录落脚点
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/jdk1.8.0_202
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.8
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.8
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
# 容器运行时监听的端口
EXPOSE 8080
# 启动时运行 tomcat
# ENTRYPOINT ["/usr/local/apache-tomcat-9.0.38/bin/startup.sh"]
# CMD ["/usr/local/apache-tomcat-9.0.38/bin/catalina.sh","run"]
CMD /usr/local/apache-tomcat-9.0.8/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.8/bin/logs/catalina.out
1.1 构建
1.2 运行镜像
docker run -d -p 9080:8080 --name myt9 \
-v /tzbuse/mydockfile/tomcat9/test:/usr/local/apache-tomcat-9.0.8/webapps/test \
-v /tzbuse/mydockfile/tomcat9/tomcat9logs:/usr/local/apache-tomcat-9.0.8/webapps/logs \
--privileged=true tzbtomcat9
1.3 在docker 镜像中执行命令