Docker use tutorial related series catalog
table of Contents
There are two main methods for Docker to build images
1: Download the installation package
Two: Write the dockerfile file
Three: build to generate a local mirror
Two: Download the jdk, tomcat installation package, and upload it to the /usr/local/soft directory
Three: Unzip, create Dockerfile file
Use tomcat:v1 basic image to build a project image
There are two main methods for Docker to build images
(1) Use the docker commit command
(2) Use docker build command and Dockerfile file (more powerful, flexible and commonly used);
Build tomcat basic image
Option One:
1: Download the installation package
Download the tomcat version you need and upload it to the docker host
vim Dockerfile-tomcat
Two: Write the 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 net-tools -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"]
Three: build to generate a local mirror
docker build -t tomcat:v1 -f Dockerfile-tomcat . # 使用 Dockerfile-tomcat 文件构建一个基础镜像 tomcat:v1
-t tomcat:v1 # 指定版本tag=v1
-f Dockerfile-tomcat # 指定dockerfile的名称
. # 指定上下文(比如配置文件在那个位置等)
Prompt for success
View mirror
Run the test
docker run -d -i -t --name=tomcatv1 -p 8888:8080 tomcat:v1
Option II:
One: prepare centos mirror
docker pull centos:7
Two: Download the jdk, tomcat installation package, and upload it to the /usr/local/soft directory
jdk1.8 download: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
tomcat8 download: https://tomcat.apache.org/download-80.cgi
Three: Unzip, create Dockerfile file
tar -zxvf apache-tomcat-8.5.63.tar.gz #解压tomcat
tar -zxvf jdk-8u281-linux-x64.tar.gz #解压jdk
rm -rf apache-tomcat-8.5.63.tar.gz #删除安装包
rm -rf jdk-8u281-linux-x64.tar.gz #删除安装包
touch Dockerfile-tomcat #创建文件
Four: write Dockerfile file
#Specify the mirror of the operation
FROM centos:7
# 维护者信息
MAINTAINER www.zenghw.com
#执行命令:创建目录
RUN mkdir -p /usr/local/soft
#将jdk1.8.0_281添加到镜像centos的/usr/local/soft/目录下,并命名为jdk
ADD jdk1.8.0_281 /usr/local/soft/jdk
#将apache-tomcat-8.5.63添加到镜像centos的/usr/local/soft/目录下,并命名为tomcat
ADD apache-tomcat-8.5.63 /usr/local/soft/tomcat
#添加环境变量
ENV JAVA_HOME /usr/local/soft/jdk
ENV CATALINA_HOME /usr/local/soft/tomcat
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
#暴露8080端口
EXPOSE 8080
#启动时运行tomcat
CMD ["/usr/local/soft/tomcat/bin/catalina.sh","run"]
For dockerfile command details, see here
Five: Build a Docker image
docker build -t centos_tomcat8:v1 -f Dockerfile-tomcat .
Six: start mirroring, access
docker run -d -p 8080:8080 --name centos_tomcat01 centos_tomcat8:v1
Use tomcat:v1 basic image to build a project image
Create the dockerfile of the project image
FROM tomcat:v1
COPY jenkins.war /usr/local/tomcat8/webapps/jenkins.war
jenkins can be downloaded on the official website
docker build -t tomcat:v2 -f Dockerfile-tomcat-project-jenkins .
Container start
docker run -d --name=tomcatv2 -p 8090:8080 tomcat:v2
In this way, the Jenkins project is deployed.
Reference: https://blog.csdn.net/qq_37936542/article/details/80824389