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

Docker deploy war package project

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Deployment principle

To deploy a war project using Docker, you must use a container, so we use a tomcact container. In fact, the war package is thrown into the webapps directory of tomcat, and the war package is automatically decompressed when tomcat starts.

Deployment method

1. Install the image of the tomcat container in Docker, and then drop the war package into the webapps under the tomcat image. But if tomcat is closed, the packages under its webapps will disappear.

two。 To mount the tomcat container, you can still install the image of the war container, but do not throw the war package into the webapps under tomcat. Create an external folder directly and associate the external folder with the wabapps. In this way, you can throw the war into the new folder, and the webapps of tomcat can also read the war package. This is called mount.

Operating environment:

1. Firewall turned off, security

two。 The docker container is already installed

3. Host centos 7 system

4. The project has been packed with war package.

5.tomcat related configuration files are ready

Deployment process 1. Search for tomcat images

Docker search tomcat

two。 Download tomcat image

Docker pull tomcat

3. View Mirror

Docker images

4. Start the container

Docker run-d-p 8088 8080 tomcat &

If it is found that the web page cannot be accessed during the pit removal process, it will return 404.

Reason: there is a problem with the downloaded tomcat image. The webapps folder in the container is empty, so it cannot be accessed.

Try the following steps:

Docker ps

Docker exec-it 8126cd702e4b / bin/bash # enters the container

Rm-rf webapps # Delete empty file webapps

Mv webapps.dist webapps # replace the webapps file

Web page verification

The first way to deploy the war package project is to copy the war package into the container. Copy the war package and configuration file to the host

two。 Copy it into the docker container

Docker cp admin.war 834273c974f2:/usr/local/tomcat/webapps

Docker cp context.xml 834273c974f2:/usr/local/tomcat/conf

3. Restart the container

Docker restart 2d9a7cdacc8b

4. Web page validation:

The second method: Mount the shared directory 1. Create a mount directory

Mkdir / root/warPackage

two。 Upload the war package to / root/warPackage3. Mounting

Docker run-it-v / root/warPackage/:/usr/local/tomcat/webapps/ / bin/bash

(- v (mount) virtual machine directory container directory)

4. View mount

Host view:

Cd / root/warPackage

Ls

View in the container:

Docker exec-it ecf6b6baa517 / bin/bash

Cd webapps

Ls

If the web page is not accessible at this time, try the following solution:

Docker exec-it ecf6b6baa517 / bin/bash # enters the container

Cd webapps

Mv webapps webapps1 # is renamed. The container is running and cannot be deleted. You can only change the name.

Mv webapps.dist webapps # replace webapps file

Exit # exit Container

Docker run-it-v / root/warPackage/:/usr/local/tomcat/webapps/ / bin/bash

# remount

Note:

1. If the newly downloaded tomcat image cannot be accessed when started, you should refer to the pit removal process. If it is normal, it can be ignored.

two。 The path of the mounted war package can be customized. If you cannot access it, you can also refer to the above method.

3. The two methods introduced here can be used on your own according to the needs of the company.

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

Servers

Wechat

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

12
Report