When using docker-py to fetch a non-existent image, it should raise docker.errors.NotFound if the image/tag is missing. This works correctly if the image is being fetched directly from DockerHub, but we get a docker.errors.APIError if fetched via harbor.
docker-py is the easiest way to demonstrate the issue, but the differences can be further shown using curl. Both harbor and dockerhub are returning a 404 error, but the body of the response is difference.
{"errors":[{"code":"NOT_FOUND","message":"resource not found: repo [docker.io/library/debian](http://docker.io/library/debian), tag badtag not found"}]}
Configure a proxy cache to dockerhub on harbor. I used docker.io as the proxy cache name in my examples below
Via docker-py
>>> import docker
>>> client = docker.from_env()
>>> client.images.pull("debian:badtag")
Traceback (most recent call last):
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/api/client.py", line 265, in _raise_for_status
response.raise_for_status()
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://localhost/v1.43/images/create?tag=badtag&fromImage=debian
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/models/images.py", line 464, in pull
pull_log = self.client.api.pull(
^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/api/image.py", line 429, in pull
self._raise_for_status(response)
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/api/client.py", line 267, in _raise_for_status
raise create_api_error_from_http_exception(e) from e
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/errors.py", line 39, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation) from e
docker.errors.NotFound: 404 Client Error for http+docker://localhost/v1.43/images/create?tag=badtag&fromImage=debian: Not Found ("manifest for debian:badtag not found: manifest unknown: manifest unknown")
>>> client.images.pull("harbor.local/docker.io/debian:badtag")
Traceback (most recent call last):
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/api/client.py", line 265, in _raise_for_status
response.raise_for_status()
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.43/images/create?tag=badtag&fromImage=harbor.local%2Fdocker.io%2Fdebian
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/models/images.py", line 464, in pull
pull_log = self.client.api.pull(
^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/api/image.py", line 429, in pull
self._raise_for_status(response)
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/api/client.py", line 267, in _raise_for_status
raise create_api_error_from_http_exception(e) from e
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/hhr7h5pab4dcy6sjbhw1xw3ym1z45h87-python3-3.11.9-env/lib/python3.11/site-packages/docker/errors.py", line 39, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation) from e
docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.43/images/create?tag=badtag&fromImage=harbor.local%2Fdocker.io%2Fdebian: Internal Server Error ("unknown: resource not found: repo docker.io/library/debian, tag badtag not found")
This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.
Expected behavior and actual behavior:
When using docker-py to fetch a non-existent image, it should raise
docker.errors.NotFound
if the image/tag is missing. This works correctly if the image is being fetched directly from DockerHub, but we get adocker.errors.APIError
if fetched via harbor.docker-py is the easiest way to demonstrate the issue, but the differences can be further shown using curl. Both harbor and dockerhub are returning a 404 error, but the body of the response is difference.
Dockerhub has:
Harbor has:
In distribution/distribution, the
MANIFEST_UNKNOWN
is defined as an appropriate error code, but I do not see anything defined forNOT_FOUND
. https://github.com/distribution/distribution/blob/3fe707de5c94160f40b41454e0fd0b91921d0176/registry/api/errcode/register.go#L145-L151Steps to reproduce the problem:
docker.io
as the proxy cache name in my examples belowVia docker-py
Via curl
Dockerhub:
Harbor:
Versions: Please specify the versions of following systems.