Docker Learning Note III: Docker deployment Java Web System

Source: Internet
Author: User
Tags docker ps docker run

Docker Deployment Java Web System

1. Create a path in the root directory test/app mkdir Test && CD test&& mkdir app &&cd app

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

3. Extract two tar.gz files

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

4. Rename the extracted files

MV apache-tomcat-7.0.29 Tomcat MV Jdk-7u25-linux-x64 JDK

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

Touch Dockerfile

6.Dockerfile Document content and annotations

-------------------------------------------------------------------------Dockerfile Content------------------------------------ ---------------------------

#使用ubuntu: 14.04 as Base image
From ubuntu:14.04
#指定镜像创建者信息
Maintainer test [email protected]
#创建日期
ENV Refreshed_at 2017-2-15
#切换镜像目录, enter the/usr directory
Workdir/usr
Create a JDK directory #在/usr/to hold the JDK file
RUN mkdir JDK
Create a Tomcat directory under #在/usr/to hold Tomcat
RUN mkdir Tomcat
#切换镜像的目录至/USR/JDK
workdir/usr/jdk/

#将宿主机的jdk目录下的文件拷至镜像的/usr/jdk directory
   ADD JDK/USR/JDK
#切换镜像的目录至/usr/tomcat
   workdir/usr/tomcat
#将宿主机的tomcat目录下的文件拷至镜像的/usr/tomcat Directory
   ADD tomcat/usr/tomcat
#设置环境变量
   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
#切换工作目录到ROOT下
   workdir/usr/tomcat/webapps/root
# Delete the Tomcat default project file
   RUN rm-rf *
#将自己的xxx. War system added to the root directory under Tomcat in the Docker image
  Add webapp/usr/ Tomcat/webapps/xxx.war
#公布tomcat的8080端口
  EXPOSE 8080
#启动tomcat
  entrypoint [".. /.. /bin/catalina.sh "," Run "]

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

7. Create a mirror with Dockerfile

Command: Docker build-t image name: Label Dockerfile location

Docker build-t tms:1.0. (. Represents the current directory)

8. The Java Web System is now made into an image, which is validated by the Docker images

9. Start a docker container by just building the image

Command: Docker run-d-P host mapping port: Container exposed port--name container name Mirror name/Mirror ID

-D parameter: Back-end startup mode

-P parameter: Map of host port to container port

--name parameter: An alias for the container

Docker run-d-P 8081:8080--name container name Mirror name: Mirror tag

10. Use Docker ps-a to verify

Docker Learning Note III: Docker deployment Java Web System

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.