构建 JDK1.7 + Tomcat8 Docker 镜像
Tomcat 本身是有现成的官方镜像的。
可惜最低支持到openJDK1.8,项目需要1.7的,所以需要自己来构建使用 openJDK1.7 的镜像。
Dockerfile
FROM centos:latest
RUN mkdir -p /usr/local/java/jdk1.7
RUN mkdir -p /usr/local/tomcat
ADD jdk1.7.0_80 /usr/local/java/jdk1.7
ADD apache-tomcat-8.5.42 /usr/local/tomcat
ENV JAVA_HOME /usr/local/java/jdk1.7
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"]
下载好jdk1.7和tomcat8的安装包,并放到和Dockerfile同一目录下,建新镜像执行
wget https://files-cdn.liferay.com/mirrors/download.oracle.com/otn-pub/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz
tar -zxvf jdk-7u80-linux-x64.tar.gz
tar -zxvf apache-tomcat-8.5.42.tar.gz
docker build -t colbrze430/jdk7-tomcat8 .
使用 docker-compose.yml
version: "3.4"
services:
web1:
image: colbrze430/jdk7-tomcat8
ports:
- "8080:8080"
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- $PWD/lantin:/usr/local/tomcat/webapps/ROOT # 项目目录
- $PWD/catalina.sh:/usr/local/tomcat/bin/catalina.sh
- $PWD/logs1:/lantin
web2:
image: colbrze430/jdk7-tomcat8
ports:
- "8081:8080"
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- $PWD/lantin:/usr/local/tomcat/webapps/ROOT # 项目目录
- $PWD/catalina.sh:/usr/local/tomcat/bin/catalina.sh
- $PWD/logs2:/lantin
tomcat 的相关配置可以通过修改 catalina.sh 文件来配置。
热更新脚本 update.sh :
#!/bin/bash
set -e
if [ ! -f lantin.zip ]; then
echo "未找到 lantin.zip 文件, 请将文件放到 $(pwd) 下"
exit -1
fi
unzip -o lantin.zip
docker-compose restart web1
start=$(date "+%s")
while [ $(curl -I -m 3 -o /dev/null -s -w %{http_code} 127.0.0.1:8080) == 000 ]
do
now=$(date "+%s")
echo -en "\r等待 web1 重启..." $((now-start))
sleep 1
done
echo -e "\nweb1 已启动\n"
docker-compose restart web2
start=$(date "+%s")
while [ $(curl -I -m 3 -o /dev/null -s -w %{http_code} 127.0.0.1:8081) == 000 ]
do
now=$(date "+%s")
echo -en "\r等待 web2 重启..." $((now-start))
sleep 1;
done
echo -e "\nweb2 已启动\n"
rm -f lantin.zip
包含了解压和重启。
网友评论