Note Each RUN creates a new image layer. Combine related commands with && to reduce layers and image size. Always clean up package manager caches in the same RUN statement, or the cache ends up in a previous layer and is never actually removed.
# Install a package# pip install requests# Install specific version# pip install requests==2.31.0# Install from requirements file# pip install -r requirements.txt# Show installed packages# pip list# Show details about a package# pip show requests
Note Consider using pip-tools, poetry, or uv for reproducible dependency management. pip freeze captures transitive deps, which can be fragile across platforms.
Frequently asked questions
How do you install package?
This task is covered in 2 stacks on this page: Docker, Python. The "RUN - Execute Build Commands" snippet in Docker uses `RUN <command>`.
Which command does the Docker example use?
The "RUN - Execute Build Commands" snippet uses `RUN <command>`, from the Dockerfile section of the Docker cheat sheet.
Which stacks cover "install package" on this page?
Docker, Python. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "RUN - Execute Build Commands": Each RUN creates a new image layer. Combine related commands with && to reduce layers and image size. Always clean up package manager caches in the same RUN statement, or the cache ends up in a previous layer and is never actually removed.