Skip to content
Runbook

Install Python on Docker

General-purpose programming language and runtime, batteries included.

Runtimelanguageruntimescriptinginterpreter

Installation

Official image · Docker
docker run --rm -it python:3.13 python --version

Pulls and runs the official python:3.13 image, then prints the version.

Slim variant · Docker
docker run --rm -it python:3.13-slim python --version

Smaller Debian-based image without build tools.

Verify the installation

Verify
docker run --rm python:3.13 python --version

Important files

TypePathDescription
binary/usr/local/bin/pythonInterpreter location inside the official image.

Command-line tools

  • pythonThe interpreter, available in the image.
  • pipPackage installer included in the image.

Good to know

  • The official image is python:3.13 (multi-architecture); there is no service or port to expose.
  • For a project, base your Dockerfile on FROM python:3.13-slim and copy requirements.txt first to leverage layer caching.
  • The -alpine variant is smaller but uses musl libc; some wheels may need compilation.

Running Python with Docker

The official python image runs Python without installing anything on the host. docker run --rm -it python:3.13 python --version pulls the image and prints the version; docker run --rm -it python:3.13 bash opens a shell. Inside, the interpreter is /usr/local/bin/python.

Containerizing an application

Base your Dockerfile on FROM python:3.13-slim. Copy requirements.txt first and run pip install --no-cache-dir -r requirements.txt, then copy the source: this ordering maximizes layer-cache reuse.

Choosing a variant

python:3.13-slim is a small Debian image; python:3.13-alpine is smaller still but relies on musl libc, so some packages with C extensions may need to compile from source.