简体   繁体   English

在docker容器中重新部署spring-boot应用程序?

[英]Redeploy spring-boot application in docker container?

I have a spring-boot project and I want automatically redeploy my jar in the container. 我有一个spring-boot项目,我想在容器中自动重新部署我的jar。 How to do it correctly? 怎么做正确? So far, all I see is this way. 到目前为止,我所看到的只是这样。 It's the right way? 这是正确的方式?

# cd /home/jdev; 
# sudo docker stop ca_spring_boot;
# sudo docker rm ca_spring_boot;  
# sudo docker rmi ca_app_image; 
# sudo docker build -t ca_app_image .;
# sudo docker run -d -p 8888:8080 --name ca_spring_boot ca_app_image

And my Dockerfile 还有我的Dockerfile

FROM java:8
VOLUME /tmp
EXPOSE 8080
ADD docker-storage/jenkins/workspace/CA/build/libs/ca-1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container","-jar","/app.jar"]

Thanks. 谢谢。

You could mount a volume and put your app.jar in there. 你可以装载一个卷并将你的app.jar放在那里。 So you do not need to rebuild the image, you just restart the container. 因此,您无需重建映像,只需重新启动容器即可。

Dockerfile Dockerfile

FROM java:8
ENTRYPOINT [ "sh", "-c", "java -jar /mnt/app.jar" ]

Put your app.jar in /docker/spring/ 把你的app.jar放在/ docker / spring /

Build and run: 构建并运行:

docker build -t spring_test .
docker run -d -v /docker/spring/:/mnt -p 12384:8080 --name spring_test_running spring_test

If you update your spring application you just do: 如果您更新Spring应用程序,您只需:

docker restart spring_test_running

The previous answer is good. 以前的答案很好。 But there is need to restart container every time when you want to test your code. 但是每次要测试代码时都需要重新启动容器。 But we can avoid this problem. 但我们可以避免这个问题。 Just use Spring dev tool And mount destination directory as described above. 只需使用Spring开发工具和安装目标目录,如上所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring-boot docker容器中的应用无法连接mongodb docker容器 - Spring-boot application in docker container is unable to connect to mongodb docker container Spring-boot应用程序无法在docker内启动时启动 - Spring-boot application won't boot at startup inside docker 为什么是 ! 在docker上的spring-boot应用程序的属性文件路径中? - Why is ! in the properties file path in spring-boot application on the docker? 使用docker和kubernetes部署的Spring-boot微服务应用程序:服务无法通信 - Spring-boot microservice application deployed with docker and kubernetes: Services not communicating 在 docker 中调试 spring-boot - debug spring-boot in docker 无法从 postman 向我的 docker spring-boot 容器发送请求 - Can't send request from postman to my docker spring-boot container 如何从docker容器内的java / spring-boot项目运行python脚本(并接收输出)? - How to run python script (and receive output) from java/spring-boot project which is inside a docker container? 将现有的Spring应用程序转换为Spring-Boot - Convert existing Spring application to Spring-Boot spring-boot无法在docker中启动 - spring-boot cannot start in docker 带有underwow servlet容器的春季启动应用程序中的“没有共同的密码套件”错误 - “no cipher suites in common” error in spring-boot application with undertow servlet container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM