Problem
- For development, I want to use a Docker image with the RStudio IDE, which relatively heavy. I also need many packages for my project, so I create my own docker file that has the above referenced image in the
FROM
statement. Let's call this new DockerfileDokerfile.development
. - For deployment, I want to use a base R image without IDE and as few dependencies as required for deployment, with the identical setup-up as in the development, but without an IDE, other development tools and dependencies required to run tests. Let us call the Dockerfile for deplyoment
Dockerfile.deployment
.
Candidate solutions
So now I see the following options to create these two images:
- One inelegant way to do that is to c/p everything from
Dokerfile.development
into myDockerfile.deployment
, but use the r-base image in theFROM
statement. Drawback: I always need to keep multiple Dockerfiles up to date. If I add another image for testing, I have 3 Dockerfiles with 99% overlap. Another way is to first create a
Dockerfile.deployment
with all requirements for the deployment. Then, the development image is built on top of the deployment image.Dockerfile.development
is more or less c/p the installation instructions in the Dockerfile for the RStudio image to add RStudio to the deployment image, but with the deplyoment image as base image. Drawback: I would not understand the code in my own Dockerfiles anymore.Use multistage builds that make it easy to extract the built executables (or actually anything) from one image and use it into another one, without having to copy all the dependencies that were needed to build the executable. So my idea would be to extract the relevant files from the RStudio image into a new image that would be my deployment image.
I think the last option is preferred because it's the most modular solution and has the least duplication in the Dockerfiles and the lowest maintenance burden.
Question
my narrow question is: Is there a (single) executable I could extract from the build RStudio image and put it on top of my deployment image?
my more open question is: How are people handling the situation where the development image is the deployment image plus some other tools that are available as standalone images and they want to avoid duplication as shown in the two first solutions under Candidate solutions.