Compose: Filter does not restrict list

Created on 1 Jun 2018  路  8Comments  路  Source: docker/compose

Description of the issue

Filtering argument for docker-compose ps seems to not work as expected. Apart from the fact that invalid keys/values provided do not show errors, filtering does work either for --filter status=running *except if you also use --services argument. To sum up:

  • docker-compose ps --filter "status=running" does not filter anything (KO)
  • docker-compose ps --filter "status=running" --services works as expected (OK)

Context information (for bug reports)

docker-compose version 1.20.1, build 5d8c71b
docker-py version: 3.1.4
CPython version: 3.6.4
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:17:38 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:15:45 2018
  OS/Arch:      linux/amd64
  Experimental: false
networks:
  network-for-static-ip:
    driver: bridge
    ipam:
      config:
      - gateway: 10.5.0.1
        subnet: 10.5.0.0/16
services:
  bdd_1:
    environment:
      MYSQL_ROOT_PASSWORD: root
    hostname: bdd_1
    image: mysql:5.6
    networks:
      network-for-static-ip:
        ipv4_address: 10.5.0.6
    ports:
    - 3308:3306/tcp
    volumes:
    - /docker/bdd_1/sql:/sql:rw
    - /docker/bdd_1/init:/docker-entrypoint-initdb.d:rw
  bdd_2:
    environment:
      MYSQL_ROOT_PASSWORD: root
    hostname: bdd_2
    image: mysql:5.6
    networks:
      network-for-static-ip:
        ipv4_address: 10.5.0.7
    ports:
    - 3309:3306/tcp
    volumes:
    - /docker/bdd_2/sql:/sql:rw
    - /docker/bdd_2/init:/docker-entrypoint-initdb.d:rw
  bdd_3:
    environment:
      MYSQL_ROOT_PASSWORD: root
    hostname: bdd_3
    image: mysql:5.6
    networks:
      network-for-static-ip:
        ipv4_address: 10.5.0.8
    ports:
    - 3310:3306/tcp
    volumes:
    - /docker/bdd_3/sql:/sql:rw
    - /docker/bdd_3/init:/docker-entrypoint-initdb.d:rw
  r1:
    environment:
      MYSQL_ROOT_PASSWORD: root
    hostname: r1
    image: mysql:5.6
    networks:
      network-for-static-ip:
        ipv4_address: 10.5.0.5
    ports:
    - 3307:3306/tcp
    volumes:
    - /docker/r1/sql:/sql:rw
    - /docker/r1/init:/docker-entrypoint-initdb.d:rw
version: '2.0'

Steps to reproduce the issue

  1. Start containers docker-compose up -d
  2. Exit one of the containers
  3. Compare outputs of docker-compose ps --filter "status=running" and docker-compose ps --filter "status=running" --services

Observed result

$ docker-compose ps --filter "status=running"

     Name                  Command             State            Ports         
------------------------------------------------------------------------------
docker_bdd_1_1   docker-entrypoint.sh mysqld   Up       0.0.0.0:3308->3306/tcp
docker_bdd_2_1   docker-entrypoint.sh mysqld   Up       0.0.0.0:3309->3306/tcp
docker_bdd_3_1   docker-entrypoint.sh mysqld   Up       0.0.0.0:3310->3306/tcp
docker_r1_1      docker-entrypoint.sh mysqld   Exit 1

$ docker-compose ps --filter "status=running" --services
bdd_1
bdd_2
bdd_3

Expected result

$ docker-compose ps --filter "status=running"

     Name                  Command             State            Ports         
------------------------------------------------------------------------------
docker_bdd_1_1   docker-entrypoint.sh mysqld   Up       0.0.0.0:3308->3306/tcp
docker_bdd_2_1   docker-entrypoint.sh mysqld   Up       0.0.0.0:3309->3306/tcp
docker_bdd_3_1   docker-entrypoint.sh mysqld   Up       0.0.0.0:3310->3306/tcp

$ docker-compose ps --filter "status=running" --services
bdd_1
bdd_2
bdd_3

Additional information

$ uname -r 
Linux ITK-P-201803-01 4.13.0-43-generic #48-Ubuntu SMP Wed May 16 12:18:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Docker-compose installed via curl from official website.

arecli kinenhancement kinquestion stale

Most helpful comment

Well indeed, I missed the fact that --filter applies only when combined with --services.

I think, and this is where it's related to #5821, is that:

  1. docker does not work the same way (eg --filter applies regardless of others arguments)
  2. There is no warning/error telling that the argument will be ignored. I did not check the code so I do not know if it could be easy to deal with, but that would be so valuable to user.

Thanks for the quick explanation regardless, much appreciated :).

All 8 comments

This is working as intended ; as docker-compose ps --help indicates, --filter applies to services, not containers.

That said, I'm open to an enhancement that would make filters available for the containers list as well, as I previously indicated: https://github.com/docker/compose/pull/5384#issuecomment-356144731

Well indeed, I missed the fact that --filter applies only when combined with --services.

I think, and this is where it's related to #5821, is that:

  1. docker does not work the same way (eg --filter applies regardless of others arguments)
  2. There is no warning/error telling that the argument will be ignored. I did not check the code so I do not know if it could be easy to deal with, but that would be so valuable to user.

Thanks for the quick explanation regardless, much appreciated :).

We are also seeing this.

Same here, tried to filter restarting containers with

docker-compose -f my.docker-compose.yml ps --filter "status=restarting"

and got all available containers

~https://docs.docker.com/engine/reference/commandline/ps/ gives examples of --filter without --service, e.g. docker ps --filter status=running.~

NVM, that document is about docker, not docker-compose.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because it had not recent activity during the stale period.

Was this page helpful?
0 / 5 - 0 ratings