• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Docker | Image Filesystem
  1. Inspect Image Filesystem
  2. Show the history of an image
  3. Export the files of an image
  4. Using dive tool to explore images

  1. Inspect Image Filesystem
    To inspect an image, use the command "image inspect":
    $ docker image inspect hello-world:latest | jq '.'
    [
      {
        "Id": "sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b",
        "RepoTags": [
          "hello-world:latest"
        ],
        "RepoDigests": [
          "hello-world@sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2020-01-03T01:21:37.263809283Z",
        "Container": "71237a2659e6419aee44fc0b51ffbd12859d1a50ba202e02c2586ed999def583",
        "ContainerConfig": {
          "Hostname": "71237a2659e6",
          "Domainname": "",
          "User": "",
          "AttachStdin": false,
          "AttachStdout": false,
          "AttachStderr": false,
          "Tty": false,
          "OpenStdin": false,
          "StdinOnce": false,
          "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ],
          "Cmd": [
            "/bin/sh",
            "-c",
            "#(nop) ",
            "CMD [\"/hello\"]"
          ],
          "ArgsEscaped": true,
          "Image": "sha256:eb850c6a1aedb3d5c62c3a484ff01b6b4aade130b950e3bf3e9c016f17f70c34",
          "Volumes": null,
          "WorkingDir": "",
          "Entrypoint": null,
          "OnBuild": null,
          "Labels": {}
        },
        "DockerVersion": "18.06.1-ce",
        "Author": "",
        "Config": {
          "Hostname": "",
          "Domainname": "",
          "User": "",
          "AttachStdin": false,
          "AttachStdout": false,
          "AttachStderr": false,
          "Tty": false,
          "OpenStdin": false,
          "StdinOnce": false,
          "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ],
          "Cmd": [
            "/hello"
          ],
          "ArgsEscaped": true,
          "Image": "sha256:eb850c6a1aedb3d5c62c3a484ff01b6b4aade130b950e3bf3e9c016f17f70c34",
          "Volumes": null,
          "WorkingDir": "",
          "Entrypoint": null,
          "OnBuild": null,
          "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 13336,
        "VirtualSize": 13336,
        "GraphDriver": {
          "Data": {
            "MergedDir": "/var/lib/docker/overlay2/0217d9fbfbd6fa9211ce017c01fa45e1c4acba6ed88be794089457f0f2679eb6/merged",
            "UpperDir": "/var/lib/docker/overlay2/0217d9fbfbd6fa9211ce017c01fa45e1c4acba6ed88be794089457f0f2679eb6/diff",
            "WorkDir": "/var/lib/docker/overlay2/0217d9fbfbd6fa9211ce017c01fa45e1c4acba6ed88be794089457f0f2679eb6/work"
          },
          "Name": "overlay2"
        },
        "RootFS": {
          "Type": "layers",
          "Layers": [
            "sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63"
          ]
        },
        "Metadata": {
          "LastTagTime": "0001-01-01T00:00:00Z"
        }
      }
    ]
    You can look at the "GraphDriver.Data" element in the json output and use the data directories to list the contents of the image:
    $ sudo ls -al /var/lib/docker/overlay2/0217d9fbfbd6fa9211ce017c01fa45e1c4acba6ed88be794089457f0f2679eb6/diff
    -rwxrwxr-x 1 root root 13336 Jan  2  2020 hello
    The "RootFS.Layers" element list the image layers:
    $ docker image inspect hello-world:latest --format '{{json .RootFS.Layers }}'
    ["sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63"]
  2. Show the history of an image
    Let's have a look at the image history:
    $ docker image history hello-world:latest --no-trunc
    IMAGE                                                                     CREATED        CREATED BY                SIZE      COMMENT
    sha256:0b6a027b5cf322f09f6706c754e086a232ec1ddba835c8a15c6cb74ef0d43c29   4 months ago   CMD ["/hello"]            0B        buildkit.dockerfile.v0
    <missing>                                                                 4 months ago   COPY hello / # buildkit   16.4kB    buildkit.dockerfile.v0
    The hello-world docker image contains only the layers of the base image (hello-world).
    You can see the layers created by the COPY and CMD instructions.

    If you look at the Dockerfile of the "hello-world" image, you will notice that it only copy the "hello" file:
    FROM scratch
    COPY hello /
    CMD ["/hello"]
  3. Export the files of an image
    To export the files of an image, use the command "docker container export" on a running container.

    Let's create a container and export its contents:
    $ docker container export $(docker container create hello-world) | tar -tv
    -rwxr-xr-x 0/0       0 .dockerenv
    drwxr-xr-x 0/0       0 dev/
    -rwxr-xr-x 0/0       0 dev/console
    drwxr-xr-x 0/0       0 dev/pts/
    drwxr-xr-x 0/0       0 dev/shm/
    drwxr-xr-x 0/0       0 etc/
    -rwxr-xr-x 0/0       0 etc/hostname
    -rwxr-xr-x 0/0       0 etc/hosts
    lrwxrwxrwx 0/0       0 etc/mtab -> /proc/mounts
    -rwxr-xr-x 0/0       0 etc/resolv.conf
    -rwxrwxr-x 0/0   13336 hello
    drwxr-xr-x 0/0       0 proc/
    drwxr-xr-x 0/0       0 sys/
    The "hello" file is the only non-empty file in the container.

    The other files and directories in the container are mandatory (required by the kernel). They all show zero bytes in length and Docker will automatically bind-mount them from the Docker host into the container when it's created.
  4. Using dive tool to explore images
    See this page for more details about dive tool: https://github.com/wagoodman/dive

    Installing dive on Ubuntu:
    $ DIVE_VERSION=$(curl -sL "https://api.github.com/repos/wagoodman/dive/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
    $ curl -fOL "https://github.com/wagoodman/dive/releases/download/v${DIVE_VERSION}/dive_${DIVE_VERSION}_linux_amd64.deb"
    $ sudo apt install ./dive_${DIVE_VERSION}_linux_amd64.deb
    Using dive:
    $ dive hello-world:latest
    dive screenshot - ubuntu image latest
© 2025  mtitek