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 Copy from container to host 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:
|
<<: Mysql 5.7.18 Using MySQL proxies_priv to implement similar user group management
>>: Detailed explanation of MySQL master-slave replication process
1. In Windows system, many software installations...
Let’s not waste any more time and get straight to...
Introduction: The configuration of Docker running...
Preface The gradient of the old version of the br...
1. Install MySQL database ① Download and unzip an...
Table of contents Object Object Definition Iterat...
There are two tables, and the records in table A ...
1. Installation environment 1. HUAWEI mate x cpu ...
Table of contents 1. Mathematical functions 2. St...
Network security is a very important topic, and t...
Comments and messages were originally a great way...
1. Background Recently, some friends encountered ...
1. Generally, mariadb is installed by default in ...
Preface MySQL continued to maintain its strong gr...
It is very easy to delete data and tables in MySQ...