Black Docker image

Official Black Docker images are available on Docker Hub.

Black images with the following tags are available:

  • release numbers, e.g. 21.5b2, 21.6b0, 21.7b0 etc.
    ℹ Recommended for users who want to use a particular version of Black.

  • latest_release - tag created when a new version of Black is released.
    ℹ Recommended for users who want to use released versions of Black. It maps to the latest release of Black.

  • latest_prerelease - tag created when a new alpha (prerelease) version of Black is released.
    ℹ Recommended for users who want to preview or test alpha versions of Black. Note that the most recent release may be newer than any prerelease, because no prereleases are created before most releases.

  • latest - tag used for the newest image of Black.
    ℹ Recommended for users who always want to use the latest version of Black, even before it is released.

There is one more tag used for Black Docker images - latest_non_release. It is created for all unreleased commits on the main branch. This tag is not meant to be used by external users.

From version 23.11.0 the Docker image installs a compiled black into the image.

Usage

A permanent container doesn’t have to be created to use Black as a Docker image. It’s enough to run Black commands for the chosen image denoted as :tag. In the below examples, the latest_release tag is used. If :tag is omitted, the latest tag will be used.

More about Black usage can be found in Usage and Configuration: The basics.

Check Black version

$ docker run --rm pyfound/black:latest_release black --version

Check code

$ docker run --rm --volume $(pwd):/src --workdir /src pyfound/black:latest_release black --check .

Remark: besides regular Black exit codes returned by --check option, Docker exit codes should also be considered.