skip to Main Content

I was wondering if it would be possible to list all running docker-compose files with a bash function? Something like docker ps or docker container ls, but I want it to show the files only.

I got started with this – lsof | egrep 'REG|DIR' | awk '{print $9}' but this provides me tons of unwanted information as well.

What would be the best approach here?

Thanks in advance.

3

Answers


  1. Chosen as BEST ANSWER

    So I played around with docker inspect and came up with that:

    for c in `docker ps -q`; do echo $c; docker inspect $c --format '{{index .Config.Labels "com.docker.compose.project.config_files"}}' ; done
    

    So it is possible ;)


  2. It is not possible to backtrack and find the docker-compose file that was used in container deployment. To overcome such issues, a project pipeline is recommended using tools like maven, jenkins, gradle etc along with a repository platform like github. If its a personal project you can organize your project by wrapping the docker deployment commands and source files in a script and only use them to create deployments. This way it will be organized to some extent.

    Login or Signup to reply.
  3. This bash oneliner shows the working dir of each container’s compose file.

    for c in `docker ps -q`; do echo $c; docker inspect $c --format '{{index .Config.Labels "com.docker.compose.project.working_dir"}}' ; done
    

    I edited kvelev’s command to get this. kvelev’s command was just printing "docker-compose.yaml" for each of my loaded containers, so I edited the filter to show the working dir, which works for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search