How to find the docker-compose.yml that used to start containers?

Viewed 4066

I want to stop some docker containers through a docker-compose.yml start.

But I don't know where is the docker-compose.yml that used to start these containers.

How to find the docker-compose.yml through containers?

Thanks.

2 Answers

It’s not persisted anywhere; certainly an individual container doesn’t know whether it was started through Docker Compose, the docker run CLI, or some other path. If you can’t find(1) or otherwise locate the docker-compose.yml file then you can’t use Docker Compose to manage the container.

That having been said, once Docker Compose starts a container, it’s an ordinary container, so you can use docker ps to find it and docker stop; docker rm to clean it up, just like any other container. The flip side of Compose not keeping the state to manage containers if you’ve lost its YAML file is that it also doesn’t really know or care if you stop containers by hand.

  • Find the image using docker ps -a
  • Then inspect the image docker image history --no-trunc image_name
Related