Docker image combat, create your own tomcat image and publish
1. Create your own tomcat mirror
1. Prepare tomcat compressed package, jdk compressed package
2. Write the dockerfile file
Write the dockerfile file, officially named it Dockerfile
, and build will automatically find this file, so there is no need to specify -f!
FROM centos
MAINTAINER ybg<[email protected]>
COPY readme.txt /usr/local/readme.txt
ADD jdk-8u281-linux-x64.tar.gz /usr/local
ADD apache-tomcat-9.0.34.tar.gz /usr/local/
RUN yum -y install vim
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/jdk1.8.0_281
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools/jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.34
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.34
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
EXPOSE 8080
CMD /usr/local/apache-tomcat-9.0.34/bin/startup.sh && tail -F /url/local/apache-tomcat-9.0.34/bin/logs/catalina.out
3. Build the image
docker build -t diytomcat .
Screenshot:
4. Start the mirror
docker run -d -p 8003:8080 --name ybgtomcat -v /home/ybg/build/tomcat/test:/usr/local/apache-tomcat-9.0.34/webapps/test -v /home/ybg/build/tomcat/tomcatlogs:/usr/local/apache-tomcat-9.0.34/logs diytomcat
Screenshot:
Test:
Access to port 8003 is successful!
5. Publish the project
Since we have mounted the volume, we only need to publish our project in the /home/ybg/build/tomcat/test directory. We can
create an index.html file in this directory.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>try</title>
</head>
<body>
<h1>
YBG 的第一个tomcat镜像!
</h1>
</body>
</html>
Create a new index.html
test on the host :
test directory under port 8003, the test is successful!
2. Publish your own mirror
1、DockerHub
1. Register a DockerHub account that can log in
Registered address: https://hub.docker.com/
2. Log in to the DockerHub account on your cloud server
docker login -u yybg
Then enter the password, the password is correct to log in successfully!
3. Publish the image
docker push 用户名/ybgtomcat:1.0
Note: The thing to push must be the username/container name: version number, otherwise push will be rejected, and the username/ybgtomcat is the name of your local mirror
Screenshot:
If your name is not username/container name at the beginning, you can modify it by command
docker tag 镜像id 用户名/容器名:版本号
Screenshot:
2. Alibaba Cloud Warehouse
1. Log in to Alibaba Cloud and find the container mirroring service
2. Create a mirror warehouse
After you select the local warehouse and
create it successfully, you can see the following information.
We click in and you can see a lot of information
3. Operate on the cloud server
Push the image to the Registry
docker login --username=叶本国 registry.cn-shenzhen.aliyuncs.com
docker tag [ImageId] registry.cn-shenzhen.aliyuncs.com/docker-ybg/docker-test:[镜像版本号]
docker push registry.cn-shenzhen.aliyuncs.com/docker-ybg/docker-test:[镜像版本号]
Please replace the [ImageId] and [Image version number] parameters in the example according to the actual image information.
Screenshot: