fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.87k stars 642 forks source link

Multiple docker images to one image #1320

Open gouravbansal11 opened 4 years ago

gouravbansal11 commented 4 years ago

Description

I wanted to merge 2 images and add my application to these images and create the final one. I tried to find any example but I didn't get. is it supported by this plugin? Could you please help me with an example.

rohanKanojia commented 4 years ago

@gouravbansal11 : Could you please elaborate your use case? What do you mean by merging two images? Not 100% sure but I think maybe you're looking for Dockerfile

gouravbansal11 commented 4 years ago

I have one base image which I want to use in my application. Apart from that, I have another image that contains scripts. In my final image, I want resources from a base image as well as resources from a scripts image.

rhuss commented 4 years ago

With Docker you can only easily use inheritance, not composition. So you need to build up a inheritance chaing: base -> script-image -> final-image

wrosenuance commented 4 years ago

You can use a multi-stage build to achieve this.

If you have published your base image as my-co/base:latest and your scripts image as my-co/scripts:latest and you are writing the Dockerfile for my-co/app:latest, you could write:

FROM my-co/base:latest

COPY --from=my-co/scripts:latest /scripts /my-co/scripts

RUN echo "Some other task"

Check the Docker documentation for multi-stage builds, particularly under Use an external image as a "stage".

bvsvas commented 3 years ago

How to use multi-stage build in pom.xml using docker-maven-plugin?

rhuss commented 3 years ago

You can leverage the Dockerfile mode as described in the documentation.