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

How to package and deploy jar package in docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Docker how to package deployment jar package, for this problem, this article details the corresponding analysis and solution, hoping to help more small partners who want to solve this problem to find a simpler and easier way.

1. vim New Dockerfile

FROM java:8MAINTAINER lyjADD thedatamanager-authserver-0.0.1-SNAPSHOT.jar /authserver.jarENTRYPOINT ["sh","-c","java -jar /authserver.jar"]

2. Upload jar package

docker build -t authlyj .

4. Check whether the packaging is successful

[root@ambari-01 lyjJars]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEauthserver-lyj2 latest 4f5c9cf1c6fb 4 hours ago 683MB

5. start

docker run -d -p 8889:7104 --name lyjtest authlyj

docker run command contains docker create and docker start commands, followed by the start and stop of the container

docker start lyjtest and docker stop lyjtest

Start can no longer specify instructions to run at container startup, because docker can only have one foreground process.

6. View logs and startup status

docker ps -a //View containers launched

docker logs -f -t --tail 10 lyjtest //View startup logs

docker stop lyjtest //stop docker container

docker rm id/name //Delete container

docker rmi imageID //delete image

This means the docker container will automatically restart after stopping or server startup--restart=always

7. The docker attach command allows you to view real-time output information

The official documentation says that CTRL-C can be used to detect after attach, but in fact after my test, if the container is currently running bash, CTRL-C is naturally the input of the current line, there is no exit; if the container is currently running in the foreground, such as the output of nginx access.log log, CTRL-C will not only cause the container to exit, but also stop. This isn't what we want, detach means to detach from the container terminal, but the container is still running. Fortunately, attach can be accompanied by--sig-proxy=false to ensure that CTRL-D or CTRL-C does not close the container.

[root@ambari-01 docker]# docker attach --sig-proxy=false lyjtest2021-01-05 15:07:19.007 INFO 7 --- [nio-7104-exec-2] o.a.c.c.C. [Tomcat]. [localhost]. [/] : Initializing Spring DispatcherServlet 'dispatcherServlet'2021-01-05 15:07:19.008 INFO 7 --- [nio-7104-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'2021-01-05 15:07:19.026 INFO 7 --- [nio-7104-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 18 ms

8. docker package import to another server

docker save -o lyjtest.tar REPOSITORY //package

docker load

docker images //check if import succeeded

About docker how to package and deploy jar package questions to share here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

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