Use docker multistage builds for R development and deployment setting
Asked Answered
B

1

9

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 Dockerfile Dokerfile.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 my Dockerfile.deployment, but use the r-base image in the FROM 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.

Brayton answered 7/10, 2019 at 12:13 Comment(0)
U
2

tl;dr: You cannot. In the way you ask, methinks. Maybe you can do it differently.

Longer version:

  • Don't take this as a glib answer.
  • I think it gets to the core of how we package source code
    • from taking source code from source repos
    • or taking binary aggreations, for example as .deb files
    • or taking binary meta-aggreations, here Docker layers
  • You realize that there are Docker layers containing components
  • If I read your request correctly, you desire "reversing" one layer
  • i.e. get the RStudio part out of the RStudio docker
  • I think you can't
  • Fundamentally, the RStudio Docker container just unpacks the .deb they ship
  • So you should reverse your whole stack
  • Start fron r-ver or r-base, add your particular development needs
  • Then add the RStudio .deb as we do in the RStudio container
  • (Legalese: We have explicit permission to redistribute this, I doubt this is transitive)

Hope this helps. Fill in any blanks where I got my assumptions wrong.

Uncleanly answered 14/10, 2019 at 1:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.