Questions tagged [docker-multi-stage-build]
221 questions
127
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
- 2,204
- 2
- 16
- 26
43
votes
4 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
- 2,719
- 1
- 22
- 46
32
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
- 2,220
- 12
- 34
28
votes
3 answers
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
- 3,572
- 3
- 33
- 48
23
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
- 7,549
- 7
- 48
- 94
21
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
- 15,037
- 12
- 64
- 93
17
votes
4 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
- 722
- 12
- 27
15
votes
4 answers
How to pnpm and Next.js in multi-stage docker file?
The official Next.js Dockerfile example does not work if I switch npm to pnpm.
How should I modify that Dockerfile so that it remains multi-stage, but also uses pnpm instead of npm?

Meglio
- 1,646
- 2
- 17
- 33
14
votes
4 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
- 1,290
- 2
- 14
- 35
13
votes
6 answers
docker multi-stage build Go image - x509: certificate signed by unknown authority
I try to build go images in private corp network use docker-multi-stage-build:
FROM golang:latest as builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN GO111MODULE="on" CGO_ENABLED=0 GOOS=linux go build -o main…

kozmo
- 4,024
- 3
- 30
- 48
13
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
- 5,155
- 6
- 26
- 20
11
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
- 453
- 1
- 6
- 18
9
votes
1 answer
Dockerfile not executing second stage
I'm getting some weird behavior from Docker and I can't find it mentioned anywhere. It is skipping stages seemingly at random, even with multi-stage Dockerfiles that I've simply copy-pasted from forums around the net.
My dockerfile is:
FROM alpine…

Eduard G
- 443
- 5
- 21
9
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
- 2,764
- 6
- 33
- 51
9
votes
2 answers
Why does the ASP.NET Core Multi-Stage Dockerfile use 4 Stages
This is the default multi-stage Dockerfile when you click on 'Add Docker Support' in Visual Studio on an ASP.NET Core site.
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY…

Muhammad Rehan Saeed
- 35,627
- 39
- 202
- 311