How do you remove the package manager and shell from a final image built on Debian?
IntermediateProductionImage Security & Hardening
Answer
Prefer distroless. If you must keep Debian slim, remove tooling in a final layer sequence carefully:
RUN rm -f /bin/sh /bin/bash /usr/bin/apt* /usr/bin/dpkg* 2>/dev/null || true
This is brittle (entrypoints often need sh), so we usually copy the app into a distroless runtime stage instead.
More on Image Security & Hardening
Why should containers not run as root, and how do you enforce it?BeginnerWhat is a distroless image and what are the trade-offs?BeginnerHow do you scan an image with Trivy and fail a CI build on serious findings?BeginnerHow do you manage Trivy false positives and accepted risks?IntermediateWhich `docker run` flags make up a hardened runtime baseline?BeginnerWhat does `no-new-privileges` protect against?Beginner