Recently I needed to copy some files from a Docker image to trouble shoot some CI build artifact. I learned that it can be done via the docker cp command, which can be invoked like so:

id=$(docker create image-name)
docker cp $id:/path/inside-container /path/on-host
docker rm -v $id

We first run a container from a given image via docker create, which will run a new container and return its id.

Then we run docker cp, and pass it the id of the new container we spun up, as well as the path of the file/directory we want to copy from, as well the path we want to copy the file to on the host. Note that docker cp takes a container id and not a image, hence why we have to run the container via docker create first.

Finally, we can remove the container via docker rm for clean up.

If you need something more robust to inspect the files within the image layers, dive may be worth a look.