In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to configure Tomcat in Docker and run the web project". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to configure Tomcat in Docker and run the web project.
First, install Tomcat
1. Find the tomcat image on Docker Hub
Docker search tomcat
2. Pull the official image
Docker pull tomcat
It will take some time to wait for the download to finish.
3. View all the images of docker
Docker images
4. Start the tomcat image
Note: the former is the peripheral access port: the latter is the internal port of the container.
Docker run-d-p 8080 tomcat
Note: the former is the peripheral access port: the latter is the internal port of the container. The following command can start tomcat-d in the background: run the container in the background and return the container ID;-I: run the container in interactive mode, usually used at the same time with-t;-t: reassign a pseudo-input terminal to the container, usually used with-I
Docker run-d-p 8080 tomcat
The startup is successful as follows:
5. View the running container
Docker ps
Deploy your own web project to Tomcat
1. Upload war package
2. Create and edit "Dockerfile" as follows:
From tomcat # Image of your tomcat MAINTAINER * @ 163.com # author RUN rm-rf / usr/local/tomcat/webapps/*COPY button.war / usr/local/tomcat/webapps # is placed in tomcat's webapps directory ENV TZ=Asia/ShanghaiRUN ln-snf / usr/share/zoneinfo/$TZ / etc/localtime & & echo $TZ > / etc/timezone
3. Generate a new image
Docker build-t button:v1.
4. Start a new image
Docker run-d-p 8080 button:v1
5. View the started image
You can add the parameter-itd background to start tomcat to view the started images in the following ways
Docker ps
6. View the items in tomcat
You can enter the tomcat image using the following command:
Docker exec-it * / bin/bash # * is the container id (CONTAINER_ID)
When we enter the image and want to modify some parameters, we usually need to install a text editor. Take vim as an example: since the download address is overseas, the download speed is very slow and may be interrupted, so make the following configuration:
Mv / etc/apt/sources.list / etc/apt/sources.list.bakecho "deb http://mirrors.163.com/debian/ jessie main non-free contrib" > / etc/apt/sources.listecho "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" > > / etc/apt/sources.listecho "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" > > / etc/apt/sources.listecho "deb-src http : / / mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib "> > / etc/apt/sources.list
Then update
Apt update
Now we can install the software we need, such as vim
Apt install vim
7. Enter ip and port to view
8. You can view the log of the specified container
Docker logs-f container id
9. After deploying the web project, there may be a difference of 8 hours between docker container and host, docker container and tomcat application printing log time and our current time. You can add the following configuration:
When ① starts the container, mounting the system time into the container can solve the problem of inconsistency between the docker container and the host time, as follows: add parameters
-v / etc/localtime:/etc/localtime:ro
The complete command is as follows:
Sudo docker run-d-- name button-api-p 8080V / etc/localtime:/etc/localtime:ro button-api:v1
The ② docker container is inconsistent with the printing log time of the tomcat application. After starting the tomcat container, go to the "bin" directory of tomcat, and modify the catalina.sh file to add the following in the first line at the end of the comment:
JAVA_OPTS= "$JAVA_OPTS-Dfile.encoding=UTF8-Duser.timezone=GMT+08"
As shown in the following figure:
Just restart the docker container after modifying and saving it. Restart method: "docker ps" query container id, and restart using the following command:
Docker restart Container id
The problem can be solved at this point.
Thank you for reading, the above is the content of "how to configure Tomcat in Docker and run web project". After the study of this article, I believe you have a deeper understanding of how to configure Tomcat and run web project in Docker, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.