Questions tagged [docker-multi-stage-build]

135 questions
37
votes
2 answers

Share variable in multi-stage Dockerfile: ARG before FROM not substituted

I'm writing a multi-stage Dockerfile for the darshan utils: ARG DARSHAN_VER=3.1.6 FROM fedora:29 as build RUN dnf install -y \ gcc \ make \ bzip2 bzip2-devel zlib zlib-devel RUN curl -O…
Alberto Chiusole
  • 1,091
  • 12
  • 23
25
votes
3 answers

How do I reduce a python (docker) image size using a multi-stage build?

I am looking for a way to create multistage builds with python and Dockerfile: For example, using the following images: 1st image: install all compile-time requirements, and install all needed python modules 2nd image: copy all compiled/built…
gCoh
  • 1,987
  • 1
  • 17
  • 36
15
votes
1 answer

Use multi-stage docker files for outputting multiple images

A new docker feature is to do something like this in the dockerfile FROM php7-fpm as build ... FROM build AS test ... FROM test AS staging ... As far as i know, the last FROM statement marks the final output image. How is it possible to have two…
Jim Panse
  • 1,562
  • 9
  • 23
13
votes
1 answer

How do I copy variables between stages of multi stage Docker build?

I've only seen examples of using COPY to copy files between stages of a multi stage Dockerfile, but is there a way to simply copy an ENV variable? My use case is to start out with a git image to just to get the commit hash that will be part of the…
Viktor Hedefalk
  • 2,868
  • 2
  • 27
  • 44
11
votes
1 answer

Docker Multi-Stage: How to split up into multiple Dockerfiles

I am successfully using Docker's Multi-Stage feature to build some code and then copy the resulting artifacts into a final image. Is it possible to split this one big-ish Dockerfile into multiple files? I would like to improve the readability of the…
Unapiedra
  • 12,344
  • 10
  • 55
  • 80
7
votes
3 answers

Tag multiple targets during one docker build

I have a Dockerfile with multiple targets. For example: FROM x as frontend ... FROM y as backend ... FROM z as runtime ... COPY --from=frontend ... COPY --from=backend ... In order to build and tag the final image, I use: docker build -t…
fbjorn
  • 367
  • 3
  • 18
7
votes
1 answer

Docker multistage: how to COPY built files between stages?

I'm beginner with Docker, and I'm trying to build an image in two stages, as explained here: https://docs.docker.com/develop/develop-images/multistage-build/ You can selectively copy artifacts from one stage to another Looking at the examples…
bli
  • 5,749
  • 2
  • 34
  • 76
7
votes
1 answer

Docker Multi-stage Builds and Test results - How to get them?

Apparently, all articles I found about multi-stage builds cover the happy path. But how to get the test results (e.g. unit or acceptance tests) out of a builder-container when something fails?
Arman
  • 762
  • 2
  • 7
  • 29
6
votes
2 answers

Dummy downsize after Docker build

Using multi-stage builds, I want to downsize an image at the end of Dockerfile, something like this: FROM ubuntu AS ubuntu_build RUN # do a lot of build things FROM alpine COPY --from=ubuntu_build /app /app ENTRYPOINT whatever the alpine image…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
6
votes
1 answer

Is it possible to to run a target build stage in docker without running all the previous build stages

I am newbie to docker and trying to explore multistage build. I want to run a specific stage on docker docker build -t build-stage-tag --target build I expect it to run the following stages dependencies --> compile --> build and skip the test. But…
Gayatri
  • 193
  • 1
  • 2
  • 15
6
votes
3 answers

Import Dockerfile from different local directory via FROM

I want to create a multistage build process whereas each of the docker files are nested inside their own directories locally with their corresponding dependencies that are ADDed in for each Docker file. Is there a way to import a Docker file from a…
Baily
  • 753
  • 10
  • 29
6
votes
2 answers

How can I cache Maven dependencies and plugins in a Docker Multi Stage Build Layer?

I want to cache Maven dependencies in a layer of the build stage of my Docker Multi Stage Build. My Dockerfile looks as follows: FROM maven:3-jdk-8 as mvnbuild RUN mkdir -p /opt/workspace WORKDIR /opt/workspace COPY pom.xml . RUN mvn -B -s…
Trastle
  • 4,905
  • 5
  • 23
  • 19
5
votes
1 answer

How to COPY library files between stages of a multi-stage Docker build while preserving symlinks?

I have a Dockerfile which is split into a two-stage multi-stage docker build. The first stage generates a basic gcc build environment in which a number of C and C++ library are compiled. The second stage uses the COPY --from= command to copy the…
TafT
  • 1,786
  • 2
  • 22
  • 41
5
votes
3 answers

Docker multi-stage-build with different project

We are working with two project at the moment: 1 C++ based project 2 Nodejs based project These two projectes are separated which means they have different codebase(git repoitory) and working directory. C++ project will produce a node binding file…
hguser
  • 31,173
  • 49
  • 145
  • 269
5
votes
1 answer

Docker: How to use multistage images after build finishes

Scenario Multistage builds combine multiple Dockerfile sections into a single one Intermediary and final stages can copy files from the upper stages Final stage is suggested to have only the binaries needed. With those in mind, I'd like to build…
Marcello de Sales
  • 17,280
  • 12
  • 60
  • 72
1
2 3
8 9