How to use docker scout watch command to monitor container images

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to effectively use the docker scout watch command to monitor container images. You will explore various scenarios, starting with watching a specific repository for new images, then refining your monitoring by filtering by tag. You will also learn how to extend your watch to encompass all repositories within a registry and finally, how to initiate a watch that includes all existing images in a repository. Through hands-on exercises, you will gain practical experience in setting up and managing image monitoring with Docker Scout.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ImageOperationsGroup(["Image Operations"]) docker/ImageOperationsGroup -.-> docker/pull("Pull Image from Repository") docker/ImageOperationsGroup -.-> docker/tag("Tag an Image") docker/ImageOperationsGroup -.-> docker/push("Push Image to Repository") docker/ImageOperationsGroup -.-> docker/images("List Images") docker/ImageOperationsGroup -.-> docker/search("Search Images in Repository") subgraph Lab Skills docker/pull -.-> lab-555218{{"How to use docker scout watch command to monitor container images"}} docker/tag -.-> lab-555218{{"How to use docker scout watch command to monitor container images"}} docker/push -.-> lab-555218{{"How to use docker scout watch command to monitor container images"}} docker/images -.-> lab-555218{{"How to use docker scout watch command to monitor container images"}} docker/search -.-> lab-555218{{"How to use docker scout watch command to monitor container images"}} end

Watch a specific repository for new images

In this step, you will learn how to watch a specific Docker repository for new images using the docker pull command. This is a fundamental operation in Docker, allowing you to download images from a registry to your local machine.

First, let's pull a specific image from the Docker Hub registry. We will use the hello-world image, which is a very small image used for testing Docker installations.

docker pull hello-world

You should see output indicating that the image is being pulled and downloaded.

Using default tag: latest
latest: Pulling from library/hello-world
...
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

This command tells Docker to download the hello-world image with the latest tag from the default registry (Docker Hub). If the image already exists locally, Docker will check if a newer version is available and download it if necessary.

Next, let's list the images you have on your local machine to confirm that the hello-world image has been downloaded.

docker images

You should see hello-world listed in the output.

REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    ...            ...            ...

This command shows you a list of all Docker images stored on your local machine, including their repository, tag, image ID, creation date, and size.

Now, let's try pulling the same image again. Since you already have the latest version of hello-world, Docker will not download it again.

docker pull hello-world

The output will indicate that the image is up to date.

Using default tag: latest
latest: Pulling from library/hello-world
Status: Image is up to date for hello-world:latest
docker.io/library/hello-world:latest

This demonstrates how docker pull checks for newer versions before downloading.

Watch a specific repository and filter by tag

In this step, you will learn how to watch a specific Docker repository and filter by tag when pulling images. Docker images often have different versions or variations identified by tags. Specifying a tag allows you to pull a particular version of an image.

In the previous step, we pulled the hello-world image with the default latest tag. Now, let's pull a different image, for example, the ubuntu image, and specify a particular tag. We will pull the 20.04 tag, which corresponds to the Ubuntu 20.04 LTS release.

docker pull ubuntu:20.04

You will see output indicating the download progress for the specified Ubuntu image tag.

20.04: Pulling from library/ubuntu
...
Status: Downloaded newer image for ubuntu:20.04
docker.io/library/ubuntu:20.04

This command tells Docker to download the ubuntu image specifically with the 20.04 tag. If you don't specify a tag, Docker defaults to latest.

Now, let's list your local images again to see the newly downloaded ubuntu:20.04 image.

docker images

You should now see both hello-world:latest and ubuntu:20.04 in the list.

REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    ...            ...            ...
ubuntu        20.04     ...            ...            ...

This shows that you have successfully pulled a specific version of the ubuntu image by specifying its tag.

You can also pull other tags of the same image. For instance, let's pull the 18.04 tag of the ubuntu image.

docker pull ubuntu:18.04

Again, you will see the download progress.

18.04: Pulling from library/ubuntu
...
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04

Listing your images one more time will show all three images you've pulled.

docker images

The output will now include ubuntu:18.04.

REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    ...            ...            ...
ubuntu        20.04     ...            ...            ...
ubuntu        18.04     ...            ...            ...

This demonstrates how you can use tags to manage different versions of the same image on your local machine.

Watch all repositories in a registry

In this step, you will learn how to list repositories within a Docker registry. While docker pull is used for individual images, there isn't a single command to "watch" or list all repositories in a public registry like Docker Hub directly from the Docker CLI due to the sheer number of repositories. However, you can search for repositories based on keywords.

The docker search command allows you to search the Docker Hub registry for images. Let's search for images related to "nginx".

docker search nginx

You will see a list of repositories that match the search term "nginx".

NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        16000     [OK]
...

The output provides information about each matching repository, including its name, description, number of stars, and whether it's an official image or an automated build.

You can also filter the search results. For example, to see only official images related to "ubuntu", you can use the --filter flag.

docker search --filter is-official=true ubuntu

This command will show you only the official Ubuntu repositories.

NAME      DESCRIPTION                STARS     OFFICIAL   AUTOMATED
ubuntu    Ubuntu is a Debian-based...   14000     [OK]

While docker search doesn't list all repositories, it's the primary way to discover images within a registry using the Docker CLI. To get a comprehensive list of repositories in a large public registry like Docker Hub, you would typically need to use the registry's API or a web interface.

For the purpose of this lab, understanding how to search and discover images is key to finding the repositories you want to "watch" or pull images from.

Watch a repository and push all existing images

In this step, you will learn how to tag an existing image and push it to a Docker registry. Pushing images allows you to share your custom images or modified versions of existing images with others or store them in a remote location.

Before you can push an image, you need to tag it with the registry address, your username, and the repository name. We will use the ubuntu:20.04 image that you pulled in the previous step. Let's tag it for pushing to Docker Hub. Replace your_docker_username with your actual Docker Hub username.

docker tag ubuntu:20.04 your_docker_username/ubuntu:20.04

This command creates a new tag for the ubuntu:20.04 image. The new tag is your_docker_username/ubuntu:20.04. The format is [registry]/[username]/[repository]:[tag]. If you are pushing to Docker Hub, you can omit the registry part (docker.io/).

Now, list your local images again to see the new tag.

docker images

You should see an entry with your_docker_username/ubuntu as the repository and 20.04 as the tag, sharing the same image ID as the original ubuntu:20.04 image.

REPOSITORY                     TAG       IMAGE ID       CREATED        SIZE
hello-world                    latest    ...            ...            ...
ubuntu                         20.04     ...            ...            ...
ubuntu                         18.04     ...            ...            ...
your_docker_username/ubuntu    20.04     ...            ...            ...

Now that the image is tagged correctly, you can push it to your Docker Hub repository. Note: You will need to be logged in to Docker Hub to push images. If you are not logged in, the docker push command will fail. For the purpose of this lab, we will demonstrate the command, but you do not need to successfully push the image unless you have a Docker Hub account and are logged in.

docker push your_docker_username/ubuntu:20.04

If you are logged in, you will see output indicating the layers being pushed to the registry. If you are not logged in, you will receive an authentication error.

The push refers to repository [docker.io/your_docker_username/ubuntu]
...

This command uploads the image with the specified tag to your repository on Docker Hub.

While you cannot "watch" a repository and automatically push all existing images with a single command, you can achieve this by scripting the docker tag and docker push commands for the images you want to push.

Summary

In this lab, you learned the fundamental docker pull command to download container images from a registry, specifically demonstrating how to pull a specific image like hello-world and verify its presence using docker images. You also observed how Docker efficiently handles subsequent pull requests for the same image, only downloading if a newer version is available.