Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To include maven in dockerfile or not?

I have this working simple Dockerfile.

FROM openjdk:8-jdk-alpine
WORKDIR /data
COPY target/*.jar, myapp.jar
ENTRYPOINT ["java","-jar",myapp.jar]

I build my jar using maven either locally or in a pipeline then use that .jar here. I've seen many examples installing maven in the Dockerfile instead of doing the build before. Doesn't that just make the image larger? Is there a benefit of doing that?

like image 477
user1807815 Avatar asked Jan 20 '26 22:01

user1807815


1 Answers

Usually I have a CI/CD server which I use for building my jar file and then I generate a docker image using it. Build a jar consumes resources and doing it when you're running your docker container can take longer depending on your configuration. In a normal CI/CD strategy, build and deploy are different steps. I also believe your docker image should be as lean as possible.

like image 175
Rodrigo Silva Avatar answered Jan 23 '26 12:01

Rodrigo Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!