Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two docker images

I'm hoping to use docker to set up some bioinformatic analysis.

I have found two docker images that I would like to use:

  1. jupyter/datascience-notebook
  2. bioconductor/devel_base

I have been successful in running each of these images independently, however I don't know how to merge them together.

Is merging two docker containers possible? Or do you start with one, and then manually install the features of the other?

like image 222
kmace Avatar asked Sep 26 '16 20:09

kmace


People also ask

Can we merge two Docker images?

Docker doesn't do merges of the images, but there isn't anything stopping you combining the dockerfiles if available, and rolling into them into a fat image which you'd need to build.

How do I merge two Dockers?

On your machine, use docker pull to download the images from Docker Hub. Then, use docker history to get the commands that were used to build them. Then, open these two files. You can then see the command stack of each image.

Can I have two Dockerfiles?

As Kingsley Uchnor said, you can have multiple Dockerfile , one per directory, which represent something you want to build.

How do I use multiple images in Dockerfile?

We can use multiple FROM commands combined with AS commands in our Dockerfile where the last FROM command will actually build the image. All the FROM commands before that, will lead to the creation of intermediate images which are cached regularly.


2 Answers

You can't just merge the images. You have to recreate your own based on what was in each of the images you want. You can download both images and re-create the Docker files for each like this:

docker history --no-trunc=true image1 > image1-dockerfile
docker history --no-trunc=true image2 > image2-dockerfile

Substitute the image1 and image2 with the images you want to see the history for. After this you can use those dockerfiles to build your own image that is the combination of the two.

The fly in the ointment here is that any ADD or COPY commands will not reveal what was copied because you don't have access to the local file system from which the original images were created. With any luck that won't be necessary or you can get any missing bits from the images themselves.

like image 126
Chris Townsend Avatar answered Oct 19 '22 00:10

Chris Townsend


If there are specific files or directories that you want to cherry-pick from the one of the two images, you can create a new Dockerfile that builds FROM one of them and copy over specific paths from the other using COPY's --from option. For example:

FROM bioconductor/devel_base
COPY --from=jupyter/datascience-notebook /path/to/something-you-want /path

However, a quick investigation of those images shows that in this specific case there isn't a lot that can easily be cherry picked.

Alternatively, you can just look at the original Dockerfiles and combine them yourself:

  • https://github.com/jupyter/docker-stacks/blob/master/base-notebook/Dockerfile
  • https://github.com/Bioconductor/bioc_docker/blob/master/out/devel_base/Dockerfile

Fortunately they are both based one APT-based distros: Ubuntu and Debian. So most of the apt-get install commands should work fine if you pick either base image.

like image 1
Yogarine Avatar answered Oct 19 '22 01:10

Yogarine