'How to start docker build at a certain stage in a multi-stage build?
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
?
Solution 1:[1]
Docker build run from the last changed stage..
See here might help you rebuild docker image from specific step
Solution 2:[2]
Actually the Docker build cache should handle such situations automatically. However this implementation has it's limits. It may not give you exactly what you want, but may be close.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | eyal RnD |
Solution 2 | Hiran Chaudhuri |
Solution 3 | DanielT |