2020年 · Docker · Linux

制作一个tomcat8+JDK1.8之docker镜像

需要的安装包:apache-tomcat-8.5.51.tar.gz   jdk-8u241-linux-x64.tar.gz
解压后  mv apache-tomcat-8.5.51  tomcat8

本镜像是基于lbelmarletelier/debian9:latest 镜像制作

root@prv:~/tomcat8.5.51_dockerfile# cat Dockerfile
FROM lbelmarletelier/debian9:latest

RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo “deb http://mirrors.163.com/debian/ stretch main non-free contrib” > /etc/apt/sources.list && \
echo “deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib” >> /etc/apt/sources.list && \
echo “deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib” >> /etc/apt/sources.list && \
echo “deb-src http://mirrors.163.com/debian/ stretch main non-free contrib” >> /etc/apt/sources.list && \
echo “deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib” >> /etc/apt/sources.list && \
echo “deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib” >> /etc/apt/sources.list && \
echo “deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib” >> /etc/apt/sources.list && \
echo “deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib” >> /etc/apt/sources.list

RUN apt-get update && apt-get -y install net-tools libapr1-dev libssl-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/*

ADD jdk1.8.0_241 /usr/local/jdk1.8.0_241
ADD tomcat8 /usr/local/tomcat8

RUN cd /usr/local/tomcat8/bin/ && tar zxf tomcat-native.tar.gz   && cd  tomcat-native-*-src/native && \
./configure –with-apr=/usr/bin/apr-1-config –with-java-home=/usr/local/jdk1.8.0_241 –with-ssl=yes –prefix=/usr/local/tomcat8 && \
make && make install

RUN groupadd -g 1000 webuser && useradd -u 1000 -g webuser webuser && \
chown webuser:webuser -R /usr/local/tomcat8

ENV JAVA_HOME /usr/local/jdk1.8.0_241
ENV JRE_HOME /usr/local/jdk1.8.0_241/jre
ENV CATALINA_HOME /usr/local/tomcat8
#ENV TOMCAT_NATIVE_LIBDIR /usr/local/tomcat/native-jni-lib
#ENV LD_LIBRARY_PATH /usr/local/tomcat/native-jni-lib
ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $CATALINA_HOME/bin:$JAVA_HOME/bin:$PATH

EXPOSE 8080

WORKDIR /usr/local/tomcat8

CMD [“catalina.sh”, “run”]

root@prv:~/tomcat8.5.51_dockerfile# docker build -t tomcat8.5.51 .    #开始创建镜像
root@prvbru:~/tomcat8.5.51_dockerfile# docker images
REPOSITORY TAG            IMAGE         ID                CREATED    SIZE
tomcat8.5.51                        latest     b5fc3610c5eb   3 days   ago   927MB
lbelmarletelier/debian9    latest     93ced94438c7   5 months   ago   455MB