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.
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.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With