Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of docker Image centos7 configuring Java running Environment

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the example analysis of docker image centos7 configuration Java running environment. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1. Pull centos image

Docker pull centos:7

two。 Run a container based on the pulled image

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

When running, it goes directly into the interface of the container.

3. Install jdk in the container

First query the available jdk version

Yum search java | grep jdk

Install according to jdk found

Yum install java-1.7.0-openjdk

You don't have to configure environment variables after installation, because it seems to be automatically configured after installation. Use the command to test whether jdk is installed successfully.

Java-version

If the jdk version number is displayed normally, the installation is successful, and then use exit to exit the container directly to the host

4. Install tomcat

Manually download the tar package of tomcat from the official website; for example, apache-tomcat-7.0.78.tar.gz will upload the file to the host first; you can use FTP and other methods to copy the tomcat package to the docker container after the upload is completed; copy command:

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

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

5. Make a tomcat startup script in the container

Enter a container that is already running

Docker exec-it mycentos / bin/bash

Create a file

Touch / root/run.sh

Edit a file

Vi / root/run.sh

Enter the contents of the file and save exit

#! / bin/bashexprot 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:$PATHsh / usr/tomcat/bin/catalina.sh run

The storage directory of JAVA_HOME:jdk, which defaults to the one in the above command

PATH: no need to explain

Sh: specifies the catalina.sh script that tomcat actually starts

Add permissions to run.sh

Chmod uplix / root/run.sh

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

6. Make a tomcat image

Docker commit mycentos mytomcat:7

The image repository submitted by the mycentos container. The image name is mytomcat and the version number is: 7.

7. Start a tomcat container with the created tomcat image

Docker run-d-name tomcat1-p 5001 mytomcat:7 / root/run.sh 8080 mytomcat:7

Use docker ps to check whether the container starts successfully-d: indicates that it starts in daemon mode-name: specify the name of the container-p: map port tomcat 8080 to port 5001 mytomcat:7 of the host: the tomcat image made in the previous step

8. Browser access

Http:// host ip:5001

Question 1: how to get into a running container

Docker exec-it tomcat1 / bin/bash

Question 2: how to deploy the project to tomcat

Docker cp / ROOT.war tomcat1:/usr/tomcat/webapps

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

Question 3: how to set the time zone of the docker container

Cp / usr/share/zoneinfo/PRC / etc/localtime

Execute the above command directly in the container. After execution, use the date command to check whether the container time is the same as the current time.

Question 4: how to set the time zone of tomcat

Export JAVA_OPTS= "$JAVA_OPTS-Dfile.encoding=UTF8-Duser.timezone=GMT+08"

Add the above code to the first line of the tomcat/bin/catalina.sh file; because the time difference between the tomcat in the container and the real time is 8 hours, it is a problem caused by inconsistent time zone; save and exit after setting up, and then restart the container to see that the time is the same.

Question 5: how to restart the container

Stop the container

Docker stop tomcat1

Start the container

This is the end of docker start tomcat1's article on "sample Analysis of docker Image centos7 configuration Java running Environment". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report