Invalid Version Parsing in docker-py with docker.io Versions Containing Suffixes (e.g., 20.10.24+dfsg1) #3288
Description
Hello,
I'm Tommaso from Kathará, a network emulator based on Docker containers.
We use docker-py
to interface with the Docker daemon, and we have encountered an issue when using the version_lt
function (and similar ones like version_ge
) from the utils
module of docker-py
with certain versions of docker.io
. Specifically, this issue arises when the Docker version string includes additional characters, such as 20.10.24+dfsg1
(docker.io) (e.g., KatharaFramework/Kathara#301, KatharaFramework/Kathara#309).
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 225, in version_lt
return compare_version(v1, v2) > 0
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 214, in compare_version
s1 = StrictVersion(v1)
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/setuptools/_distutils/version.py", line 54, in __init__
self.parse(vstring)
File "/usr/lib/python3/dist-packages/setuptools/_distutils/version.py", line 157, in parse
raise ValueError("invalid version number '%s'" % vstring)
ValueError: invalid version number '20.10.24+dfsg1'
I understand that docker.io
is not officially released by Docker, so I am unsure if this falls within your intended scope. However, I wanted to bring this to your attention in case you are interested in addressing the compatibility issue.
STEP TO REPRODUCE
- Run a container and enter it:
docker run -ti --rm debian:latest bash
- Install required packages:
apt update
apt install python3 python3-pip
- Install docker-py:
python3 -m pip install docker-py --break-system-packages
- Enter a Python shell:
python3
- Reproduce the error:
from docker.utils import version_lt
version_lt("20.10.24+dfsg1", "20.10.0")
- Get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 225, in version_lt
return compare_version(v1, v2) < 0
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 24, in compare_version
a = StrictVersion(vA)
File "/usr/lib/python3.11/dist-packages/setuptools/_distutils/version.py", line 41, in __init__
self.parse(vstring)
File "/usr/lib/python3.11/dist-packages/setuptools/_distutils/version.py", line 157, in parse
raise ValueError(f"invalid version number '{vstring}'")
ValueError: invalid version number '20.10.24+dfsg1'