Docker automatic deployment Tomcat detailed _docker

Source: Internet
Author: User
Tags java web docker ps docker run

Docker automatically deploy Tomcat

1. Download Mirror

# Docker Pull Centos:latest #获取最新的centos镜像

2. Start the container

#docker run-i-t-v/home/user/software/:/home/software/imageid/bin/bash

Actually contains the following three parts:

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

Among them, the related parameters include:

-I: means to run the container in interactive mode

-T: Indicates that the container will enter its command line when it starts

-V: Indicates which directory you want to mount to the container in the format:-v < host directory >:< container directory >

Assuming that all of our installers are placed in the/home/user/software/directory of the host, we now need to mount them in the container's/home/software/directory. The initial command indicates that once the container is started, the command that needs to be run, "/bin/bash" is used to indicate nothing, just go to the command line.

3. Install JDK

In order to build a Java WEB runtime environment, we need to install JDK and Tomcat, and the following procedures are within the container.

#chmod +x Jdk-6u45-linux-x64-rpm.bin

#./jdk-6u45-linux-x64-rpm.bin

# java-version

4. Install Tomcat

① the extracted tomcat to the/opt/root directory under the name tomcat7.0. Then configure the JDK and Tomcat environment variable modification files/etc/profile The following environment variables at the end of the profile file:

Export java_home=/usr/java/jdk1.6.0_38
export jre_home=/usr/java/jdk1.6.0_38/jre
export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar 
export tomcat_home=/opt/tomcat7.0
export catalina_home=/opt/ tomcat7.0 
export path= $PATH:/sbin:/bin:/usr/sbin:/usr/bin:/usr/x11r6/bin: $JAVA _home/bin 

② set Open container is startup script, add:

# cd/root/run.sh

#!/bin/bash

source/etc/profile

sh/opt/tomcat7.0/bin/catalina.sh Run

③ Modify Tomcat User login account and password

# vi/opt/tomcat7.0/conf/tomcat-users.xml

<tomcat-users>

 <role rolename= ' root '/>

 <user Username= "root" password= "root" roles= "Manager-gui"/>

</tomcat-users>

5. Exit container

When all the above steps are complete, you can exit the container using the Exit command. You can then view the running container by using the following command:

#docker PS

At this point, you should not see any running programs, because the container that you just exited with the Exit command is in a stopped state, and you can view all containers using the following command:

#docker ps-a

Remember the above container ID (container ID), and then we will create a mirror running the Java Web through the container.

6. Create a Java Web image

Use the following command to create a new mirror image based on a "container ID":

#docker Commit 57c312bbaad1 javaweb:0.1

The ID of the container is "57c312bbaad1" and the Mirror name created is "javaweb:0.1", which can then be used to start the Java Web container.

7. Start the Java Web container

It is necessary to first use the Docker Images command to view all current mirrors.

Visible, you have seen the most recently created mirror "javaweb:0.1" with a mirror ID of "d70ea3e3000c". As described above, we can start the container with "mirror name" or "Mirror ID", unlike the last boot container, where we now stop entering the container's command line and start the Tomcat service directly inside the container. At this point, you need to use the following command:

#docker run-d-v/home/user/software/:/home/software/-P 58080:8080--name javaweb javaweb:0.1/root/run.sh

If the creation fails, try to focus on Docker.

-D: Indicates that the/root/run.sh script is executed in "daemon mode", when the Tomcat console does not appear on the output terminal.

-P: Represents the port mapping of the host and container, at which point 8080 ports inside the container are mapped to 58080 ports of the host, exposing 58080 ports to the outside, and accessing the 8080 ports inside the container through the Docker Network Bridge.

--name: Represents the container name, with a meaningful name.

The log view Tomcat has been started.

10. Test

Enter URL address locally with browser: http://10.5.83.210:58080/manager/index.jsp

Success!

Thank you for reading, I hope to help you, thank you for your support for this site!

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.