Docker-compose displaying all services not the one defined in docker-compose.yml

Cross-posting from stackoverflow as I did not get any response there.

I am executing docker-compose like below

docker-compose --compatibility -f docker-compose.yml up --scale es01=0 --scale elasticsearch-mapping-init=0 --scale analytics-db=0 

docker-compose --compatibility -f docker-compose.app.yml up --scale autocomplete-service=0 

After this when I am executing the below command it is displaying all services not just the ones defined in docker-compose.app.yml

docker-compose -f docker-compose.app.yml ps --services

Output

backoffice-db
booking-ending-db
booking-engine-service
master-service
objectstore-service
profile-service
sagev2-service
supplier-service
directory-db

docker-compose.app.yml has only the below services

version: '3'
    services: 
        master-service:
            image: master:latest
            network_mode: "host"
            restart: always
            environment:
                - SPOTNANA_ENV_TYPE=dev
                - IS_E2E=true
            ports:
                - "8080:8080"     # master-service
            deploy:
                resources:
                    limits:
                        memory: 1862M
    
        supplier-service:
            image: supplier:latest
            network_mode: "host"
            restart: always
            environment:
                - SPOTNANA_ENV_TYPE=dev
                - IS_E2E=true
            ports:
                - "6565:6565"     # supplier-service
            deploy:
                resources:
                    limits:
                        memory: 2960M
    
        booking-engine-service:
            image: bengine:latest
            network_mode: "host"
            restart: always
            environment:
                - SPOTNANA_ENV_TYPE=dev
                - IS_E2E=true
            ports:
                - "6569:6569"     # booking-engine-service
            deploy:
                resources:
                    limits:
                        memory: 2462M
  • Docker Compose version v2.6.0
  • aws/codebuild/standard:6.0

Can someone let me know why docker-compose -f docker-compose.app.yml ps --services not listing the services defined in docker-compose.app.yml only?

NOTE - I started seeing this problem only after moving to aws/codebuild/standard image 6.0 from 4.0. In image 6.0 docker-compose is upgraded to 2.6.0 from 1.26.0 in image 4.0.

Have you tried the same anyhere other than aws? Compose works as expected on my machine, although I have 2.13.0.

No I did not try anywhere other than AWS yet.

The below workaround is working in AWS with docker-compose v2.

Start docker cluster with -p

docker-compose --compatibility -f docker-compose.yml -p infra up --scale es01=0 --scale elasticsearch-mapping-init=0 --scale analytics-db=0 

docker-compose --compatibility -f docker-compose.app.yml -p app up --scale autocomplete-service=0 

Use -p in docker ps like below

docker-compose -p app ps --services

Also can you let me know how to upgrade to docker-compose v2 in Mac OS Ventura? I have started a new discussion for this.

Regarding -p== project name:

If you don’t provide a project name, the folder where the compose files are stored will be the project name. If you up the projects with and without specifying the project name, you will end up having the services running twice.

While your initial post used the fallback project name, It might explain why you saw all services that belong to the project name, rather than the services that belong to the compose file. If you had executed up again, it would complain about orphaned services and would ask whether it should remove them.

Your work around actually isn’t a workaround, it is the correct way to use it.

You can inspect the labels of a created container to see which project name it belongs to:

docker inspect ${container id or name} --format '{{json .Config.Labels}}' | jq

Check the value for the label com.docker.compose.project to see which project a container belongs to.

@meyay Is anything related to this changed in docker-compose v2?

In docker-compose 1.26.0 I was observing that docker-compose -f <compose file> ps --services showing correctly the services as defined in the compose file unlike in V2.

Okay I can confirm, this seems to be a bug in Docker Compose v2.6. I downloaded that version to my Mac and saw the same issue.

I also have to agree with @meyay that using the project name would be the correct way in case of docker compose up, but if you just want to see the state of some services in a specific compose file belonging to the only one project you have, this bug can be a problem.

If you just want to see the list of services defined in a specific compose file, you can use the config subcommand instead of ps

docker compose -f docker-compose.app.yml config --services

Based on that if you need the status of those services, the actual workaround would be something like this:

docker-compose -f docker-compose.app.yml ps $(docker-compose -f docker-compose.app.yml config --services)

It works because you can pass the service names after the “ps” subcommand.

You can do this, or upgrade docker compose to the latest version.

I will respond to the upgrade part in the other topic you opened.