Docker automatically deploys tomcat details

  • 2020-05-24 06:34:29
  • OfStack

Docker automatically deploys tomcat

1. Download the image

# Docker pull centos:latest # gets the latest centos image

2. Start the container

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

In fact, it consists of the following three parts:

docker run < Related parameters > < Mirror ID > < The initial order >

Among them, relevant parameters include:

-i: means to run the container in "interactive mode"

-t: indicates that the container enters its command line when it is started

-v: indicates which local directory needs to be mounted into the container, in the format: -v < Host directory > : < Container directory >

Assuming that all our installers are in the host's /home/user/software/ directory, we now need to mount them to the container's /home/software/ directory. The initial command represents a command that needs to be run once the container is started. At this point, "/bin/bash" is used to mean that nothing is done but the command line is entered.

3. Install JDK

In order to set up the Java Web running environment, we need to install JDK and Tomcat. The following procedures are carried out inside the container.

#chmod +x jdk-6u45-Linux-x64-rpm.bin

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

# java -version

4. Install Tomcat

Upload the extracted tomcat to the root directory of /opt/ and name it tomcat7.0. Then configure the jdk and tomcat environment variables to modify the file /etc/profile and append the following environment variables to 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 

Setting the open container is a startup script, add:


# cd /root/run.sh

#!/bin/bash

source /etc/profile

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

Modify the login account and password of tomcat user


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

<tomcat-users>

 <role rolename="root"/>

 <user username="root" password="root" roles="manager-gui"/>

</tomcat-users>

Exit the container

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

#docker ps

At this point, you should not be able to see any of the running programs, because the container that has just exited using the exit command is in a stop state, and you can view all containers using the following command:

#docker ps -a

Remember Container ID (container ID) above, and then we will create a running image of Java Web from that container.

6. Create Java Web mirror

Create a new "mirror" based on a "container ID" using the following command:

#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 launch the Java Web container.

7. Start the Java Web container

It is necessary to first view all the current images using the docker images command.

Visible, at this time has already seen the newly created image "javaweb: 0.1", the mirror ID is "d70ea3e3000c". As described above, we can start the container by "mirroring the name" or "mirroring ID." unlike the last time we started the container, we no longer go to the command line of the container, but directly start the Tomcat service 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 restarting docker.

-d: means to execute the /root/ run.sh script in "daemon mode" when the Tomcat console does not appear on the output terminal.

-p: represents the port mapping between the host and the container. At this point, port 8080 inside the container is mapped to port 58080 of the host. Thus, port 58080 is exposed to the outside world, and port 8080 inside the container can be accessed through the Docker bridge.

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

Check the log to see if tomcat has started.

Test 10.

In the local browser enter url address: http: / / 10.5.83.210:58080 / manager index. jsp

Success!

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


Related articles: