Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

How to identify which Docker container an overlay is for?

+2
−0

Docker stores data under directories like /var/lib/docker/overlay2/xyz123. These sometimes grow very large, and Docker does not provide good instructions for how to easily manage the space used by these. I assume IDs like xyz123 somehow correspond to containers.

Occasionally, I notice that one of these is very large, eg. 10 GB. If all I know is the path of the overlay dir, how can I figure out which container this was for, so I can decide if it's something that I can clean up?

Note: When this point is brought up, it often conjures long arguments about whether it's bad to mess with these overlay dirs manually. I'm not asking about deleting them manually in this question, so let's not get into that here. I am only asking how to identify which container/image is responsible for a given overlay directory.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Pruning (2 comments)

1 answer

+1
−0

You can find that when you run docker inspect $CONTAINER. You can automate this with a simple loop like this:

for CONTAINER in $(docker ps -qa);
    do docker inspect $CONTAINER |grep -q $DIRNAME && docker ps -a |grep $CONTAINER;
done

where $DIRNAME is the overlay directory name.

This will loop over all containers, grep the output of docker inspect on it and if it finds the directory name it will run grep with the container ID on the output of docker ps -a, showing the container where it is mounted.

If you don't get any output the container where it belonged to doesn't exist anymore.

Example:

root@host:/var/lib/docker/overlay2# ls -1
e9341f72f22128ceeed7373a36bce28d02751bd0c51e60e1deaa8f77903f2f35
root@host:/var/lib/docker/overlay2# for CONTAINER in $(docker ps -qa); do docker inspect $CONTAINER |grep -q e9341f72f22128ceeed7373a36bce28d02751bd0c51e60e1deaa8f77903f2f35 && docker ps -a |grep $CONTAINER; done
458f26e907ff wordpress "docker-entrypoint.s…"   11 months ago   Up 12 days  0.0.0.0:8081->80/tcp, [::]:8081->80/tcp   wordpress-wordpress-1
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Works for me (3 comments)

Sign up to answer this question »