Why do my Docker containers have to include a full OS for a simple Python app?

February 17, 2026 5 answers
Asked by delta formation
I'm puzzled about why my Docker container for a Flask application pulls in over 200MB of Ubuntu. The only things my Python service really needs are the runtime and some libraries, not an entire OS with systemd and package managers. Moreover, my security scans come back with around 150 vulnerabilities in packages that we don't need and can't remove without breaking the base image. Sure, having a shell can help with debugging, but do I really need it in production? I've read about distroless images as a potential solution, but I've also seen situations where not having a shell becomes problematic when troubleshooting. How do others manage minimal base images at scale?

Answers

PIVOT.on.heel
Alpine can be an option, but it has its own complications since it uses musl libc, which may not be compatible with all your Python packages. If that's a concern, stick with a slim variant of Debian for compatibility and ease.
Reply to this answer
TRIAL RUN
Iโ€™ve had solid experiences with distroless images too. They reduce the attack surface significantly, although debugging can be tricky. We keep a fallback image around just in case, and most issues will show up in logs anyway.
Reply to this answer
dns.TTL360
Switching away from Ubuntu for your base image will yield better results. A minimal image will save you headaches, especially if you're worried about vulnerabilities. Docker images are really just lightweight OS images sharing the same host kernel.
Reply to this answer
LACE_pattern_
You really need to assess your actual requirements when building your image. Using an Ubuntu image just because itโ€™s common can be lazy if you donโ€™t need all that. Look for smaller base images that satisfy your needs without the added bulk.
Reply to this answer
municipal pool hours
Consider using Alpine Linux or a lighter image specially designed for Python, like python:3.12-slim, which is about 50MB. Plenty of options are out there that wonโ€™t weigh down your app.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions