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

Java-war-jar-docker

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1 add and modify the configuration file add the config directory in the application root directory, and then copy the Tomcat Server.xml configuration file to that directory. Then modify the configuration file according to your own needs.

--

2 because I am used to deploying the application to the Tomcat root directory, I need to modify the Tomcat configuration file. It is not convenient to modify the configuration file directly in the Docker container, so create a new configuration file to replace the configuration file in the container. You can skip this step if you use the default profile. Write Dockerfile files-war package method

Add the Dockerfile file to the root directory of the application and write the following content: # pull tomcat image FROM tomcat:8# delete tomcat access home page RUN rm-rf / usr/local/tomcat/webapps/*#war package put in tomcatADD / target/agent-app.war / usr/local/tomcat/webapps/ROOT.war# modify tomcat access port, port '8888'ADD server.xml / usr/local/tomcat/conf/server.xml# run tomcatCMD ["catalina.sh", "run"]

Dockerfile-jar packet mode

FROM java:8EXPOSE 7800VOLUME / tmpENV TZ=Asia/ShanghaiRUN ln-snf / usr/share/zoneinfo/$TZ / etc/localtime & & echo $TZ > / etc/timezoneADD goods-cloud-youzan.jar / app.jarRUN bash-c 'touch / app.jar'ENTRYPOINT ["java", "- Xmx1024m", "- jar", "/ app.jar"]

Add a .dockerkeeper file under the root of the application. This file is similar to .gitignore and is used to avoid adding certain files to the context in which the Docker image is created. Add directories and files other than the config directory:

Src/ .idea / target/ can add the config directory and Dockerfile to another directory to avoid the .dockerboards file

Write docker-compose.yml files

Because your project uses Mysql and Redis, you need to run multiple service containers. So Docker Compose is used to manage these services.

Version: "3306" services:mysql:image: mysqlexpose:-"3306" # Mysql service port environment:-MYSQL_ROOT_PASSWORD=123456 # Mysql root user password redis:image: redis:alpineexpose:-"6379" forus:build: .links:-mysql-redisenvironment:-spring.profiles.active=test # activate Spring's Profile-JPDA_ADDRESS=0.0.0.0:8000 # remote debugging site Address volumes: -. / target/forus/:/usr/local/tomcat/webapps/forus/expose:-"8080" ports:-"8080 ports" # Application Port Mapping-"8000 ports 8000" # remote debugging Port Mapping

Run / debug

Running

1. Run the command `project: exploded` under the root directory of the application to compile the project. two。 Run the `image up` command to build the image and run the corresponding service. 3. Open `localhost: 8080` in the browser to access the application. 4. Run the `service down` command under the root directory of the application to stop the service and delete related containers and images.

Debug

Connect to `localhost:8000' by remote debugging to debug.

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