Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start docker build at a certain stage in a multi-stage build?

Tags:

docker

Our application take a very long time to compile. Any change to the Dockerfile triggers a full-recomplile (which takes a very long time) The Dockerfile is a muli-stage build. I'm trying to work on the second stage. Is there any way to tell docker build to begin at the second stage?

FROM debian:latest AS builder

# 10-20 mins worth of stuff here

FROM alpine:latest AS runner
WORKDIR /

COPY --from=builder /work/myapp.zip .
RUN unzip myapp.zip -d /myapp

# and more stuff that I'm working on here

Is there some way to do docker build --begin-with runner?

like image 741
101010 Avatar asked Oct 27 '25 10:10

101010


1 Answers

You can use --target [STAGE-NAME] from the build command according to the documentation, e.g

docker build -f Dockerfile --target runner -t imagename:1.0 .

This will compile just the runner stage

like image 155
DanielT Avatar answered Oct 29 '25 23:10

DanielT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!