Docker Mirror and Docker File Making tomcat Mirror

Keywords: Tomcat JDK CentOS Docker

Make tomcat image:

JDK and tomcat images are constructed based on centos 7.2.1511 basic images provided by the government. First, JDK images are constructed, and then tomcat images are constructed based on JDK images.

Building JDK Mirror

  1. Download the Basic Mirror Centos:
docker pull centos
  1. Execute the build JDK image:
mkdir /opt/dockerfile/{web/{nginx,tomcat,jdk,apache},system/{centos,ubuntu,redhat}} -pv
cd /opt/dockerfile/web/jdk/
  1. Edit Dockerfile
vim Dockerfile
#JDK Base Image
FROM centos-7.5-base:latest

MAINTAINER zhangshijie "zhangshijie@300.cn"

ADD jdk-8u162-linux-x64.tar.gz /usr/local/src/
RUN ln -sv /usr/local/src/jdk1.8.0_162 /usr/local/jdk
ADD profile /etc/profile
ENV JAVA_HOME /usr/local/jdk
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/:$JRE_HOME/lib/
ENV PATH $PATH:$JAVA_HOME/bin

RUN rm -rf /etc/localtime \
      && ln -snf /usr/share/zoneinfo/Asia/Shanghai/etc/localtime \
      && echo "Asia/Shanghai" > /etc/timezone
  1. Upload JDK compressed package and profile file:
    Upload the JDK compressed package to the current directory of Dockerfile, and then execute the build:
docker build -t centos-7.5-jdk:v1 .
  1. Starting container
docker run -it centos-jdk:v2 bash
  1. Upload the mirror to harbor (see below)
docker push 192.168.10.205/centos/centos-7.2.1511-jdk1.7.0.79

Building tomcat-8 Mirror from JDK Mirror

  1. Enter the tomcat directory:
cd /opt/dockerfile/web/tomcat
  1. Edit Dockerfile file
vim Dockerfile
FROM centos-jdk:v2
RUN useradd www -u 2019

ENV TZ "Asia/Shanghai"
ENV LANG en_US.UTF-8
ENV TERM xterm
ENV TOMCAT_MAJOR_VERSION 8
ENV TOMCAT_MINOR_VERSION 8.0.49
ENV CATALINA_HOME /apps/tomcat
ENV APP_DIR ${CATALINA_HOME}/webapps

RUN mkdir /apps
ADD apache-tomcat-8.5.42.tar.gz /apps
RUN ln -sv /apps/apache-tomcat-8.5.42 /apps/tomcat
  1. Upload Tomcat compression package: apache-tomcat-8.5.42.tar.gz

  2. Building tomcat base image through script

docker build -t tomcat:v1 .
  1. Verify that mirror construction is complete
docker images
  1. Building Business Mirror 1:
mkdir -pv /opt/dockerfile/app/tomcat-app1
cd /opt/dockerfile/app/tomcat-app1
  1. Prepare Dockerfile:
vim Dockerfile
FROM tomcat:v1
ADD run_tomcat.sh /apps/tomcat/bin/run_tomcat.sh
ADD myapp/* /apps/tomcat/webapps/myapp/
RUN chown www.www /apps/ -R
RUN chmod +x /apps/tomcat/bin/run_tomcat.sh
EXPOSE 8080 8009
CMD ["/apps/tomcat/bin/run_tomcat.sh"]
  1. Prepare a custom myapp page:
mkdir myapp
echo "Tomcat Web Page1" > myapp/index.html
  1. Prepare the container to start the execution script:
vim run_tomcat.sh
#!/bin/bash
echo "1.1.1.1 abc.test.com" >> /etc/hosts
echo "nameserver 223.5.5.5" > /etc/resolv.conf
su - www -c "/apps/tomcat/bin/catalina.sh start"
su - www -c "tail -f /etc/hosts"
  1. structure
docker build -t tomcat-app1:v1 .
  1. View mirroring
docker images
  1. Start container test from mirror:
docker run -it -d -p 8888:8080 tomcat-app1:v1
  1. Access test

Posted by neon on Wed, 02 Oct 2019 23:19:00 -0700