Use a ‘slim’ runtime image
For many applications written in languages that require a runtime, you can use a “slim” runtime image for the language. These are prebuilt images that contain the bare minimum of what’s needed to launch and run an application written in the given language.
It’s worth saying again that slim images only give you what’s needed to support the runtime itself, not your particular application. For instance, if you have a Python application that needs third-party packages from PyPI, you must add those as part of the image build process (RUN pip install
, etc.).
Another good source for slender base images, built for specific use cases, is the Google Distroless Image collection. They’re built on top of stripped-down instances of Debian Linux, run on multiple architectures, and offer included runtimes for Python 3, C-compiled programs, Java (including versions 17 and 21), and Node.js (versions 18, 20, and 22). They don’t contain shells or package managers, so you must configure your Dockerfile’s ENTRYPOINT
so it won’t attempt to use a shell (e.g., ENTRYPOINT ["start"]
instead of ENTRYPOINT "start"
) or supply arguments to the language runtime configured as the default.