Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 571
Stefan Avatar asked Feb 08 '17 08:02

Stefan


People also ask

Where is the Docker compose yml file located?

The Compose file is a YAML file defining services, networks and volumes. The default path for a Compose file is ./docker-compose.


2 Answers

The answer to this question seems to have changed with new versions of docker-compose. There is a label "com.docker.compose.project.working_dir": "/var/opt/docker", that points to the directory where I started docker-compose. I have not checked if that is pwd or the actual location of the docker-compose.yml file.

This got me interesting information about docker-compose:

 samuel@vmhost1:~$ docker inspect fc440a1afbaa | grep com.docker.compose                 "com.docker.compose.config-hash": "89069285a4783b79b421ea84f2b652becbdee148fbad095a6d9d85aab67ececc",                 "com.docker.compose.container-number": "1",                 "com.docker.compose.oneoff": "False",                 "com.docker.compose.project": "docker",                 "com.docker.compose.project.config_files": "docker-compose.yml",                 "com.docker.compose.project.working_dir": "/var/opt/docker",                 "com.docker.compose.service": "jenkins",                 "com.docker.compose.version": "1.25.0" samuel@vmhost1:~$  

I'm running docker-compose.yml configuration version 3.6

like image 75
Samuel Åslund Avatar answered Oct 08 '22 11:10

Samuel Åslund


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)
like image 34
Thibault Loison Avatar answered Oct 08 '22 10:10

Thibault Loison