Search code examples
dockerdocker-compose

Get docker-compose.yml file location from running container?


I have a few running docker containers created by executing docker-compose up.

Is there any way to get the exact file path of the corresponding docker-compose.yml file used to start these containers, just by inspecting the running containers?

As far as I can see, docker inspect CONTAINER_NAME does not provide this information, nor does docker-compose provide a method to get compose-related information from a running container.

What I'd like to do in a script:

  • list certain running containers on a docker host
  • get the corresponding docker-compose.yml file locations
  • use docker-compose to restart all containers of the corresponding docker-compose projects at once

Solution

  • It is not currently possible.

    As an alternative might find the following helpful:

    • Use docker ps -a | grep <certain_container>
    • Use locate docker-compose.yml and find the one that you want
    • Use docker-compose restart (do docker-compose to see option)