Getting a list of available docker containers using docker-py

I am using docker-py to manage docker containers for one of my applications. I want to get a list of all running containers, identical docker ps

. But the method containers

returns an empty list.

>>> import docker
>>> c = docker.Client()
>>> container = c.create_container(image='base', command='/bin/bash', stdin_open=True, tty=True, name='docker-test')
>>> container
{u'Id': u'1998f08a031d8632400264af667d93162465a04348b61144a4c730c7c4462875', u'Warnings': None}
>>> c.start(container)
>>> c.containers(quiet=False, all=True, trunc=True, latest=False, since=None, before=None, limit=-1)
[]

      

But of course doing $ docker ps

it gives me this:

CONTAINER ID        IMAGE                   COMMAND             CREATED             STATUS              PORTS               NAMES
1998f08a031d        base:latest             /bin/bash           3 minutes ago       Up 3 minutes                            docker-test

      

What am I missing here?

+3


source to share


1 answer


Okay, I figured out what happened. Client and servers were not the same version. When I reinitialize docker.Client

with the correct version number, it returns a list of all running containers.



+3


source







All Articles