I have several docker-compose.yml files, running ok with docker-compose up, individually.
Each docker-compose runs several containers.
After they are up, I can't see what containers are up with docker ps.
I can see something with docker-compose ps, but only for a specific docker-compose.yml.
I want access to global polling of the containers state.
How can I list all running containers, no matter their origin?
Docker compose adds labels to each container that it creates. If you want to get all containers created by compose, you can perform a container ls and apply a filter.
docker container ls --filter label=com.docker.compose.project
This will show all running container created by compose, regardless of the project name.
For example, I created some containers from different compose projects. With the filter, I get only those, but no other container that have not been created by compose and therefore don't have a project label.
$ base='{{.Status}}\t{{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}\t{{.Networks}}\t{{.Mounts}}'
$ compose='{{.Label "com.docker.compose.project"}}\t{{.Label "com.docker.compose.service"}}'
$ docker container ls --all \
--filter label=com.docker.compose.project \
--format "table $compose\t$base"
project service STATUS CONTAINER ID NAMES IMAGE PORTS NETWORKS MOUNTS
kafka kafka Up 5 minutes 3f97a460266e kafka_kafka_1 bitnami/kafka:3 0.0.0.0:9092->9092/tcp, :::9092->9092/tcp kafka_default kafka_kafka_da…,kafka_kafa_con…
kafka zookeeper Up 5 minutes 0b6f32ccd196 kafka_zookeeper_1 bitnami/zookeeper:3.7 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 8080/tcp kafka_default kafka_zookeepe…
manager db Up 22 minutes 4f0e799b4fd7 manager_db_1 da2cb49d7a8d 5432/tcp manager_default 0d667a0e48a280…
foo db Exited (0) 37 minutes ago e106c5cdbf5e foo_db_1 da2cb49d7a8d foo_default 5a87e93627b8f6…
foo backend Up 10 minutes 08a0873c0587 foo_backend_2 c316d5a335a5 80/tcp foo_default
foo frontend Up 10 minutes be723bf41aeb foo_frontend_1 c316d5a335a5 80/tcp foo_default
foo backend Up 10 minutes 5d91d4bcfcb3 foo_backend_1 c316d5a335a5 80/tcp foo_default
manager app Up 22 minutes 2ca4c0920807 manager_app_1 c316d5a335a5 80/tcp manager_default
manager app Up 22 minutes b2fa2b9724b0 manager_app_2 c316d5a335a5 80/tcp manager_default
loadbalancer app Exited (0) 37 minutes ago 791f4059b4af loadbalancer_app_1 c316d5a335a5 loadbalancer_default
If you want to see all container regardless of their state, you can add the --all or short -a flag to the ls command, like I did in my example. Otherwise, only running containers are shown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With