Your Python Docker image is 1.1 GB. How do you shrink it?
IntermediateScenarioTesting, CI/CD, packaging & services
Answer
Situation read → Full base image, build tools, caches and tests shipped to production.
What I'd do →
python:3.12-sliminstead ofpython:3.12; avoid Alpine unless all deps have musllinux wheels.- Multi-stage: build a wheel (or venv) in a builder stage with compilers, copy only the result to the runtime stage.
pip install --no-cache-dir;.dockerignorefor.git,.venv, tests, caches.- Install only runtime deps, not
[dev]. - Measure with
docker historyordive.
Why → Most size is the base and build toolchain; multi-stage removes both.
Interview tip → Explain why Alpine can make Python images slower to build and sometimes bigger.
More on Testing, CI/CD, packaging & services
You join a team whose Python automation repo has no tests. Where do you start?BeginnerYour pytest suite takes 12 minutes. How do you speed it up?IntermediateA test passes locally but fails in CI only when run with the rest of the suite. What do you suspect?IntermediateYou want a reusable CI pipeline for 15 Python tool repos. What goes in it?IntermediateYou want to distribute an internal CLI to 200 engineers. What are your options?IntermediateA Flask app runs with `app.run()` in production and falls over under load. What do you change?Beginner