How can I list docker containers by application? For example, assume that I have app1 (that has c1, c2, c3) and app2 (that has c4, c5) deployed. I can see c1, c2 and c3 are under app1 and c4 and c5 are under app2 using docker dashboard. But, if I do "docker ps", it returns a flat list of containers, I have no way to know which containers belong to which app? Below is an example.
As can be seen in docker dashboard on the left side, there are two applications, nginx-gohttp-master and demo, deployed in the docker environment. The first app has two containers and the second app has four containers, and the two apps are independent of each other. However, I only see a flat list of containers on the right side as listed by "docker ps". I would like to know how many apps are deployed and which containers belong to which app. How can I do that using a docker command line tool?
Thanks
2
Answers
By default,
docker-compose
adds some labels includingcom.docker.compose.project
which contains the name of the compose app/project. You can get that output usingdocker ps
with the--format
option like so:You can see some of the other labels that
docker-compose
applies here.Check out filters
Apparently there’s no need for a wildcard character
*
, because=
is not a direct exact-match string equality but a sub-string search.For an exact match (which is not what you want in your question) you need to pipe the result into something else as discussed here.