Incompatibility between python-docker and docker-ce leads to Error while fetching server API version

3,702 views
Skip to first unread message

jean-christophe Manciot

unread,
Mar 17, 2018, 1:24:29 PM3/17/18
to docker-dev
Ubuntu 17.10
docker-ce 18.02.0~ce-0~ubuntu
python-docker 2.5.1
ansible 2.4.3.0-1

Running the attached simple playbook as root or local user (who is part of docker group) leads to the same issue:
ansible-playbook -vvvv postgres.yml
ansible-playbook 2.6.0 (devel 0a6b951447) last updated 2018/03/17 18:10:25 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/actionmystique/src/Ansible/git-yang-networkop/ansible-101/library']
  ansible python module location = /media/actionmystique/SAMSUNG5-Shared/home/actionmystique/src/Ansible/git-ansible/lib/ansible
  executable location = /media/actionmystique/SAMSUNG5-Shared/home/actionmystique/src/Ansible/git-ansible/bin/ansible-playbook
  python version = 2.7.14+ (default, Mar 16 2018, 11:04:57) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /etc/ansible/hosts inventory source with ini plugin
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

Loading callback plugin default of type stdout, v2.0 from /media/actionmystique/SAMSUNG5-Shared/home/actionmystique/src/Ansible/git-ansible/lib/ansible/plugins/callback/default.py
 ________________________
< PLAYBOOK: postgres.yml >
 ------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

1 plays in postgres.yml
 ____________________________________
< PLAY [Activate postgres container] >
 ------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

META: ran handlers
 _________________________
< TASK [docker_container] >
 -------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

task path: /media/actionmystique/SAMSUNG5-Shared/home/actionmystique/src/Ansible/test-docker_container/postgres.yml:7
Using module file /media/actionmystique/SAMSUNG5-Shared/home/actionmystique/src/Ansible/git-ansible/lib/ansible/modules/cloud/docker/docker_container.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python && sleep 0'
The full traceback is:
  File "/tmp/ansible_Q1Qz5S/ansible_modlib.zip/ansible/module_utils/docker_common.py", line 159, in __init__
    super(AnsibleDockerClient, self).__init__(**self._connect_params)
  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 154, in __init__
    self._version = self._retrieve_server_version()
  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 179, in _retrieve_server_version
    'Error while fetching server API version: {0}'.format(e)

fatal: [127.0.0.1]: FAILED! => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "api_version": null, 
            "auto_remove": false, 
            "blkio_weight": null, 
            "cacert_path": null, 
            "capabilities": null, 
            "cert_path": null, 
            "cleanup": false, 
            "command": null, 
            "cpu_period": null, 
            "cpu_quota": null, 
            "cpu_shares": null, 
            "cpuset_cpus": null, 
            "cpuset_mems": null, 
            "debug": false, 
            "detach": true, 
            "devices": null, 
            "dns_opts": null, 
            "dns_search_domains": null, 
            "dns_servers": null, 
            "docker_host": null, 
            "domainname": null, 
            "entrypoint": null, 
            "env": {
                "PGDATA": "/var/lib/postgresql/data/pgdata", 
                "POSTGRES_DB": "/var/lib/postgresql", 
                "POSTGRES_PASSWORD": "password", 
                "POSTGRES_USER": "admin"
            }, 
            "env_file": null, 
            "etc_hosts": null, 
            "exposed_ports": null, 
            "filter_logger": false, 
            "force_kill": false, 
            "groups": null, 
            "hostname": null, 
            "ignore_image": false, 
            "image": "postgres:9.6", 
            "interactive": false, 
            "ipc_mode": null, 
            "keep_volumes": true, 
            "kernel_memory": null, 
            "key_path": null, 
            "kill_signal": null, 
            "labels": null, 
            "links": null, 
            "log_driver": null, 
            "log_options": null, 
            "mac_address": null, 
            "memory": "0", 
            "memory_reservation": null, 
            "memory_swap": null, 
            "memory_swappiness": null, 
            "name": "postgres", 
            "network_mode": null, 
            "networks": null, 
            "oom_killer": null, 
            "oom_score_adj": null, 
            "paused": false, 
            "pid_mode": null, 
            "privileged": false, 
            "published_ports": null, 
            "pull": false, 
            "purge_networks": false, 
            "read_only": false, 
            "recreate": false, 
            "restart": false, 
            "restart_policy": "unless-stopped", 
            "restart_retries": null, 
            "security_opts": null, 
            "shm_size": null, 
            "ssl_version": null, 
            "state": "started", 
            "stop_signal": null, 
            "stop_timeout": null, 
            "sysctls": null, 
            "timeout": null, 
            "tls": null, 
            "tls_hostname": null, 
            "tls_verify": null, 
            "tmpfs": null, 
            "trust_image_content": false, 
            "tty": false, 
            "ulimits": null, 
            "user": null, 
            "userns_mode": null, 
            "uts": null, 
            "volume_driver": null, 
            "volumes": [
                "/var/lib/pgdocker"
            ], 
            "volumes_from": null, 
            "working_dir": null
        }
    }, 
    "msg": "Error connecting: Error while fetching server API version: Timeout value connect was Timeout(connect=60, read=60, total=None), but it must be an int or float."
}
 
This does not appear to be an ansible issue, but rather an incompatibility between many differnt versions of python-docker and docker-ce.
I have tried unsuccessfully:
- all previous releases of docker-ce
- python-docker 1.9.0-1
- all docker python module versions from 2.7.0 up to 3.1.1 through pip which leads to a 1-year old unsolved issue (https://github.com/docker/docker-py/issues/1502)

Any suggestion?
Am I missing something?

jean-christophe Manciot

unread,
Mar 17, 2018, 1:33:15 PM3/17/18
to docker-dev
Of course, the docker service is active & running:
# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-03-17 18:01:29 CET; 30min ago
 Main PID: 3155 (dockerd)
    Tasks: 37
   Memory: 92.5M
      CPU: 4.612s
   CGroup: /system.slice/docker.service
           ├─3155 /usr/bin/dockerd -H fd://
           └─4044 docker-containerd --config /var/run/docker/containerd/containerd.toml

Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.250079202+01:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.250626550+01:00" level=warning msg="Your kernel does not support cgroup rt period"
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.250650308+01:00" level=warning msg="Your kernel does not support cgroup rt runtime"
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.251306890+01:00" level=info msg="Loading containers: start."
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.654334183+01:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.22.0.0/1
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.683017680+01:00" level=info msg="Loading containers: done."
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.799037549+01:00" level=info msg="Docker daemon" commit=fc4de44 graphdriver(s)=overlay2 version=18.02.
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.809087985+01:00" level=info msg="Daemon has completed initialization"
Mar 17 18:01:29 samsung-ubuntu dockerd[3155]: time="2018-03-17T18:01:29.834316366+01:00" level=info msg="API listen on /var/run/docker.sock"
Mar 17 18:01:29 samsung-ubuntu systemd[1]: Started Docker Application Container Engine.

jean-christophe Manciot

unread,
Mar 19, 2018, 6:59:01 AM3/19/18
to docker-dev
The solution is to uninstall python-docker and run the previous playbook in a virtualenv with docker pip module 3.1.1.

Lovi Sharma

unread,
Jun 12, 2019, 10:57:11 PM6/12/19
to docker-dev
Hi Jean,

Struggling with the same error since from a weeks time,

Pip List Output
Package                      Version
---------------------------- -----------
ansible                      2.8.1
asn1crypto                   0.24.0
backports.ssl-match-hostname 3.7.0.1
bcrypt                       3.1.6
cached-property              1.5.1
certifi                      2019.3.9
cffi                         1.12.3
chardet                      3.0.4
configparser                 3.5.0b2
cryptography                 2.7
decorator                    4.4.0
docker                       3.7.2
docker-compose               1.24.0
docker-pycreds               0.4.0
dockerpty                    0.4.1
docopt                       0.6.2
entrypoints                  0.3
enum34                       1.1.6
functools32                  3.2.3.post2
gyp                          0.1
httplib2                     0.11.3
idna                         2.7
ipaddress                    1.0.22
Jinja2                       2.10
jsonschema                   2.6.0
kerberos                     1.3.0
keyring                      17.1.1
keyrings.alt                 3.1.1
MarkupSafe                   1.1.0
ntlm-auth                    1.3.0
paramiko                     2.4.2
pip                          19.1.1
pyasn1                       0.4.5
pycparser                    2.19
pycrypto                     2.6.1
pycurl                       7.43.0.2
PyGObject                    3.32.0
pykerberos                   1.2.1
pyliblzma                    0.5.3
PyNaCl                       1.3.0
pyOpenSSL                    19.0.0
pypsrp                       0.3.1
pysqlite                     1.0.1
pyxdg                        0.25
PyYAML                       3.13
requests                     2.20.1
requests-credssp             1.0.2
requests-kerberos            0.12.0
rpm                          4.14.2.1
SecretStorage                2.3.1
setuptools                   40.8.0
six                          1.12.0
texttable                    0.9.1
urlgrabber                   3.10.2
urllib3                      1.24.3
websocket-client             0.56.0
wheel                        0.32.3
yum-metadata-parser          1.1.4

Services are running,

systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/docker.service.d
           └─https-proxy.conf
   Active: active (running) since Thu 2019-06-13 10:08:13 AWST; 45min ago
 Main PID: 24345 (dockerd)
    Tasks: 17
   Memory: 37.6M
   CGroup: /system.slice/docker.service
           └─24345 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

docker pull hello-world, it is also setup

Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8
Status: Image is up to date for hello-world:latest

Still getting the same error,

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "build": false,
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "debug": false,
            "definition": null,
            "dependencies": true,
            "docker_host": "unix://var/run/docker.sock",
            "files": null,
            "hostname_check": false,
            "nocache": false,
            "project_name": null,
            "project_src": "/var/lib/awx",
            "pull": false,
            "recreate": "smart",
            "remove_images": null,
            "remove_orphans": false,
            "remove_volumes": false,
            "restarted": false,
            "scale": null,
            "services": null,
            "ssl_version": null,
            "state": "present",
            "stopped": false,
            "timeout": 10,
            "tls": false,
            "tls_hostname": "localhost",
            "validate_certs": false
        }
    },
    "msg": "Error connecting: Error while fetching server API version: Timeout value connect was Timeout(connect=10, read=10, total=None), but it must be an int or float."


Need help, please
Reply all
Reply to author
Forward
0 new messages