Skip to content
Laviyx Learn

Try

Docker and Kubernetes course menu

Docker Images Explained: Pull, List, Tag and Remove

Understand Docker images: repositories and tags, docker pull, listing and inspecting images, slim and Alpine variants, image history, and freeing disk space.

Beginner6 min readUpdated
On this page

An image is a read-only template for containers. It contains a small file system with an app and its libraries, plus settings such as which command to run.

Image names#

Text
python:3.13-slim
  |      |
  |      +-- tag: a version or variant
  +--------- repository: the name

ghcr.io/your-name/app:1.2.0
   |        |     |     |
   |        |     |     +-- tag
   |        |     +-------- image name
   |        +-------------- account
   +----------------------- registry

Without a registry, Docker uses Docker Hub. Without a tag, it uses latest.

Pull and list#

docker pull downloads an image without running it:

Terminal
docker pull -q alpine:3.24
docker pull -q python:3.13-slim
docker pull -q python:3.13-alpine
docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.Size}}'
Output
docker.io/library/alpine:3.24
docker.io/library/python:3.13-slim
docker.io/library/python:3.13-alpine
REPOSITORY   TAG           SIZE
python       3.13-slim     118MB
python       3.13-alpine   45.7MB
alpine       3.24          8.42MB

Choosing a variant#

Official images come in several flavours:

TagBased onNotes
python:3.13Full DebianLarge; includes build tools
python:3.13-slimMinimal DebianA good default
python:3.13-alpineAlpine LinuxSmallest, but it uses different system libraries, so some packages are harder to install

Smaller images download faster and contain less that can be attacked.

Inspect an image#

docker inspect shows an image's settings. --format picks out a value:

Terminal
docker inspect --format '{{.Os}}/{{.Architecture}}' alpine:3.24
docker inspect --format '{{json .Config.Cmd}}' python:3.13-slim
Output
linux/amd64
["python3"]

Cmd is the command that runs by default, which is why a plain docker run python:3.13-slim would start Python.

Layers#

An image is built from layers. Each one records a change to the file system, and images that share a base also share its layers on disk:

Terminal
docker history --format '{{.Size}}\t{{.CreatedBy}}' alpine:3.24 | cut -c1-60
Output
0B	CMD ["/bin/sh"]
8.42MB	ADD alpine-minirootfs-3.24.3-x86_64.tar.gz /…

You will see why this matters in Layers, Cache and .dockerignore.

Running an image with another command#

Terminal
docker run --rm python:3.13-slim python -c "print(sum(range(101)))"
Output
5050

You did not install Python on your computer. This is useful for trying a tool or a version without installing it.

Tag an image#

docker tag gives an image another name. No data is copied, and both names have the same ID:

Terminal
docker tag alpine:3.24 my-base:1.0
docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep -E 'alpine:3.24|my-base'
Output
alpine:3.24 b92841763c5c
my-base:1.0 b92841763c5c

Remove images#

Terminal
docker rmi my-base:1.0
docker image prune -f
Output
Untagged: my-base:1.0
Total reclaimed space: 0B

docker rmi removes a name, and deletes the image if no names are left. docker image prune removes "dangling" images, which have no name. Add -a to remove all images not used by a container.

Check how much space Docker is using:

Terminal
docker system df --format 'table {{.Type}}\t{{.TotalCount}}\t{{.Size}}' | head -n 3
Output
TYPE            TOTAL     SIZE
Images          3         164MB
Containers      0         0B

docker system prune removes stopped containers, unused networks, and dangling images. It asks you to confirm first.

Finding images#

Search on hub.docker.com. Prefer Docker Official Images and Verified Publishers. Anyone can publish an image, so treat others with care, as you would any program from the internet.

Common mistakes#

Practice#

Practice exercise

Pull redis:8.6-alpine, print its size, and print the default command using docker inspect.

Show solution
Terminal
docker pull -q redis:8.6-alpine
docker images redis --format '{{.Size}}'
docker inspect --format '{{json .Config.Cmd}}' redis:8.6-alpine
Output
docker.io/library/redis:8.6-alpine
98.1MB
["redis-server"]

Key takeaway#

Next: Managing Containers.

Finished this lesson?

Some links are affiliate links. If you buy through them, Laviyx Learn may earn a commission at no extra cost to you. As an Amazon Associate, we earn from qualifying purchases.