通过Tomcat安装包构建镜像
- Dockerfile
shell
# 使用官方的OpenJDK镜像作为基础镜像
FROM xa-test.harbor.com:55555/idaas/openjdk:8u232
ENV CATALINA_HOME=/usr/local/tomcat
ENV PATH=$CATALINA_HOME/bin:$PATH
# 将Tomcat的压缩包复制到镜像中并解压到指定目录
COPY apache-tomcat-8.5.61.tar.gz /usr/local/
RUN tar -xvzf /usr/local/apache-tomcat-8.5.61.tar.gz -C /usr/local/ && \
mv /usr/local/apache-tomcat-8.5.61 /usr/local/tomcat && \
rm -rf /usr/local/apache-tomcat-8.5.61.tar.gz
RUN chown -R root:root /usr/local/tomcat
RUN chmod +x $CATALINA_HOME/bin/catalina.sh
WORKDIR $CATALINA_HOME
# 暴露端口
EXPOSE 8080
# 设置容器启动时执行的命令
CMD ["catalina.sh", "run"]
- 将apache-tomcat-8.5.61.tar.gz 和Dockerfile放在同一目录下
删除镜像,根据镜像id
docker rmi $(docker images | grep tomcat | grep -v grep | awk '{ print $3 }')
- 构建
shell
docker build -t xa-test.harbor.com:55555/idaas/tomcat_x86:8.5.61 . --no-cache
- 运行
shell
docker run -d -p 8888:8080 --name tomcat xa-test.harbor.com:55555/idaas/tomcat_x86:8.5.61
- 推送仓库
shell
docker push xa-test.harbor.com:55555/idaas/tomcat_x86:8.5.61