English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Docker Learning Notes: Deploying Java Web System with Docker

Docker deployment of Java Web system

 1.In the root directory, create a path test/.In the root directory, create a path test

2.Copy apache-tomcat-7.0.29.tar.gz and jdk-7u25-linux-x64.tar.gz copy to the app directory

3.Unzip two tar.gz files

tar -zxvf apache-tomcat-7.0.29.tar.gz tar -zxvf jdk-7u25-linux-x64.tar.gz

4.Rename the unpacked files

mv apache-tomcat-7.0.29 tomcat mv jdk-7u25-linux-x64 jdk

5.In the app directory, create a Dockerfile file to create the image

touch Dockerfile

6.Dockerfile document content and annotations

-----------------------------Dockerfile content----------------------------------

 # Use ubuntu:14.04As the base image
 FROM ubuntu:14.04
# Specify the information of the image creator
 MAINTAINER test [email protected]
# Creation date
 ENV REFRESHED_AT 2017-2-15
# Change the image directory, enter/usr directory
 WORKDIR /usr
# In/usr/Create a jdk directory below to store jdk files
 RUN mkdir jdk
# In/usr/Create a tomcat directory below to store tomcat
 RUN mkdir tomcat
# Change the directory of the image to/usr/jdk
 WORKDIR /usr/jdk/
# Copy files from the host's jdk directory to the image/usr/In the jdk directory
 ADD jdk /usr/jdk
# Change the directory of the image to/usr/tomcat
 WORKDIR /usr/tomcat
# Copy files from the host's tomcat directory to the image/usr/In the tomcat directory
 ADD tomcat /usr/tomcat
# Set environment variables
 ENV JAVA_HOME=/usr/jdk
 ENV JAVA_BIN=/usr/jdk/bin
 ENV PATH=$PATH:$JAVA_HOME/bin
 ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#Switch the working directory to ROOT
 WORKDIR /usr/tomcat/webapps/ROOT
#Delete the default project files of tomcat
 RUN rm -rf *
#Add your xxx.war system to the ROOT directory under tomcat in the docker image
 ADD webapp /usr/tomcat/webapps/xxx.war
#Announce the port of tomcat8080 Port
 EXPOSE 8080
#Start tomcat
 ENTRYPOINT ["../../bin/catalina.sh","run"]

---------------------------------------------------------------------------------

7.Create an image through Dockerfile

Command:  

docker build -t Image Name: Tag Dockerfile Location
docker build -t tms:1.0 . (. represents the current directory)

8.Thus, the Java Web system is made into an image, and verified through docker images

9.Through the newly built image to start a Docker container

Command: docker run -d -p Host Machine Mapped Port: Container Exposed Port --name Container Name Image Name/Image ID

-d Parameter: Backend startup mode

-p Parameter: Mapping of host machine port to container port

--name Parameter: Give the container a different name

docker run -d -p 8081:8080 --name Container Name Image Name name: Image Tag

10.Through docker ps -a to verify

That's all for this article. Hope it will be helpful to your study, and also hope everyone will support the Yelling Tutorial.

Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report by email to codebox.com (replace # with @ when sending email) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.

You May Also Like