Docker-py: Support for older docker client("client is newer than server ")

Created on 14 Feb 2017  路  7Comments  路  Source: docker/docker-py

Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import docker
client = docker.from_env()
client.containers.list()
Traceback (most recent call last):
File "", line 1, in
File "/home/ocdn_oper/ci_cd_deployer/env/lib/python2.7/site-packages/docker/models/containers.py", line 762, in list
since=since)
File "/home/ocdn_oper/ci_cd_deployer/env/lib/python2.7/site-packages/docker/api/container.py", line 189, in containers
res = self._result(self._get(u, params=params), True)
File "/home/ocdn_oper/ci_cd_deployer/env/lib/python2.7/site-packages/docker/api/client.py", line 216, in _result
self._raise_for_status(response)
File "/home/ocdn_oper/ci_cd_deployer/env/lib/python2.7/site-packages/docker/api/client.py", line 212, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/home/ocdn_oper/ci_cd_deployer/env/lib/python2.7/site-packages/docker/errors.py", line 30, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 400 Client Error: Bad Request for url: http+docker://localunixsocket/v1.24/containers/json?all=0&limit=-1&trunc_cmd=0&size=0 ("client is newer than server (client API version: 1.24, server API version: 1.22)")

My docker version:

docker version

Client:
Version: 1.10.3
API version: 1.22
Package version: docker-common-1.10.3-59.el7.centos.x86_64
Go version: go1.6.3
Git commit: 3999ccb-unsupported
Built: Thu Dec 15 17:24:43 2016
OS/Arch: linux/amd64

Server:
Version: 1.10.3
API version: 1.22
Package version: docker-common-1.10.3-59.el7.centos.x86_64
Go version: go1.6.3
Git commit: 3999ccb-unsupported
Built: Thu Dec 15 17:24:43 2016
OS/Arch: linux/amd64

kinquestion

Most helpful comment

You'll have to either specify the API version to use, or set it to "auto"; https://docker-py.readthedocs.io/en/stable/client.html

All 7 comments

You'll have to either specify the API version to use, or set it to "auto"; https://docker-py.readthedocs.io/en/stable/client.html

See also: #873, #878

For later versions of docker-py (2.2.1+), you would need to do this

client = docker.DockerClient(version='1.22')

Hello.

I just changed one row in api/client.py and it fix this problem.

https://github.com/swood/docker-py/commit/528c1da44d3e117359ba665f020ad42153a679fc

Could you tell me, is it hack or right way to fix the problem?

Ohh joy... why not making the client detect the server version instead?

Ohh joy... why not making the client detect the server version instead?

That's what the Go client does (e.g., this is the docker cli doing version negotiation; https://github.com/docker/cli/blob/0f337f1dfe574eb12eab8bb102a24f714cc79d86/cli/command/cli.go#L345-L363)

Not sure if the docker-py SDK has this?

In fact adding version="auto" seems to fix this. Why auto is not the implicit value is a mistery which nobody will ever resolve.

Was this page helpful?
0 / 5 - 0 ratings