Learning paths / Containers / Images and layers

Try it: inspect an image's layers

Reading · 12 min · Module 2, lesson 4 of 517 min left in this module

Module 2 · Images and layersLesson 4 of 5

Goal: Read an image's layers with docker history, and its size with docker image ls.

You need Docker running (set up in lesson 3.1.1), and about 2 GB of free disk space for a few minutes.

Check Docker, and what differs by machine

Run docker version. If it prints a Server section, Docker is running. If it says it can't connect, start Docker Desktop (macOS, Windows) or the Docker service (Linux) and try again.

Recent Docker versions show two size columns, DISK USAGE and CONTENT SIZE; older ones show one SIZE column, which is the disk usage. Numbers here are from Docker 29, and small differences on your machine are normal.

  1. Pull the lab image

    docker pull quay.io/computesphere/learn-hello-web:1.0.0
    

    Docker downloads only the layers it doesn't already have. If you've pulled this image before, it says Image is up to date instead.

    You should seeone or more lines ending in Pull complete, then Digest: sha256:5491c5ca… and Status: Downloaded newer image for quay.io/computesphere/learn-hello-web:1.0.0

  2. List its layers

    docker history quay.io/computesphere/learn-hello-web:1.0.0
    

    Read it bottom to top: that's the order the layers were built. The bazel build rows are the distroless base; the COPY is the app itself, one compiled file. Rows at 0B change settings, not files.

    You should see17 rows. The top five are ENTRYPOINT, USER, EXPOSE and ENV at 0B, and a COPY of 5.07MB. Below them, twelve bazel build rows, the largest tzdata at 4.24MB.

  3. See its size

    docker image ls quay.io/computesphere/learn-hello-web
    

    Content size is what's downloaded, compressed. Disk usage is what it takes up once unpacked.

    If you pulled it by digest in the last lesson, there's a second row ending in @sha256:5491c5ca…, with the same ID: one image, two names.

    You should seeDISK USAGE 12.9MB and CONTENT SIZE 2.36MB (or one SIZE column of 12.9MB).

  4. Pull a full base image for contrast

    docker pull node:22
    

    This is the full Node image from the last lesson, with no app in it at all.

    You should seeeight layers, each ending in Pull complete, then Status: Downloaded newer image for node:22. This takes a minute or two.

  5. List its layers

    docker history node:22
    

    The apt-get layers are compilers, libraries and tools, installed so that any package can build. Your app would sit on top of all of it.

    Check yourself

    Which part of node:22 would your running app actually use?

    You should see12 rows. The largest is a RUN layer that installs packages with apt-get, about 590MB, then Node itself at about 210MB, and the Debian base at the bottom at about 150MB.

  6. Compare the sizes

    docker image ls node:22
    

    You should seeDISK USAGE about 1.6GB and CONTENT SIZE about 410MB: over a hundred times the lab image, before any app is added.

  7. Clean up

    docker rmi node:22
    

    Keep learn-hello-web: you'll run it in the next module.

    You should seeUntagged: node:22, then a Deleted: sha256:… line.