By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Multi-stage builds separate build and runtime dependencies by using multiple Dockerfiles to create a final image. Use the --build-arg flag to pass arguments to the build stage.
--build-arg
mkdir multi-stage-build && cd multi-stage-build
Dockerfile
FROM python:3.9-slim AS build-stage
RUN pip install -r requirements.txt
COPY . /app
RUN python -m build
Dockerfile.runtime
FROM python:3.9-slim
COPY --from=build-stage /app/dist /app
CMD ["python", "app.py"]
docker build -t myapp -f Dockerfile.runtime .
docker run -p 8000:8000 myapp
docker system prune -f
-t
-f
docker build -t myapp -f Dockerfile.runtime --build-arg VCS_REF=$(git rev-parse --short HEAD) .
VCS_REF
COPY --from
COPY --from not found
docker --version
--build-arg not found
FROM
FROM not found
docker run -it --rm myapp /bin/bash
RUN
CMD
docker build
docker run
docker system prune
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.