docker / docker/docker-py

docker-py does not correctly handle 409 "rate limit" responses from registry

Open
#2,715 0 comments 1 reaction 1 assignee View on GitHub

@ulyssessouza is already working on this.

Since Dec 7, 2020.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

I noticed this in the Moby CI, where a test failed and prints a 500 (internal server error) instead of a 409 (rate limit exceeded);

[2020-12-02T14:41:33.711Z] docker/api/client.py:261: in _raise_for_status
[2020-12-02T14:41:33.711Z]     response.raise_for_status()
[2020-12-02T14:41:33.711Z] /usr/local/lib/python3.7/site-packages/requests/models.py:940: in raise_for_status
[2020-12-02T14:41:33.711Z]     raise HTTPError(http_error_msg, response=self)
[2020-12-02T14:41:33.711Z] E   requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://localhost/v1.39/containers/create
[2020-12-02T14:41:33.711Z]
[2020-12-02T14:41:33.711Z] During handling of the above exception, another exception occurred:
[2020-12-02T14:41:33.711Z] docker/models/containers.py:810: in run
[2020-12-02T14:41:33.711Z]     detach=detach, **kwargs)
[2020-12-02T14:41:33.711Z] docker/models/containers.py:868: in create
[2020-12-02T14:41:33.711Z]     resp = self.client.api.create_container(**create_kwargs)
[2020-12-02T14:41:33.711Z] docker/api/container.py:430: in create_container
[2020-12-02T14:41:33.711Z]     return self.create_container_from_config(config, name)
[2020-12-02T14:41:33.711Z] docker/api/container.py:441: in create_container_from_config
[2020-12-02T14:41:33.711Z]     return self._result(res, True)
[2020-12-02T14:41:33.711Z] docker/api/client.py:267: in _result
[2020-12-02T14:41:33.711Z]     self._raise_for_status(response)
[2020-12-02T14:41:33.711Z] docker/api/client.py:263: in _raise_for_status
[2020-12-02T14:41:33.711Z]     raise create_api_error_from_http_exception(e)
[2020-12-02T14:41:33.711Z] docker/errors.py:31: in create_api_error_from_http_exception
[2020-12-02T14:41:33.711Z]     raise cls(e, response=response, explanation=explanation)
[2020-12-02T14:41:33.711Z] E   docker.errors.ImageNotFound: 404 Client Error: Not Found ("No such image: alpine:latest")
[2020-12-02T14:41:33.711Z]
[2020-12-02T14:41:33.711Z] During handling of the above exception, another exception occurred:
[2020-12-02T14:41:33.711Z] docker/api/client.py:261: in _raise_for_status
[2020-12-02T14:41:33.711Z]     response.raise_for_status()
[2020-12-02T14:41:33.711Z] /usr/local/lib/python3.7/site-packages/requests/models.py:940: in raise_for_status
[2020-12-02T14:41:33.711Z]     raise HTTPError(http_error_msg, response=self)
[2020-12-02T14:41:33.711Z] E   requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.39/images/create?fromImage=alpine
[2020-12-02T14:41:33.711Z]
[2020-12-02T14:41:33.711Z] During handling of the above exception, another exception occurred:
[2020-12-02T14:41:33.711Z] tests/integration/models_resources_test.py:9: in test_reload
[2020-12-02T14:41:33.711Z]     container = client.containers.run("alpine", "sleep 300", detach=True)
[2020-12-02T14:41:33.711Z] docker/models/containers.py:812: in run
[2020-12-02T14:41:33.711Z]     self.client.images.pull(image, platform=platform)
[2020-12-02T14:41:33.711Z] docker/models/images.py:445: in pull
[2020-12-02T14:41:33.711Z]     repository, tag=tag, stream=True, **kwargs
[2020-12-02T14:41:33.711Z] docker/api/image.py:415: in pull
[2020-12-02T14:41:33.711Z]     self._raise_for_status(response)
[2020-12-02T14:41:33.711Z] docker/api/client.py:263: in _raise_for_status
[2020-12-02T14:41:33.711Z]     raise create_api_error_from_http_exception(e)
[2020-12-02T14:41:33.711Z] docker/errors.py:31: in create_api_error_from_http_exception
[2020-12-02T14:41:33.711Z]     raise cls(e, response=response, explanation=explanation)
[2020-12-02T14:41:33.711Z] E   docker.errors.APIError: 500 Server Error: Internal Server Error ("toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit")

Using "debug" logging in compose, I see the same issue; using

docker-compose --version
docker-compose version 1.27.4, build 40524192

To reproduce, try running a compose project that uses the ratelimitalways/test:latest image:

docker-compose --log-level=DEBUG -f - up <<'EOF'
version: "3.9"
services:
  test:
    image: ratelimitalways/test:latest
EOF

Which outputs;

Trying paths: ['/Users/sebastiaan/.docker/config.json', '/Users/sebastiaan/.dockercfg']
Found file at path: /Users/sebastiaan/.docker/config.json
Trying paths: ['/Users/sebastiaan/.docker/config.json', '/Users/sebastiaan/.dockercfg']
Found file at path: /Users/sebastiaan/.docker/config.json
Found 'auths' section
Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
Found 'credsStore' section
http://localhost:None "GET /version HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/networks/rate_default HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/info HTTP/1.1" 200 None
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

http://localhost:None "GET /v1.41/networks/rate_default HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/containers/json?limit=-1&all=0&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Drate%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/containers/json?limit=-1&all=0&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Drate%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Drate%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Drate%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Drate%22%2C+%22com.docker.compose.service%3Dtest%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Drate%22%2C+%22com.docker.compose.service%3Dtest%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
http://localhost:None "GET /v1.41/images/ratelimitalways/test:latest/json HTTP/1.1" 404 None
Pulling test (ratelimitalways/test:latest)...
Looking for auth config
Using credentials store "desktop"
Looking for auth entry for 'https://index.docker.io/v1/'
Found auth config
http://localhost:None "POST /v1.41/images/create?tag=latest&fromImage=ratelimitalways%2Ftest HTTP/1.1" 500 None
ERROR: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
bash-5.0$ docker-compose --version
docker-compose version 1.27.4, build 40524192

@aiordache @ulyssessouza ptal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.