Bird
0
0

You want to create a multi-stage Dockerfile for your Flask app to reduce image size. Which approach is correct?

hard📝 Application Q8 of 15
Flask - Deployment
You want to create a multi-stage Dockerfile for your Flask app to reduce image size. Which approach is correct?
AUse multiple FROM lines but copy everything between stages
BInstall dependencies in the final stage only, skipping build stage
CUse one stage to install dependencies and build, then copy only necessary files to a smaller final stage
DBuild the app outside Docker and copy all files into a single stage
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-stage build purpose

    Multi-stage builds use one stage to install and build dependencies, then copy only needed artifacts to a smaller final image to reduce size.
  2. Step 2: Evaluate options

    Installing dependencies only in final stage misses build tools. Copying everything defeats size reduction. Building outside Docker loses container benefits.
  3. Final Answer:

    Use one stage to install dependencies and build, then copy only necessary files to a smaller final stage -> Option C
  4. Quick Check:

    Multi-stage builds reduce size by selective copying [OK]
Quick Trick: Multi-stage builds copy only needed files to final image [OK]
Common Mistakes:
MISTAKES
  • Copying all files between stages defeats purpose
  • Skipping dependency install in build stage
  • Building app outside Docker loses container benefits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes