Skip to content
Lesson: Docker ImagesSwitch
← DevOps Operations

Delivery and containers

Docker Images

Pull, tag, list and remove images, and understand how layers and tags work.

An image is a read-only package holding a filesystem and settings such as the default command. A container is a running or stopped instance made from an image. You can create many containers from one image.

Pull an image

$ docker pull nginx:alpine
alpine: Pulling from library/nginx
...
Status: Downloaded newer image for nginx:alpine
docker.io/library/nginx:alpine

By default images come from Docker Hub, a public registry. A full name has this shape:

registry/namespace/repository:tag

For example, nginx:alpine is short for docker.io/library/nginx:alpine.

Tags and digests

A tag is a label such as alpine or 1.27. If you leave it out, Docker uses latest. That is only a default tag name; it does not promise the newest release. Whoever publishes an image can move a tag to different content.

When you need exactly the same bytes every time, use a digest:

$ docker pull nginx@sha256:<digest>

Replace <digest> with the long value that docker pull prints.

List images

$ docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        alpine    1e5f3c5b981a   2 weeks ago   48MB

docker images does the same. Newer Docker releases use a different column layout, and your IDs and sizes will differ.

Layers

Images are built from stacked layers. Images that share a layer store it once. See the steps behind an image with:

$ docker history nginx:alpine

Tag and remove

$ docker tag nginx:alpine mysite:v1
$ docker image rm mysite:v1
Untagged: mysite:v1

tag adds another name for the same image; it copies no data. Removing one name leaves the image while other names still refer to it.

Docker refuses to remove the last name of an image that a container still uses, even a stopped one, unless you force it. Remove the container first. docker image prune deletes dangling images, those with no tag that nothing uses.

Choose official or verified publisher images where you can, since you are running someone else's code.

Try it

Pull alpine, tag it as myalpine:test, list your images and compare the IDs. Remove the new tag and confirm that alpine is still there.

Check your understanding

Docker Images

All 4 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.