Detail docker mirror centos7 configuration Java runtime environment

  • 2020-06-15 10:34:12
  • OfStack

1. Pull centos mirror image


docker pull centos:7

2. Run 1 container based on the pulled image


docker run -it --name mycentos docker.io/centos:7 /bin/bash

Running it takes you directly into the container's interface

3. Install jdk in the container

Start by querying the available version of jdk


yum search java|grep jdk

Follow the search to jdk to install


yum install java-1.7.0-openjdk

You don't need to configure the environment variables once the installation is complete, as it appears to be automatically configured to test the jdk installation with commands


java -version

If the version number of jdk is displayed normally indicating a successful installation, then exit the container directly to the host using exit

4. Install tomcat

Download the tar package from the official website manually; apache-tomcat-7.0.78. tar. gz upload the file to the host first. You can copy the tomcat package to the docker container with FTP and so on. Copy command:


docker cp /apache-tomcat-7.0.78.tar.gz mycentos:/usr

The command above is to copy the tomcat package to the usr directory named mycentos container

5. Make the tomcat startup script in the container

Enter the container that is already running


docker exec -it mycentos /bin/bash

Create a file


touch /root/run.sh

Edit the file


vi /root/run.sh

Enter file contents, save and exit


#!/bin/bash
exprot JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/
export PATH=$JAVA_HOME/bin:$PATH
sh /usr/tomcat/bin/catalina.sh run

JAVA_HOME: The directory in which jdk is stored. It defaults to the above command
PATH: Don't explain
sh: Specifies the ES72en.sh script that tomcat actually starts
Add permissions to run.sh


docker run -it --name mycentos docker.io/centos:7 /bin/bash
0

Exit the container after authorization is completed; Exit to the host using the exit command

6. Mirror tomcat


docker run -it --name mycentos docker.io/centos:7 /bin/bash
1

The mirror warehouse to which the mycentos container is submitted is named mytomcat and has version number: 7

7. Start an tomcat container with the made tomcat image


docker run -it --name mycentos docker.io/centos:7 /bin/bash
2

Use docker ps to see if the container started successfully -d: means started in a daemon mode -name: specify the name of the container -p: map port tomcat 8080 to port mytomcat:7: the tomcat image made in step 1 above

8. Browser access


http:// The host machine ip:5001

Question 1: How do I get into a running container


docker run -it --name mycentos docker.io/centos:7 /bin/bash
4

Question 2: How do I deploy the project to tomcat


docker run -it --name mycentos docker.io/centos:7 /bin/bash
5

Directly in the host copy Jar package to the container tomcat webapps directory

Question 3: How do I set the time zone of the docker container


docker run -it --name mycentos docker.io/centos:7 /bin/bash
6

Execute the above command directly in the container, and then use the date command to see if the container time is the same as the current time

Question 4: How to set the time zone of tomcat


docker run -it --name mycentos docker.io/centos:7 /bin/bash
7

In tomcat/bin/catalina sh file line 1 to add the code above; Because the time difference between tomcat in the container and the real time is 8 hours, it is caused by the time zone not 1. When the setup is complete, save and exit, and restart the container to see time 1

Question 5: How do I restart the container

Stop the container


docker stop tomcat1

Start the container


docker run -it --name mycentos docker.io/centos:7 /bin/bash
9

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


Related articles: