2

I am creating a Docker image that needs to contain both:

  1. Ex: Company Foo's image of Jenkins support functions: docker.foo.com/jenkins-build:latest
  2. cypress/included:4.12.1

This image will be labeled docker.foo.com/cypress-build

Dockerfile for this image is scripted as follows:

# Image containing company Foo's Jenkins build
FROM docker.foo.com/jenkins-build:latest

# Main image that include all operating system dependencies necessary to run Cypress,
# but NOT the test runner itself.
FROM cypress/included:4.12.1

Is this Dockerfile valid in scripting with multiple FROM?

If not, then what must be done to correct it?

Thank you, much appreciate any feedback!

Jeff
  • 1,917
  • 1
  • 25
  • 43

1 Answers1

4

Yes multiple FROM lines are allowed. This is part of the multi-stage build implementation. Each FROM line starts a new stage as a new image, and that image only includes the filesystem layers and configuration of that FROM line. The tagged image at the end is either the last stage to be built, or the targeted stage if you direct the build to tag a specific stage.

Note that multi-stage is not some kind of multiple inheritance or image merging process. That doesn't exist, and there's no trivial way to implement that. Multi-stage builds are designed to allow the build environment to be moved into the docker environment, without including compilers and other build tooling in the distributed image. It does this by allowing files to be copied between stages with the COPY --from syntax.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • So expecting this `Dockerfile` with the 2 FROMs to perform a merge into a single image is a wrong expectation, correct? – Jeff Aug 12 '20 at 01:14
  • @JeffTanner correct. That doesn't exist, and there's no trivial way to implement that. – BMitch Aug 12 '20 at 01:19
  • @JeffTanner Unfortunately Docker does not treat image layers the way Git treats commits. – Konrad Botor Aug 12 '20 at 13:38
  • 2
    @KonradBotor Trying to merge two docker images (Linux filesystems) is similar to trying to automatically merge two git repos, for completely different projects, that also have conflicting filenames. At least one, and probably both, of those filesystem trees would be broken in the process. – BMitch Aug 12 '20 at 13:41
  • 1
    @BMitch Yes, I imagine merging two Docker images would only be possible if they have the same base image and even then you'd probably have to manually resolve merge conflicts. – Konrad Botor Aug 12 '20 at 13:44