1

A few containers which are started from a docker-compose file are running on the VM. but I don't know where is the docker-compose file, how to figure it out?

Furthermore, If there is a container start using "docker run", how to check the parameters used by "docker run"?

Jim
  • 111
  • 1

2 Answers2

2

Show running containers:

docker ps

Get Configurations of docker container

docker inspect <containerid>

Parsing the output to get only the run-command:

docker inspect <containerid> | jq -r '.[0]["Config"]["Cmd"][0]'

For your second part of question regarding finding the docker file:

docker inspect <containerid> | jq -r '.[0]["Config"]["Labels"]["com.docker.compose.project.working_dir"]'
Lorem ipsum
  • 852
  • 3
  • 13
  • Thanks. but I don't think it solves my problem. I would like to know which compose file is used by a running container. I can't check all the compose file on the machine. and I can't search all the compose file in the file system, the file may be in a folder I don't have access right. The 2nd question is, if I stop a container, rebuild it. I would like to start the container again using "docker run" with the same parameters, how can I do that. I don't think "docker inspect" give this information directly. – Jim Aug 19 '20 at 09:50
  • Hi i just edited my post. The second grep commands should do this. – Lorem ipsum Aug 19 '20 at 09:51
  • hmm, I don't have compose.project.working_dir and compose.config_files here is my output ******************************** docker inspect f8b5e2d46ece | grep compose "com.docker.compose.config-hash": "aea3d925be0cddea645a6640cf3a1565b5b1576c28bf61d7baa179732b1c9f59", "com.docker.compose.container-number": "3", "com.docker.compose.oneoff": "False", "com.docker.compose.project": "docker", "com.docker.compose.service": "worker", "com.docker.compose.version": "1.24.0-rc1", – Jim Aug 19 '20 at 09:55
  • regarding another one, ["Config"]["Cmd"] doesn't contains the information I need. For example, I start a contaner "docker run -e foo="bar" -v /tmp:/tmp --rm -d " , so I can see from docker inspect out that foo="bar" is set in ["Config"]["Env"], and /tmp:/tmp is in ["Mounts"], but there is not a place to show that the container start with '-e foo="bar" -v /tmp:/tmp --rm -d' – Jim Aug 19 '20 at 10:07
  • Is it possbile my docker and cocker-compose are too old? I still use docker 18.09, and docker-compose 1.24 ? – Jim Aug 19 '20 at 10:12
0

You can use -f, --format to save the use of jq.

Credits to https://forums.rancher.com/t/how-to-list-container-ip-with-docker-inspect-format/13044

docker inspect --format='{{index .Config.Labels "com.docker.compose.project.working_dir"}}' CONTAINER_ID
silencej
  • 111
  • 3