Dockerfile: Are multiple FROM (s) allowed?

Viewed 893

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!

1 Answers

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.

Related