docker-py
docker-py copied to clipboard
404 on containers.create for valid images
tested under:
Python 3.6.5 Docker version 17.12.1-ce, build 7390fc6 docker 3.4.1
and
Python 3.7.0 Docker version 18.06.0-ce, build 0ffa825 docker 3.4.1
When running
>>> import docker as dockerpy
>>> _client = dockerpy.from_env()
>>> container = _client.containers.create(image='tomochain/infra-telegraf:devnet', name='telegraf')
Traceback (most recent call last):
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/docker/api/client.py", line 229, in _raise_for_status
response.raise_for_status()
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/requests/models.py", line 939, 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.35/containers/create?name=telegraf
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/docker/models/containers.py", line 824, in create
resp = self.client.api.create_container(**create_kwargs)
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/docker/api/container.py", line 411, in create_container
return self.create_container_from_config(config, name)
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/docker/api/container.py", line 422, in create_container_from_config
return self._result(res, True)
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/docker/api/client.py", line 235, in _result
self._raise_for_status(response)
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/docker/api/client.py", line 231, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/Users/etienne/Library/Caches/pypoetry/virtualenvs/tmn-py3.7/lib/python3.7/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.ImageNotFound: 404 Client Error: Not Found ("No such image: tomochain/infra-telegraf:devnet")
If I use the docker client:
➜ docker pull tomochain/infra-telegraf:devnet
devnet: Pulling from tomochain/infra-telegraf
55cbf04beb70: Downloading [===============> ] 14.27MB/45.31MB
1607093a898c: Downloading [=====================> ] 4.586MB/10.74MB
9a8ea045c926: Download complete
9dbf507f8efa: Downloading [==> ] 817.9kB/15.96MB
b7bbc4db97cd: Waiting
b8898b2dd4b3: Waiting
595512eec936: Waiting
d4bd43885499: Waiting
Works fine. And after that there will be no exceptions as the images are already present locally It also works with the images.pull function:
>>> client.images.pull('tomochain/infra-telegraf:devnet')
<Image: 'tomochain/infra-telegraf:devnet'>
Have you figured out what was wrong?
@mitar Nope, ended up pulling the image if this exception is raised :man_shrugging:
Same issue here, docker-py not usable at all.
just want to chime in. i had the same issue and worked around it by using Docker CLI to pull the image before attempting to use docker-py.
@etienne-napoleone this issue probably shouldn't have been closed
Experiencing the same here
Reopening I guess
same here, except it's with an Image that I built using docker-py
, it suddenly can't find it when I do client.containers.run(...)
. Even weirder, it worked perfectly on my Windows machine, but only throws this error on my MacBook Pro 2019
Update - I upgraded docker-py from 4.0 to 4.4.1 and the issue seems fixed.
If someone else can confirm, I will close this issue
I'm using 5.0.0 and it still happens randomly.
Same here, with version 5.0.0 too.
Can confirm this is happening with version 5.0.2
I'm not too familiar with the Python SDK, but from an API perspective, it's expected to get a 404 when you try to create a container that uses an image that's not found in the daemon's local image cache / store.
For comparison; this is the logic in the docker
cli when running docker container create
/ docker create
(which is also used when doing a docker run
); the CLI will send a container create
request to the daemon, which returns a 404 if the image that's referenced for the container doesn't exist. In that case (depending on the --pull
option that's set), it will either pull the image, or return an error that the image is not present);
https://github.com/docker/cli/blob/d8b33fa994b8620f17522aeb7b9cca9896cc0791/cli/command/container/create.go#L258-L276
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name)
if err != nil {
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
if apiclient.IsErrNotFound(err) && namedRef != nil && opts.pull == PullImageMissing {
// we don't want to write to stdout anything apart from container.ID
fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
if err := pullAndTagImage(); err != nil {
return nil, err
}
var retryErr error
response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name)
if retryErr != nil {
return nil, retryErr
}
} else {
return nil, err
}
}
So we have noticed that this happens when running on disk-constrained environment where the Docker image pulled is larger than available space. Then the image pulling in fact fails so when it attempts to do the next step (creating container) that fails with 404. Why exactly pulling does not fail with some exception first is strange. Calling docker pull
using a subprocess first shows the error fine.
This is example CI job which fails this way because on GitLab CI workers have limited space and we are trying to run a 11 GB large image: https://gitlab.com/bhshah/primitives/-/jobs/1695097123
I'm not too familiar with the Python SDK, but from an API perspective, it's expected to get a 404 when you try to create a container that uses an image that's not found in the daemon's local image cache / store.
For comparison; this is the logic in the
docker
cli when runningdocker container create
/docker create
(which is also used when doing adocker run
); the CLI will send acontainer create
request to the daemon, which returns a 404 if the image that's referenced for the container doesn't exist. In that case (depending on the--pull
option that's set), it will either pull the image, or return an error that the image is not present);https://github.com/docker/cli/blob/d8b33fa994b8620f17522aeb7b9cca9896cc0791/cli/command/container/create.go#L258-L276
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name) if err != nil { // Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior. if apiclient.IsErrNotFound(err) && namedRef != nil && opts.pull == PullImageMissing { // we don't want to write to stdout anything apart from container.ID fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef)) if err := pullAndTagImage(); err != nil { return nil, err } var retryErr error response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name) if retryErr != nil { return nil, retryErr } } else { return nil, err } }
Maybe some issues are getting mixed here. I am experiencing the same error, but with client.containers.run
, the same as some of the users above. I think the expected behaviour is it would pull the image if it doesn't exist (just like Docker would using the CLI). Looking at the docs, there doesn't appear to be any flag to specify the pull, it is usually default behaviour (https://docker-py.readthedocs.io/en/stable/containers.html#). Moreover, the issue is intermittent. After a couple of goes at it, something must change in the environment which means the containers.run command eventually pulls the image. Here is an error example from containers.run:
[2020-09-20 10:55:52] - [ERROR] - [docker:93] - Failed to run container.
Traceback (most recent call last):
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status
response.raise_for_status()
File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/containers/create?name=kolibri
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 811, in run
container = self.create(image=image, command=command,
File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 870, in create
resp = self.client.api.create_container(**create_kwargs)
File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 430, in create_container
return self.create_container_from_config(config, name)
File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 441, in create_container_from_config
return self._result(res, True)
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 274, in _result
self._raise_for_status(response)
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.ImageNotFound: 404 Client Error for http+docker://localhost/v1.40/containers/create?name=kolibri: Not Found ("No such image: ghcr.io/learnersblock/kolibri:latest")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status
response.raise_for_status()
File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/images/create?tag=latest&fromImage=ghcr.io%2Flearnersblock%2Fkolibri
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/common/docker.py", line 81, in run
response = client.containers.run(image,
File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 814, in run
self.client.images.pull(image, platform=platform)
File "/root/.local/lib/python3.8/site-packages/docker/models/images.py", line 446, in pull
pull_log = self.client.api.pull(
File "/root/.local/lib/python3.8/site-packages/docker/api/image.py", line 430, in pull
self._raise_for_status(response)
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.40/images/create?tag=latest&fromImage=ghcr.io%2Flearnersblock%2Fkolibri: Internal Server Error ("Get https://ghcr.io/v2/: x509: certificate has expired or is not yet valid")
192.168.0.64 - - [20/Sep/2020 10:55:52] "POST /v1/docker/run HTTP/1.1" 500 -
192.168.0.64 - - [20/Sep/2020 10:55:53] "OPTIONS /v1/appstore/status HTTP/1.1" 200 -
192.168.0.64 - - [20/Sep/2020 10:55:53] "GET /v1/appstore/status HTTP/1.1" 200 -
192.168.0.64 - - [20/Sep/2020 10:56:35] "OPTIONS /v1/system/portainer HTTP/1.1" 200 -
[2020-09-20 10:56:36] - [ERROR] - [docker:93] - Failed to run container.
Traceback (most recent call last):
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status
response.raise_for_status()
File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/containers/create?name=portainer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 811, in run
container = self.create(image=image, command=command,
File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 870, in create
resp = self.client.api.create_container(**create_kwargs)
File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 430, in create_container
return self.create_container_from_config(config, name)
File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 441, in create_container_from_config
return self._result(res, True)
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 274, in _result
self._raise_for_status(response)
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.ImageNotFound: 404 Client Error for http+docker://localhost/v1.40/containers/create?name=portainer: Not Found ("No such image: portainer/portainer-ce:2.6.3-alpine")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status
response.raise_for_status()
File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/images/create?tag=2.6.3-alpine&fromImage=portainer%2Fportainer-ce
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/common/docker.py", line 81, in run
response = client.containers.run(image,
File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 814, in run
self.client.images.pull(image, platform=platform)
File "/root/.local/lib/python3.8/site-packages/docker/models/images.py", line 446, in pull
pull_log = self.client.api.pull(
File "/root/.local/lib/python3.8/site-packages/docker/api/image.py", line 430, in pull
self._raise_for_status(response)
File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.40/images/create?tag=2.6.3-alpine&fromImage=portainer%2Fportainer-ce: Internal Server Error ("Get https://registry-1.docker.io/v2/: x509: certificate has expired or is not yet valid")
This occurred just after the device came up, some of the first steps of its load process on a device that has just booted. Not sure if that is significant. A slightly different error with the 509 is interesting too.
I'm not too familiar with the Python SDK, but from an API perspective, it's expected to get a 404 when you try to create a container that uses an image that's not found in the daemon's local image cache / store. For comparison; this is the logic in the
docker
cli when runningdocker container create
/docker create
(which is also used when doing adocker run
); the CLI will send acontainer create
request to the daemon, which returns a 404 if the image that's referenced for the container doesn't exist. In that case (depending on the--pull
option that's set), it will either pull the image, or return an error that the image is not present); https://github.com/docker/cli/blob/d8b33fa994b8620f17522aeb7b9cca9896cc0791/cli/command/container/create.go#L258-L276response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name) if err != nil { // Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior. if apiclient.IsErrNotFound(err) && namedRef != nil && opts.pull == PullImageMissing { // we don't want to write to stdout anything apart from container.ID fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef)) if err := pullAndTagImage(); err != nil { return nil, err } var retryErr error response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name) if retryErr != nil { return nil, retryErr } } else { return nil, err } }
Maybe some issues are getting mixed here. I am experiencing the same error, but with
client.containers.run
, the same as some of the users above. I think the expected behaviour is it would pull the image if it doesn't exist (just like Docker would using the CLI). Looking at the docs, there doesn't appear to be any flag to specify the pull, it is usually default behaviour (https://docker-py.readthedocs.io/en/stable/containers.html#). Moreover, the issue is intermittent. After a couple of goes at it, something must change in the environment which means the containers.run command eventually pulls the image. Here is an error example from containers.run:[2020-09-20 10:55:52] - [ERROR] - [docker:93] - Failed to run container. Traceback (most recent call last): File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status response.raise_for_status() File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/containers/create?name=kolibri During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 811, in run container = self.create(image=image, command=command, File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 870, in create resp = self.client.api.create_container(**create_kwargs) File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 430, in create_container return self.create_container_from_config(config, name) File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 441, in create_container_from_config return self._result(res, True) File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 274, in _result self._raise_for_status(response) File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status raise create_api_error_from_http_exception(e) File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception raise cls(e, response=response, explanation=explanation) docker.errors.ImageNotFound: 404 Client Error for http+docker://localhost/v1.40/containers/create?name=kolibri: Not Found ("No such image: ghcr.io/learnersblock/kolibri:latest") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status response.raise_for_status() File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/images/create?tag=latest&fromImage=ghcr.io%2Flearnersblock%2Fkolibri During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/common/docker.py", line 81, in run response = client.containers.run(image, File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 814, in run self.client.images.pull(image, platform=platform) File "/root/.local/lib/python3.8/site-packages/docker/models/images.py", line 446, in pull pull_log = self.client.api.pull( File "/root/.local/lib/python3.8/site-packages/docker/api/image.py", line 430, in pull self._raise_for_status(response) File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status raise create_api_error_from_http_exception(e) File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception raise cls(e, response=response, explanation=explanation) docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.40/images/create?tag=latest&fromImage=ghcr.io%2Flearnersblock%2Fkolibri: Internal Server Error ("Get https://ghcr.io/v2/: x509: certificate has expired or is not yet valid") 192.168.0.64 - - [20/Sep/2020 10:55:52] "POST /v1/docker/run HTTP/1.1" 500 - 192.168.0.64 - - [20/Sep/2020 10:55:53] "OPTIONS /v1/appstore/status HTTP/1.1" 200 - 192.168.0.64 - - [20/Sep/2020 10:55:53] "GET /v1/appstore/status HTTP/1.1" 200 - 192.168.0.64 - - [20/Sep/2020 10:56:35] "OPTIONS /v1/system/portainer HTTP/1.1" 200 - [2020-09-20 10:56:36] - [ERROR] - [docker:93] - Failed to run container. Traceback (most recent call last): File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status response.raise_for_status() File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/containers/create?name=portainer During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 811, in run container = self.create(image=image, command=command, File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 870, in create resp = self.client.api.create_container(**create_kwargs) File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 430, in create_container return self.create_container_from_config(config, name) File "/root/.local/lib/python3.8/site-packages/docker/api/container.py", line 441, in create_container_from_config return self._result(res, True) File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 274, in _result self._raise_for_status(response) File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status raise create_api_error_from_http_exception(e) File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception raise cls(e, response=response, explanation=explanation) docker.errors.ImageNotFound: 404 Client Error for http+docker://localhost/v1.40/containers/create?name=portainer: Not Found ("No such image: portainer/portainer-ce:2.6.3-alpine") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status response.raise_for_status() File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 943, 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.40/images/create?tag=2.6.3-alpine&fromImage=portainer%2Fportainer-ce During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/common/docker.py", line 81, in run response = client.containers.run(image, File "/root/.local/lib/python3.8/site-packages/docker/models/containers.py", line 814, in run self.client.images.pull(image, platform=platform) File "/root/.local/lib/python3.8/site-packages/docker/models/images.py", line 446, in pull pull_log = self.client.api.pull( File "/root/.local/lib/python3.8/site-packages/docker/api/image.py", line 430, in pull self._raise_for_status(response) File "/root/.local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status raise create_api_error_from_http_exception(e) File "/root/.local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception raise cls(e, response=response, explanation=explanation) docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.40/images/create?tag=2.6.3-alpine&fromImage=portainer%2Fportainer-ce: Internal Server Error ("Get https://registry-1.docker.io/v2/: x509: certificate has expired or is not yet valid")
This occurred just after the device came up, some of the first steps of its load process on a device that has just booted. Not sure if that is significant. A slightly different error with the 509 is interesting too.
For me, it seems to be related to clock drift. Set your clock back a year (not sure what the threshold is, but seems to need to be more than a day at least, so I jumped to a year just to test) and the issue I note above is generated. I am working on IoT devices, so this isn't uncommon if you try to do a pull before the device can sync with an NTP server. Will provide more details if anything of value.
Ideally for docker-py we could have the option to disable the cert requirement on pulling images.
We're seeing this happen intermittently in CI on GitHub Actions.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/docker/api/client.py", line 261, in _raise_for_status
response.raise_for_status()
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 943, 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.35/images/yandex/clickhouse-server:20.3.9.70/json
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/sentry", line 33, in <module>
sys.exit(load_entry_point('sentry', 'console_scripts', 'sentry')())
File "/.pip/sentry/src/sentry/runner/__init__.py", line 188, in main
func(**kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/.pip/sentry/src/sentry/runner/commands/devservices.py", line 217, in up
_start_service(
File "/.pip/sentry/src/sentry/runner/commands/devservices.py", line 279, in _start_service
client.images.pull(options["image"])
File "/usr/local/lib/python3.8/site-packages/docker/models/images.py", line 449, in pull
return self.get('{0}{2}{1}'.format(
File "/usr/local/lib/python3.8/site-packages/docker/models/images.py", line 316, in get
return self.prepare_model(self.client.api.inspect_image(name))
File "/usr/local/lib/python3.8/site-packages/docker/utils/decorators.py", line 19, in wrapped
return f(self, resource_id, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/docker/api/image.py", line 244, in inspect_image
return self._result(
File "/usr/local/lib/python3.8/site-packages/docker/api/client.py", line 267, in _result
self._raise_for_status(response)
File "/usr/local/lib/python3.8/site-packages/docker/api/client.py", line 263, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/usr/local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.ImageNotFound: 404 Client Error: Not Found ("no such image: yandex/clickhouse-server:20.3.9.70: No such image: yandex/clickhouse-server:20.3.9.70")
https://github.com/docker/docker-py/issues/2503 seems like a related issue as well.
Oddly _raise_for_status
is a function used to raise the error which doesn’t receive and share the function that called _raise_for_status
. Not sure where to start looking.
I was seeing this locally for a few days on Ubuntu 22.10, and even reproduced bizarre, seemingly contradictory output like this in ipython
:
In [4]: client.images.list()
Out[4]:
[List of old, unused images from...somewhere?]
In [5]: !docker images --all
REPOSITORY TAG IMAGE ID CREATED SIZE
[nothing]
I dug deeper and found, buried in ~/.docker/contexts/meta/[long hash]]/meta.json
, that my CLI docker was connecting to a socket in my ~/.local
directory, whereas docker.from_env()
was connecting to /var/run/docker
because I had not explicitly set/exported DOCKER_HOST.
Adding export DOCKER_HOST=[the correct host]
and re-sourcing my shell fixed this for me. Hopefully this is helpful for someone stumbling upon this in the future.
I am using
client.images.build()
instead of
client.api.build()
before creating my container based on that image. So far so good.
I was having the same issue, I had 12g of free diskspace, downloading a 6g image, I used client.image.pull, and got no error, but when doing a client.containers.run, it got the 404, image not found issue.
When I used docker pull cli, it worked fine. After finding this bug report, I added another 20g of diskspace, and things worked without problems.
Maybe client.image.pull should return an error if the image doesn't actually download?
Ran into this issue while trying to run a docker container via jupyter notebooks.
The issue for me seems to have been related to the docker daemon endpoint. I needed to expose it without TLS.
Then it turns out that the library already has a way to turn on verification for TLS
docker.tls.TLSConfig(verify=True)