Docker-py: Can not list containers using multiple labels by containers.list()

Created on 14 May 2019  路  3Comments  路  Source: docker/docker-py

By command, we can use many --filter to specify many labels for "docker ps". But containers.list() did not show this option to specify multiple labels. How to use multiple lables?

` def list(self, all=False, before=None, filters=None, limit=-1, since=None,
sparse=False, ignore_removed=False):
"""
List containers. Similar to the docker ps command.

    Args:
        all (bool): Show all containers. Only running containers are shown
            by default
        since (str): Show only containers created since Id or Name, include
            non-running ones
        before (str): Show only container created before Id or Name,
            include non-running ones
        limit (int): Show `limit` last created containers, include
            non-running ones
        filters (dict): Filters to be processed on the image list.
            Available filters:

            - `exited` (int): Only containers with specified exit code
            - `status` (str): One of ``restarting``, ``running``,
                ``paused``, ``exited``
            - `label` (str): format either ``"key"`` or ``"key=value"``
            - `id` (str): The id of the container.
            - `name` (str): The name of the container.
            - `ancestor` (str): Filter by container ancestor. Format of
                ``<image-name>[:tag]``, ``<image-id>``, or
                ``<image@digest>``.
            - `before` (str): Only containers created before a particular
                container. Give the container name or id.
            - `since` (str): Only containers created after a particular
                container. Give container name or id.

            A comprehensive list can be found in the documentation for
            `docker ps
            <https://docs.docker.com/engine/reference/commandline/ps>`_.`

Most helpful comment

Hello @GodQ it is possible to query multiple labels by passing a list with the label key in the filters dictionary.
For instance

client.containers.list(filters={"label":["foo=1", "bar=2"]})

This is equivalent to

docker ps -f label="foo=1" -f label="bar=2"

All 3 comments

Hello @GodQ it is possible to query multiple labels by passing a list with the label key in the filters dictionary.
For instance

client.containers.list(filters={"label":["foo=1", "bar=2"]})

This is equivalent to

docker ps -f label="foo=1" -f label="bar=2"

Hello @GodQ it is possible to query multiple labels by passing a list with the label key in the filters dictionary.
For instance

client.containers.list(filters={"label":["foo=1", "bar=2"]})

This is equivalent to

docker ps -f label="foo=1" -f label="bar=2"

Thank you very much!

Issue resolved

Was this page helpful?
0 / 5 - 0 ratings