2

Is there a way to inspect a running Docker container? E.g., inspect the filesystem using a shell, etc?

To inspect an image, we could using docker run <tag> /bin/bash but I am looking to inspect a running container, not an image.

note that docker container inspect is not what I am looking for - that command just gives me metadata about the container.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

2 Answers2

3

You can use docker exec command

docker exec -it {container Id or name} command 
Mohsin Mehmood
  • 4,156
  • 2
  • 12
  • 18
3

Assuming that your container has a typical filesystem, you can just use docker exec to start a shell inside the container, as in:

docker exec -it mycontainer bash

Or if bash isn't available (for example, Alpine-based images):

docker exec -it mycontainer sh

Alternatively, you can export a container's filesystem as a tar archive using docker export. For example:

docker export -o mycontainer.tar mycontainer

And then you can inspect the archive or extract it as necessary. If you just want to a file listing, then:

docker export mycontainer | tar tf -
larsks
  • 277,717
  • 41
  • 399
  • 399
  • `docker export` does not export the contents of volumes associated with the container - which I suspect will be some of the most interesting files to the OP. – emory Jun 20 '18 at 01:04
  • That's true. If you need to see the contents of volumes, either stick with the `docker exec` variations, or mount the volumes into another container (using for example the `--volumes-from` option). – larsks Jun 20 '18 at 01:32