使用Docker开发Java EE应用程序

问题描述:

我将添加300点作为赏金

I will add 300 points as bounty

我最近开始仔细观察Docker以及如何使用它来更快地获得团队的新成员,并与开发环境一起运行,以及将新版本的软件发送到生产。

I have recently started to take a closer look at Docker and how I can use it for faster getting new member of the team up and running with the development environment as well as shipping new versions of the software to production.

我有一些关于如何以及在什么阶段将Java EE应用程序添加到容器的问题。就像我看到的那样,有很多种方法。

I have some questions regarding how and at what stage I should add the Java EE application to the container. As I see it there are multiple ways of doing this.

这是Docker之前的典型工作流程(在我的团队中):

This WAS the typical workflow (in my team) before Docker:


  1. 开发人员写代码

  2. 开发人员使用Maven生成代码生成WAR

  3. 开发人员上载WAR在JBoss管理控制台中或使用Maven插件

现在,在Docker来临之后,我有点困惑,如果我应该创建图像我需要并配置它们,以便运行JBoss Wildfly容器时要做的所有操作都是通过Web上的管理控制台部署应用程序。或者我应该每次在Maven中构建应用程序时创建一个新的容器,并在Dockerfile中使用 ADD 命令添加新的容器,然后运行容器,而不会部署到它一旦开始了

Now after Docker came around I am a little confused about if I should create the images that I need and configure them so that all that is left to do when you run the JBoss Wildfly container is to deploy the application through the admin console on the web. Or should I create a new container for each time I build the application in Maven and add it with the ADD command in the Dockerfile and then just run the container without ever deploying to it once it is started?

在生产中我猜最后一个方法是什么呢?纠正我,如果我错了
但在开发中应该怎么做?有没有其他工作流程?

In production I guess the last approach is what it preffered? Correct me if I am wrong. But in development how should it be done? Are there other workflows?

我已经使用Docker与Glassfish广泛使用了很长时间,现在写了一个博客前一段时间此处

I've used Docker with Glassfish extensively, for a long time now and wrote a blog on the subject a while ago here.

它是JavaEE开发的一个很好的工具。

Its a great tool for JavaEE development.

对于您的生产图像,我更愿意将所有内容捆绑在一起,构建静态基本图像并在新的WAR中进行分层。我喜欢使用CI服务器来完成这些工作,并为生产分支机构配置一个配置文件,以便在发布版本中获取基础层,然后发布工件。通常,我们手动部署到生产中,但如果您真的想得到您的喜好,甚至可以通过CI服务器部署到生产环境中并使用代理服务器来确保新的会话获得更新版本。

For your production image I prefer to bundle everything together, building off the static base image and layering in the new WAR. I like to use the CI server to do the work and have a CI configuration for production branches which will grab a base, layer in the release build, and then publish the artifact. Typically we manually deploy into production but if you really want to get fancy you can even automate that with the CI server deploying into a production environment and using proxy servers to ensure new sessions that come it get the updated version.

在开发过程中,我喜欢采取相同的方法,当它来到本地运行任何依赖于容器(例如Arquillian集成测试)之前检查代码。这使得环境尽可能接近生产,我认为在测试时很重要。这是一个很大的原因,我反对像使用嵌入式容器测试但部署到非嵌入式容器的方法。我看到很多情况下,测试将在嵌入式环境中传递,并在生产/非嵌入式环境中失败。

In development I like to take the same approach when it comes time to locally running any that rely on the container (eg. Arquillian integration tests) prior to checking in code. That keeps the environment as close to production as possible which I think is important when it comes to testing. That's one big reason I am against approaches like testing with embedded containers but deploying to non-embedded ones. I've seen plenty of cases where a test will pass in the embedded environment and fail in the production/non-embedded one.

在开发/部署/手测试周期中,在提交代码之前,我认为部署到容器(它是基础映像的一部分)的方法更多在开发商的速度方面具有成本效益。每次你的WAR中的循环与构建。如果您的开发环境使用JRebel或XRebel等工具,您可以在其中轻松部署代码,只需刷新浏览器即可查看更改,这也是一个更好的方法。

During a develop/deploy/hand test cycle, prior to committing code, I think the approach of deploying into a container (which is part of a base image) is more cost effective in terms of speed of that dev. cycle vs. building in your WAR each time. It's also a better approach if your dev environment uses a tool like JRebel or XRebel where you can hot deploy your code and simply refresh your browser to see the changes.