在docker图像中部署WAR文件的正确方法 [英] Correct way to deploy WAR files in docker image

查看:231
本文介绍了在docker图像中部署WAR文件的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是否将战争复制到webapps中?

  FROM jetty:9.2.10 
MAINTAINER Meme@me.com
添加./target/*.war / var / lib / jetty / webapps / ROOT.war

或者我采取爆炸的战争文件:

  FROM jetty:9.2.10 
MAINTAINER Meme@me.com
添加./target/app-0.1 .0.BUILD-SNAPSHOT / var / lib / jetty / webapps / ROOT

通常情况下,密封的战争文件,如果它是一个普通的容器,但是使用docker,这意味着每次进行一个小的更改时都会推送一个10-20MB的文件,而添加爆炸式战争只会推动差异 - .class文件已经改变。 p>

部署爆炸战争而不是战争文件有什么缺点吗?

解决方案

我想知道你如何使用图像。在构建图像时添加20MB文件应该是即时的。在某些情况下,您可能会在部署过程中构建图像,如AWS给您一个Docker文件。



无论如何,我认为这取决于您的部署方式。如果你自己移动图像,我添加一个.war文件和一个爆炸的WAR目录之间看不出很大的区别。我会说为你做的方便。但是,如果您有时从Docker运行应用程序,有时会从.war(可能会错过Docker的某些要点)运行该应用程序,那么您可以一直使用.war。



如果您正在部署如AWS Elastic Beanstalk(某些从存储库中提取映像的内容),它们需要一个Dockerfile或一个Dockerrun.aws.json文件,则将该映像从实际部署中分离出来有一些意义(或者对我来说已经有意义了)。这允许容器保持不变,而更新应用程序可能只是将.jar / .war文件复制到正确的位置(这也可能会错过Docker的一部分)。



我一直在做的是在Docker Hub上创建一个基本映像,然后使用Dockerrun.aws.json文件在我的应用程序中映射。这样一来,AWS不需要构建我的形象,只需拉一下。这样快得多($)。但它使我的应用程序与图像分离,这在某些情况下可能会使部署复杂化。但是,由于我的图像非常稳定,我通常只需将.jar文件,Dockerrun.aws.json文件和shell脚本捆绑到.zip中并将其上传到AWS。很简单我想。



我的Docker文件很简单,我真正需要我的Spring Boot应用程序:

  FROM java:8 
VOLUME / tmp
VOLUME / app
EXPOSE 8080
ENTRYPOINT [sh,/ app / app。 sh]

你可以做类似的事情,并使用-v选项等来映射卷到你的应用程序,它的环境设置等。BTW,这个图像在Docker Hub上可用。


What is the docker way to deploy java projects in a docker container?

Do I copy the war into webapps:

FROM jetty:9.2.10
MAINTAINER Me "me@me.com"
ADD ./target/*.war /var/lib/jetty/webapps/ROOT.war

or do I take the exploded war file:

FROM jetty:9.2.10
MAINTAINER Me "me@me.com"
ADD ./target/app-0.1.0.BUILD-SNAPSHOT /var/lib/jetty/webapps/ROOT

Normally one would deploy the sealed war file if it was a normal container, but with docker, that means pushing a 10-20MB file every time you make a small change whereas adding the exploded war would only push the difference - the .class file that has changed.

Are there any downsides to deploying the exploded war instead of the war file?

解决方案

I wonder how you're using your images. Adding a 20MB file while building an image should almost be instant. Mayb you somehow building images during deployment, like AWS does when you give it a Dockerfile.

In any case, I think it depends on how you're deploying. If you're moving the images around yourself, I don't see a lot of difference between ADDing a .war file and an exploded WAR directory. I would say do what's convenient for you. However, if you sometimes run the app from Docker and sometimes from a .war (which might miss some of the point of Docker), you might as well use the .war all the time.

If you're deploying to something like AWS Elastic Beanstalk (something that pulls the image from a repository), which wants either a Dockerfile or a Dockerrun.aws.json file, then separating the image from what you actually deploy makes some sense (or it has made sense to me so far). This allows the container to stay the same, while updating your app can be just copying a .jar/.war file to the right location (which also might miss part of the point of Docker ;).

What I've been doing is creating a base image on Docker Hub and then using the Dockerrun.aws.json file to map in my app. That way, AWS does not need to build my image, just pull it. That's much faster and less costly ($). But it does separate my app from the image, which might complicate deployment in some circumstances. However, because my image is so stable, I generally just bundle a .jar file, a Dockerrun.aws.json file and a shell script into a .zip and upload it to AWS. Pretty easy I think.

My Dockerfile is pretty simple and really all I need for my Spring Boot app:

FROM java:8
VOLUME /tmp
VOLUME /app
EXPOSE 8080
ENTRYPOINT ["sh","/app/app.sh"]

You could do something similar and use the -v option, etc., to map volumes to your app, it's environment settings, etc. BTW, this image is available on Docker Hub.

这篇关于在docker图像中部署WAR文件的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆