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

Post History

50%
+0 −0
Q&A How to identify which Docker container an overlay is for?

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...

posted 8d ago by GeraldS‭  ·  edited 8d ago by GeraldS‭

Answer
#2: Post edited by user avatar GeraldS‭ · 2024-11-13T10:39:29Z (8 days ago)
  • You can find that when you run `docker inspect $CONTAINER`. You can automate this with a simple loop like this:
  • ```bash
  • 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
  • Example:
  • ```console
  • 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
  • ```
  • You can find that when you run `docker inspect $CONTAINER`. You can automate this with a simple loop like this:
  • ```bash
  • 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:
  • ```console
  • 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
  • ```
#1: Initial revision by user avatar GeraldS‭ · 2024-11-13T10:32:29Z (8 days ago)
You can find that when you run `docker inspect $CONTAINER`. You can automate this with a simple loop like this:

```bash
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

Example:

```console
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
```