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

How to use Tomcat to quickly deploy web applications in Docker

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of "how to deploy web applications quickly with Tomcat in Docker". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to quickly deploy web applications with Tomcat in Docker" can help you solve the problem.

First of all, it is necessary to install docker on the machine. If not, install it with the yum install-y docker command.

Yum install-y docker

Since we are deploying web applications, of course we can't do without tomcat, so we should pull the tomcat image first. The command is as follows

Docker pull tomcat

This image is a little large, so it can be pulled in advance to save time.

Next we use the tomcat image to start a container

Docker run-it-- name webdemo-p 80purl 8080 tomcat / bin/bash

Here we start an interactive container, named webdemo,-p 80, which means mapping port 8080 of the container to port 80 of the host, so that we can access the service of the container as long as we access port 80 of the host.

After the container is created, it will enter the container, and we can just take a look at the internal file structure. There is a webapps file, we just need to save our web application to the format of war package, and then copy it to this file. Because tomcat will automatically unpack and deploy the war package for us.

How do I copy files from the host to the container?

Because my previous terminal is in the container, here I open the second terminal to operate. I put my war package files in the / mnt/ directory

Copy from the host to the container sudo docker cp host_path containerid:container_path

Copy from the container to the host sudo docker cp containerid:container_path host_path

The orders we use here are:

Docker cp / mnt/webdemo.war a2f2091a661fa51e02c0be54f252fc46fc604932526b17038ccc267affcef12c:/usr/local/tomcat/webapps

The long string is the id of the container. Check it yourself. The latter path is the internal path of the container. If you really don't know how to copy it, you can copy it. Note here: there is no space after the colon. I had a space before, and I can't copy it all the time.

The next step is to start tomcat.

The war package has been imported into the container. At this time, we can go to the first terminal to check it.

You can see that the war package has been imported. But at this time, the tomcat service is not started, so let's start the tomcat service and let tomcat help us unpack and deploy the war package.

Here we go to the bin directory to run the catalina.sh file in the directory so that tomcat runs, and tomcat runs at the front end, which is why I opened the second terminal.

Finally, we can see the effect in the browser:

This is the end of the introduction to "how to quickly deploy web applications with Tomcat in Docker". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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

Development

Wechat

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

12
Report