57

My /var/lib/docker/overlay directory contains data for my containers but the directory names are all hashed. How can I determine which container owns which overlay?

3 Answers 3

68

You can use jq like so:

 docker inspect $(docker ps -qa) |  jq -r 'map([.Name, .GraphDriver.Data.MergedDir]) | .[] | "\(.[0])\t\(.[1])"'

Which gives:

/traefik_traefik_1      /var/lib/docker/overlay/58df937e805ec0496bd09686394db421c129e975f67180e737d5af51751af49c/merged
/gitlab-runner  /var/lib/docker/overlay/4e5b06f4ee09c60e2dad3a0ce87352cead086eb8229775f6839a477b46dce565/merged
/rancher-agent  /var/lib/docker/overlay/6026bb65dd9a83c2088a05cff005a1dd824494222445bab46b7329dc331465aa/merged

Explanation:

docker inspect $(docker ps -qa)

Display full docker details.

jq -r

Parse json and output regular strings:

map([.Name, .GraphDriver.Data.MergedDir])

For each element in the original array, find the Name and the overlay MergedDir.

"\(.[0])\t\(.[1])"

Output the first two elements of the array.

1
  • 4
    You can also use it with docker inspect $(docker image ls -aq) to search for image layers
    – Gaël J
    Commented May 12, 2020 at 10:10
46

Thanks to @Matthew for his solution. It made me think of a Docker-only solution (without jq):

docker inspect -f $'{{.Name}}\t{{.GraphDriver.Data.MergedDir}}' $(docker ps -aq)

You can also ask for a specific container using

docker inspect -f $'{{.Name}}\t{{.GraphDriver.Data.MergedDir}}' <container_name>

Explanations

I use the -f option of Docker inspect that allows me to use a Go template to format the output of docker inspect.

I use $'' in Bash to allow special chars like \t in my format.

1
  • 1
    For image overlays: docker inspect -f "{{.RepoTags}} {{.GraphDriver}}" $(docker images -q)
    – Arnie97
    Commented Mar 19, 2022 at 4:23
8
docker ps -qa | xargs -I{} bash -c "docker inspect {} | grep <hash> && echo {}"

which would give you, for example,

    "LowerDir": "...<hash>...",
    "MergedDir": "...<hash>...",
    "UpperDir": "...<hash>...",
    "WorkDir": "...<hash>..."
24f8ab7ae838

Now you can tell the container 24f8ab7ae838 owns the overlay <hash>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.