Technical work, should be praised and then see, form a habitCopy the code

Docker use tutorial related series of directories


There are two main ways Docker builds images

(1) Run docker commit

(2) use docker build command and Dockerfile (more powerful, flexible and common);

Build a basic Tomcat image

Solution a:

One: Download the installation package

Download the version of Tomcat you need and upload it to your Docker host

vim Dockerfile-tomcat
Copy the code

Two: write dockerfile file

FROM centos:7 MAINTAINER www.zenghw.com ENV VERSION=8.5.47 RUN yum install java-1.8.0- openJDK wget curl unzip iproute Nettools -y && \ yum clean all && \ rm -rf /var/cache/yum/* COPY apache-tomcat-8.5.47.zip/TMP RUN CD/TMP && \ unzip Apache-tomcat-8.5.47.zip && mv apache-tomcat-8.5.47 /usr/local/tomcat8&& rm -rf apache-tomcat-8.5.47.zip && CD /usr/local/tomcat8/bin/ && \ chmod +x *.sh && \ sed -i '1a JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"' /usr/local/tomcat8/bin/catalina.sh && \ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ENV PATH $PATH:/usr/local/tomcat8/bin WORKDIR /usr/local/tomcat8 EXPOSE 8080 CMD ["/usr/local/tomcat8/bin/catalina.sh", "run"]Copy the code

3. Build Generates a local image

Docker build -t tomcat:v1 -f Dockerfile-tomcat. Docker build -t tomcat:v1 -t tomcat:v1 # Tag =v1 -f Dockerfile-tomcat # specifies the name of the Dockerfile.Copy the code

Successful tip

Look at mirror

Run the test

docker run -d -i -t --name=tomcatv1 -p 8888:8080 tomcat:v1
Copy the code

Scheme 2:

One: Prepare a centos image file

docker pull centos:7
Copy the code

2. Download the JDK and Tomcat installation packages and upload them to the /usr/local/soft directory

Jdk1.8 download: www.oracle.com/technetwork…

Tomcat8 download: tomcat.apache.org/download-80…

Three: decompress, create Dockerfile file

Tar -zxvf apache-tomcat-8.5.63.tar.gz # decompress tomcat tar -zxvf jdK-8u281-linux-x64.tar. gz # decompress JDKCopy the code

Rm -rf apache-tomcat-8.5.63.tar.gz # delete installation package rm -rf jdK-8U281-linux-x64.tar. gz # delete installation packageCopy the code

Touch Dockerfile-tomcat # create fileCopy the code

Four: write Dockerfile file

# specify the mirror of the operation

FROM centos:7 # MAINTAINER information MAINTAINER www.zenghw.com RUN mkdir -p /usr/local/soft # RUN mkdir -p /usr/local/soft /usr/local/soft/ JDK/apache-tomcat-8.5.63 /usr/local/soft/ ADD the environment variable ENV JAVA_HOME /usr/local/soft/ JDK ENV CATALINA_HOME and name it tomcat ADD apache-tomcat-8.5.63 /usr/local/soft/tomcat /usr/local/soft/tomcat ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin # EXPOSE 8080 # Run tomcat CMD on startup ["/usr/local/soft/tomcat/bin/catalina.sh","run"]Copy the code

The dockerfile command is shown here

Five: Build Docker image

docker build -t centos_tomcat8:v1 -f Dockerfile-tomcat .
Copy the code

Six: Start the mirror and access

docker run -d -p 8080:8080 --name centos_tomcat01 centos_tomcat8:v1
Copy the code

 

Build a project image using the Tomcat: V1 base image

Create the dockerfile for the project image

FROM tomcat:v1
COPY jenkins.war /usr/local/tomcat8/webapps/jenkins.war
Copy the code

Jenkins can be downloaded from the official website

docker build -t tomcat:v2 -f Dockerfile-tomcat-project-jenkins .
Copy the code

Container startup

docker run -d --name=tomcatv2 -p 8090:8080 tomcat:v2
Copy the code

So Jenkins’ project was deployed.

Reference: blog.csdn.net/qq_37936542…