問題描述
在docker容器中部署java項目的docker方式是什么?
What is the docker way to deploy java projects in a docker container?
我是否將戰爭復制到 webapps 中:
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
如果它是一個普通容器,通常會部署密封的戰爭文件,但對于 docker,這意味著每次你做一個小的改變時都會推送一個 10-20MB 的文件,而添加爆炸的戰爭只會推動差異 - .已更改的類文件.
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?
推薦答案
我想知道您是如何使用圖像的.在構建圖像時添加 20MB 文件幾乎應該是即時的.也許你在部署過程中以某種方式構建圖像,就像 AWS 在你給它一個 Dockerfile 時所做的那樣.
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.
無論如何,我認為這取決于您的部署方式.如果您在自己周圍移動圖像,我認為添加 .war 文件和分解的 WAR 目錄之間沒有太大區別.我會說做你方便的事.但是,如果您有時從 Docker 運行應用程序,有時從 .war 運行應用程序(這可能會忽略 Docker 的某些要點),那么您不妨一直使用 .war.
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.
如果您要部署到諸如 AWS Elastic Beanstalk(從存儲庫中提取圖像的東西)之類的東西,它需要 Dockerfile 或 Dockerrun.aws.json 文件,那么將圖像與您實際部署的內容分開會產生一些影響有意義(或者到目前為止對我來說是有意義的).這允許容器保持不變,而更新您的應用程序只需將 .jar/.war 文件復制到正確的位置(這也可能會錯過 Docker 的部分要點;).
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 ;).
我一直在做的是在 Docker Hub 上創建一個基礎映像,然后使用 Dockerrun.aws.json 文件在我的應用程序中進行映射.這樣,AWS 不需要構建我的鏡像,只需拉取它.這更快,成本更低($).但它確實將我的應用程序與圖像分開,這在某些情況下可能會使部署復雜化.但是,因為我的鏡像非常穩定,所以我通常只是將一個 .jar 文件、一個 Dockerrun.aws.json 文件和一個 shell 腳本打包成一個 .zip 并上傳到 AWS.我覺得很簡單.
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.
我的 Dockerfile 非常簡單,是我的 Spring Boot 應用程序所需要的全部內容:
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"]
您可以執行類似的操作并使用 -v 選項等將卷映射到您的應用程序、環境設置等.順便說一句,這個鏡像 在 Docker Hub 上可用.
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 文件的正確方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!