环境信息:
MacBook Pro(M1)
VMware-fusion(Player 版本 13.0.0 (20802013))
Ubuntu 22.10
tomcat镜像:
centos-7.9.2009
jdk1.8.0_341
apache-tomcat-8.5.84
制作步骤:
(1)下载好tomcat/jdk(我是在macbookpro上制作的,所以用的aarch64的SDK)
注意,apache-tomcat-8.5.84、jdk1.8.0_341和Dockerfile要放到同一个目录下
(2)Dockerfile文件内容
FROM centos:7.9.2009
#install jdk/tomcat
ADD jdk1.8.0_341 /usr/local/jdk
ADD apache-tomcat-8.5.84 /usr/local/tomcat
ENV WORKDIR /usr/local
WORKDIR $WORKDIR
ENV JAVA_HOME /usr/local/jdk
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
EXPOSE 8080
CMD ["/usr/local/tomcat/bin/catalina.sh","run"]
(3)构建镜像:
docker build -t centos-7.9.2009-tomcat-8.5.84:5.0 .
(4)启动镜像:
docker run -d -p 8080:8080 --name tomcatv5 centos-7.9.2009-tomcat-8.5.84:5.0
(5)查看启动日志:
docker logs 187b4a6de782143edc69e93ea54235233fbdac6d25dafc0fefafed8c266bfc8f
(6)查看容器:
docker ps -a
(7)进入命令模式:
docker exec -it 187b4a6de782143edc69e93ea54235233fbdac6d25dafc0fefafed8c266bfc8f /bin/bash
(8)在宿主机上执行如下命令即可访问docker提供的tomcat服务
http://172.16.218.128:8080/
,其中的172的IP地址是宿主机的IP
曾经碰到 docker (56) Recv failure: Connection reset by peer,重启下docker服务就OK了。