Docker's simple Build (Java/tomcat environment)

Source: Internet
Author: User
Tags server port docker ps docker cp docker run

1, a simple picture of the layout of the Docker, it is virtual, Docker is divided into a VPN, mirror, container three modules

Generally from the server pull image, image run a container, we put the container as a virtual service, which can be run independently of the process has a separate intranet IP,

Usually the Tomcat, the project is hung in the container to run

2. Fast installation of Docker (not much difference on CentOS, Ubuntu)

sudo apt-get updatesudoinstall Docker.io
#启动服务和守护进程service Docker.io statusservice Docker.io start

3. Download the image file (pull command download, download a mirror from a single, and re-create it Yourself)

#pull followed by the name of the image, you can first Docker  search Java in the download Java if there is this image and then downloaded
sudo Docker pull Java

#下载好后 Whether the query image exists
sudo docker images

3. Download the image to create and then make the container.

Once the image is downloaded locally, you can use Docker to run it,
Start the container with the following command arguments,

Docker run < related parameters > < mirroring id> < initial commands >

-I: Indicates that the container is running in "interactive mode"
-T: Indicates that the container will enter its command line after it is started ()
-V: Indicates which directory you need to mount to the container ( this directory is interactive with the local, and the files in the directory are visible to each other in the container and locally )
Format:-v < host directory >:< container directory >

#我的相关程序都在当前机器的 the/data/software/ directory and want to mount it in the same directory as the container:sudo docker run-i-t-v/data/software/:/data/ Software/ae983d5e88ce/bin/bash

4, create the container automatically into the container and then install the JDK and Tomcat and so on (This step is most important to configure the Tomcat environment, the configuration is not good to restart the container does not run) (You can use the command (Docker CPfile nameContainer ID : the path under the container) the correspondingthe installation fileCopied into the container)

Install the relevant JDK and other programs, all installed in the/data/ directory:tar -zxvf jdk-7u25-linux-x64. tar. gz-c/data/mv jdk1. 7 . 0_25 JDK Unzip apache-tomcat-7.0. . zip -d/data/mv apache-tomcat-7.0.  Wu Tomcat configuration Environment Variables vi /etc/profile Add the following configuration:

Export Histtimeformat
java_home=/data/jdk1.7
Classpath= $JAVA _home/lib/
Path= $PATH: $JAVA _home/bin
Export PATH java_home CLASSPATH


Export Catalina_home=/data/tomcat
Export Catalina_base=/data/tomcat

/etc/profile

5. When you start Tomcat, you must passTOMCATHOME/BIN/CATALINA.SH real now , can make tomcat_home/bin/ Startup.sh is started, or the container exits immediately after the script executes.

VI /data/start. SH Add the following: #!/bin//etc//data/tomcat/bin/catalina. SH Run to add executable permissions: chmod U+x/data/start. SH

#然后退出 container
Exit

#查看容器
Docker PS #查看运行的容器
Docker ps-a #查看 all containers

Docker start container ID #启动容器
Docker restart container ID #重启
Docker stop container ID #停止容器
Docker RM Container ID #删除容器
Docker RMI Image ID #删除镜像


#当你重启容器时 Docker PS also saw that the container started successfully.


6, this makes a good container, and then you can submit the image (you can use this image to create a container, the container has java+tomcat environment )

#提交容器  Create mirror Docker commit  container ID  mirror name sudo Docker commit 39b2cf60a4c1 Flm/java

#查看是否创建镜像
sudo docker images

#如果看到 Flm/java, this image is there to show you were successful.


#docker Inspect can view the details of the newly created image:

sudo Docker inspect Flm/java

7, run the newly created container (- p 18080:8080 is to map the server port 18080 to the container port 8080,javaweb naming container name, /data/start.sh Kai moving files)

8080 18080  180808080PS

And then visit http://192.168.10.16:18080 to show you that you succeeded.

Hahaha Thans

Docker's simple Build (Java/tomcat environment)

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.