Struggling with the lacking documentation at $DAY_JOB, I have figured out that I need to use one of our docker images that contain a specific *.so file. Let’s call it "libimportant.so".
A search with find
reveals that the file exists in a local docker layer in my dev environment:
$ sudo find / -name libimportant.so 2>/dev/null
/var/lib/docker/overlay2/fedc8afc375f5bf02c74542b5d3a2621fcfd522875dff06bbb63fff6d1251234/diff/usr/lib64/libimportant.so
I have over 200 docker images locally (according to docker image ls | wc -l
).
Question: How do I figure out which docker image (or docker images) that are using this docker layer?
NOTE: The environment currently has no containers running. This is a question about images, not containers.
I tried creating a container for each image, export the files, and search for the file in question. But this solution seems to take forever to run. It never run to completion.
$ docker image ls -qa | while read -r _hash; do _container="$(docker create "$_hash")"; docker container export "$_container" | tar t | grep -q 'libimportant.so' && echo "$_hash"; docker container rm "$_container" >/dev/null; done
^C
$
I also tried to list the GraphDriver data for each image, and grep for the overlay hash. But that didn’t find any matches.
$ docker image ls -qa | while read -r imageid; do docker image inspect --format '{{json .GraphDriver.Data}}' "$imageid" | grep -q 'fedc8afc375f5bf02c74542b5d3a2621fcfd522875dff06bbb63fff6d1251234' && echo "$imageid"; done
$
docker version
$ docker version
Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:52 2020
OS/Arch: linux/amd64
Experimental: false
POST EDIT
The reason I could not find the image was because my /etc/docker/daemon.json
had reconfigured "data-root" from /var/lib/docker
to another directory.
Therefore the layers in /var/lib/docker/overlay2
was not used by any image listed with docker image ls
.
After correcting this, searching the GraphDriver.Data for each image actually worked.
2
Answers
As mentioned in my post edit, when I first tried to figure this out dockerd was using the wrong data-root.
Here is my solution using GraphDriver that worked for me, pretty printed:
You could do something like: