Images
100%

Docker · Lesson 2

Images

Learn how to read an image reference and check whether the referenced image is available locally.

A Docker image packages a program, its files, and default settings. Docker uses that package as the starting point for a container. Here you will read image names and find out which images Docker already has.

Reading an Image Name and Tag

In nginx:alpine, nginx is the image name and alpine is the tag, a label used to select a particular release or variant. Here it selects a variant built on Alpine Linux. The colon separates the name from the tag. nginx:alpine and nginx:latest are different references to the same image name.

In busybox:1.36, which part is the tag?

Choosing a Tag

When you omit the tag from a reference such as nginx, Docker uses latest. That is a tag name chosen by convention. A publisher can decide which image a tag points to and can update it later. Using nginx:alpine states which variant you want, even though that tag can receive updates too.

A colleague runs nginx without a tag and assumes Docker chose the newest release. What did the reference actually select?

Downloading an Image

A registry stores and serves images. Docker Hub is the registry Docker uses by default for references such as nginx:alpine. To download an image to the Docker environment you are connected to, use docker pull. Downloading is sometimes called pulling an image.

$ docker pull nginx:alpine

After this command succeeds, the image is available there. Starting a container is a separate action. In transcript examples, the $ is the terminal prompt.

An image pull finishes successfully. What has Docker done?

Checking Local Images

Use docker image ls to see images already available. This example shows just the name and tag columns. Docker labels the image name column REPOSITORY.

$ docker image ls
REPOSITORY   TAG
nginx        alpine
busybox      1.36

The first row shows nginx:alpine. This table answers which images are present. It has no column for the state of a container created from those images.

LabEx Terminal showing docker pull and the repository and tag columns in docker image ls

The image list in this capture is filtered to the two references used in the lesson.

Which reference is shown as available in this output?

Lesson complete

You finished Images

You can now read an image reference and check whether it appears in the local image list.

  • Identify the name and tag in an image reference.

  • Explain what happens when you leave out the tag.

  • Use docker pull to download an image from a registry.

  • Read the name and tag columns in docker image ls.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Docker