10

There is a smart way to get the list of services (or containers) of docker-compose files from inside of a container.

I would prefer not to using volumes, or passing statically the compose-file to container and parse it or pass a list with these infromations from environment variable.

One perfect result is given by docker-compose config --service, that returns the list of all services of compose but I don't know how to pass it to my container from the host.

(I would like get the list of all containers that they compose my application so I can monitor which go up and down with using registrator and consul).

aryanveer
  • 628
  • 1
  • 6
  • 17
user2972221
  • 376
  • 3
  • 15
  • Isn't the consul API enough? You can query by service name – Robert Jun 08 '17 at 12:21
  • if a container not goes up, i will never know nothing about it , is right? so i wish have a list of all container that compose my application..i don't want querying for a specific service. Maybe i can do that with consul..but i don't know how. Thanks. – user2972221 Jun 08 '17 at 13:45
  • @user2972221 Did you ever find the answer to this? – user1717828 Oct 09 '18 at 13:10
  • This post is old now, but wouldn't mounting the docker socket work just fine for this? – Zac Anger Jan 12 '21 at 21:52

1 Answers1

0

Please follow the instruction:

  1. Install yq on your machine. for instance, if your operating system is macOS/OSX brew install yq.
  2. Then run one of these commands: docker-compose config | yq '.services[]|key' or docker compose config | yq '.services[]|key'.

you will find the list of all available services.

Hossein Mayboudi
  • 395
  • 1
  • 4
  • 12