Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I identify which container owns which overlay directory?

Tags:

docker

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?

like image 312
Matthew Avatar asked Jun 15 '18 12:06

Matthew


People also ask

What is the Docker overlay directory?

Overlay filesystems (also called union filesystems) is a fundamental technology in Docker to create images and containers. They allow creating a union of directories to create a filesystem. Multiple filesystems, which are just directories, are superposed one on top of another to create a new filesystem.

What is overlay in container?

The overlay network driver creates a distributed network among multiple Docker daemon hosts. This network sits on top of (overlays) the host-specific networks, allowing containers connected to it (including swarm service containers) to communicate securely when encryption is enabled.


1 Answers

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.

like image 62
Matthew Avatar answered Sep 17 '22 11:09

Matthew