Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find docker file path according to container id

Tags:

docker

I want to download Docker container logs to my local. I know my container's container id.

Now, I use df -h to find the docker file path. Like this /data/docker/overlay2/ea3e1ad0ccdee0e41d83722dfc6bf913250abd57918fecabd1067736b3e44305/merged. But I have multiple containers, it is difficult to know my container's file path.

How can I know ea3e1ad0ccdee0e41d83722dfc6bf913250abd57918fecabd1067736b3e44305 according to my container id.

like image 237
Shui shengbao Avatar asked Dec 04 '22 19:12

Shui shengbao


1 Answers

You can find the image layers associated with the containers using docker inspect.

There might be a cleaner solution, but I was able to find the container id with some help from xargs and jq.

docker ps -a -q | xargs docker inspect | jq '.[] | select(.GraphDriver.Data.LowerDir | contains("ea3e1ad0ccdee0e41d83722dfc6bf913250abd57918fecabd1067736b3e44305")) | .Id'
  • docker ps -a -q to grab a list of all the container Ids.
  • xargs docker inspect to get the details of each container.
  • jq to search the list and return the Id of any containers referencing the image layer in the GraphDriver object.
like image 100
Jason Greathouse Avatar answered Jan 09 '23 16:01

Jason Greathouse