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

How to set PATH environment variable in Linux system (3 methods)

1. In Windows system, many software installations...

10 Website Usability Tips Everyone Should Know

Let’s not waste any more time and get straight to...

Detailed steps for running springboot project in Linux Docker

Introduction: The configuration of Docker running...

Detailed explanation of the code for implementing linear gradients with CSS3

Preface The gradient of the old version of the br...

JavaScript object built-in objects, value types and reference types explained

Table of contents Object Object Definition Iterat...

SQL left join and right join principle and example analysis

There are two tables, and the records in table A ...

Solve the black screen problem after VMware installs Linux system and starts

1. Installation environment 1. HUAWEI mate x cpu ...

A brief introduction to MySQL functions

Table of contents 1. Mathematical functions 2. St...

How to enhance Linux and Unix server security

Network security is a very important topic, and t...

Nofollow makes the links in comments and messages really work

Comments and messages were originally a great way...

Detailed steps to install MYSQL8.0 on CentOS7.6

1. Generally, mariadb is installed by default in ...

Eight common SQL usage examples in MySQL

Preface MySQL continued to maintain its strong gr...

Mysql delete data and data table method example

It is very easy to delete data and tables in MySQ...