6

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"?

2 Answers 2

5

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"]'
6
  • 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. Commented Aug 19, 2020 at 9:50
  • Hi i just edited my post. The second grep commands should do this. Commented Aug 19, 2020 at 9: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", Commented Aug 19, 2020 at 9: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 <imageid>" , 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' Commented Aug 19, 2020 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 ? Commented Aug 19, 2020 at 10:12
1

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
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.