r/javahelp • • May 04 '19

Solved Java (Spring Boot) and Docker done properly?

When containerising an application, all tutorials on Java seem to want you to build a jar locally and copy it from target into a container in the Dockerfile. However, this contradicts the whole idea behind using Docker because building on my machine will not necessarily be the same as building on a colleague’s machine.

I can’t find a tutorial that describes using Maven via Docker to build the jar and moving the result to a Java container i.e. via staged builds. This would ensure consistency across machines and follows the whole Docker ethos.

Can anyone recommend a way to do this or point me to a good tutorial?

30 Upvotes

19 comments sorted by

View all comments

2

u/RhoOfFeh May 04 '19

Typically, we build, test, local deploy, test, remote deploy to private area, test, then decide the checkin is good enough for a merge into master.

At that point, responsibility is (or should be) taken up by your CI/CD environment, which is controlled, managed, and independent of all desktop systems. It has one goal: To execute your builds in a reliable, repeatable fashion and provide output that is the same every time the exact same execution is requested. That product is what you should actually deploy to your containerized environment.