An example of how to quickly deploy web applications using Tomcat in Docker

An example of how to quickly deploy web applications using Tomcat in Docker

After learning the basic operations of Docker, we can try to deploy some basic applications in our container.

In this article, we will talk about how to quickly deploy a web application in docker.

First of all, Docker must be installed on the machine. If it is not installed, use the yum install -y docker command to install it.

yum install -y docker

Since we are deploying a web application, Tomcat is of course indispensable, so we should pull the Tomcat image first. The command is as follows

docker pull tomcat

This image is a bit large, so you can pull it in advance to save time.

Next we use the Tomcat image to start a container

docker run -it --name webdemo -p 80:8080 tomcat /bin/bash

Here we start an interactive container named webdemo. -p 80:8080 means mapping port 8080 of the container to port 80 of the host. In this way, we can access the container service by accessing port 80 of the host.


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

How to copy files from host to container?

Because my previous terminal was in the container, I opened a second terminal here to operate. I put my war package file in the directory /mnt/


Copy from host to container sudo docker cp host_path containerID:container_path

Copy from container to host sudo docker cp containerID:container_path host_path

The command we use here is:

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

The long string is the container ID, check it yourself. The path behind is the internal path of the container. If you really don’t understand it, you can copy it. Please note here: there is no space after the colon. I had a space before it and couldn’t copy it.

The next step is to start Tomcat.

The war package has been imported into the container. Now we can go to the first terminal to check it.


You can see that the war package has been imported. However, the Tomcat service is not started at this time. Let's start the Tomcat service and let Tomcat help us decompress and deploy the war package.


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

Finally, we can view the effect in the browser:


This page is just for demonstration, so you can try it if you have other small applications!

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of Docker deployment of Tomcat and Web applications
  • Detailed explanation of Docker automatic deployment of tomcat
  • Detailed steps to deploy tomcat and java applications in docker
  • Use docker to deploy tomcat and connect to skywalking

<<:  Mysql 5.7.18 Using MySQL proxies_priv to implement similar user group management

>>:  Detailed explanation of MySQL master-slave replication process

Recommend

Installation and configuration of mysql 8.0.15 under Centos7

This article shares with you the installation and...

Use node-media-server to build a simple streaming media server

Record some of the processes of using node-media-...

Defining the minimum height of the inline element span

The span tag is often used when making HTML web p...

Summary of web design experience and skills

■ Website theme planning Be careful not to make yo...

Vue uses openlayers to load Tiandi Map and Amap

Table of contents 1. World Map 1. Install openlay...

Solution to the problem that mysql local login cannot use port number to log in

Recently, when I was using Linux to log in locall...

What is jQuery used for? jQuery is actually a js framework

Introduction to jQuery The jQuery library can be ...

SSM implements the mysql database account password ciphertext login function

introduction Our company is engaged in the resear...

Detailed explanation of sql_mode mode example in MySQL

This article describes the sql_mode mode in MySQL...

How to use negative margin technology to achieve average layout in CSS

We usually use float layout to solve the compatib...

JavaScript to achieve full screen page scrolling effect

After I finished reading JavaScript DOM, I had a ...

Detailed explanation of chmod command usage in Linux

chmod Command Syntax This is the correct syntax w...

Solution to the problem of MySQL thread in Opening tables

Problem Description Recently, there was a MySQL5....