Skip to content

pip-pin-versions

Dockerfilesuspiciousno fixdefault: offdockerfile/hadolint

Reports a pip install (also pip3, pip3.12) of a package without a version. A package is pinned when it has a specifier (==, >=, <, !=, ~=) or is a wheel, a source archive or a path (.whl, .tar.gz, anything with a /). A VCS requirement such as git+https://example.com/x.git must name a revision after @.

Not reported: pip install -r requirements.txt and -c constraints.txt (the versions are in the file), pip install ., and the values of options such as -i, -e or -t. python -m pip install and pipenv are not checked.

An unpinned pip install takes the latest release of the package, and of the libraries it depends on, on the day of the build. A new major version can break the application, and two builds of one Dockerfile give different images.

Pin the packages, ideally in a requirements.txt made by a lock tool, and install it with -r.

Reported
FROM node:20
RUN pip install flask
RUN pip install flask==2.0 "requests>=2"
RUN pip3 install -r requirements.txt
RUN pip install --no-cache-dir -i https://x/simple flask==1
RUN pip install .
RUN pip install git+https://github.com/a/b
RUN pip install git+https://github.com/a/b@v1
RUN npm install
...
dockerfile:
lint:
rules:
pip-pin-versions: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line pip-pin-versions in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
hadolint DL3013 partial python -m pip install and the wrappers (pipx, pipenv) are not told apart as hadolint does.