There’s a common case when you need to get IDs of your compose project containers. For example to perform docker inspect command for some debugging purposes.

When you execute docker-compose ps the columns you’ll see are: Name, Command, State, Ports. The problem is that you won’t see the ID column in the output anywhere.

However there’re two options available to use with this command:

  • docker-compose ps --services to list service names only
  • docker-compose ps --quite to list service IDs only.

The funny thing here is that they can not be used together. So we need to merge their output somehow.

To list all the services inside of a docker-compose project use:

docker-compose ps --services \
| awk '{ print "echo -n \""$1": \" ; docker-compose ps -q "$1 }' \
| bash
  • docker-compose ps --services - list all service names without a project name prefix
  • grep -v 'Name' | grep -v -- "-----" - omit both Name and delimiter lines
  • awk... - print service name beside with service id
  • docker-compose ps -q <service-name> - get ID of a service

The example output you’ll see will be somewhat like:

app: a58cd49ea1abf8df73c786241269b596a54ae95e89d2596620f8faf9665646e1
db: f5f4cc8d9e161d98e43d5943145610b86af4a490145b93fc8d92ec72b07022a2
proxy: b086f0433b0e1a4a9d029298dc81055c67145957fcd045a4b0bfa220e1c5daba