How to use docker checkpoint rm command to remove a checkpoint

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to manage Docker container checkpoints. We will begin by creating a Docker container and then creating a checkpoint of its current state, which allows you to save and restore the container's state.

Following the creation of a checkpoint, you will learn how to list existing checkpoints to verify their presence. Finally, you will practice removing a specific checkpoint using the docker checkpoint rm command and verify that it has been successfully removed. This lab provides hands-on experience with the fundamental operations of Docker checkpoints.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker(("Docker")) -.-> docker/ImageOperationsGroup(["Image Operations"]) docker/ContainerOperationsGroup -.-> docker/run("Run a Container") docker/ContainerOperationsGroup -.-> docker/ps("List Running Containers") docker/ContainerOperationsGroup -.-> docker/stop("Stop Container") docker/ContainerOperationsGroup -.-> docker/rm("Remove Container") docker/ImageOperationsGroup -.-> docker/pull("Pull Image from Repository") subgraph Lab Skills docker/run -.-> lab-555068{{"How to use docker checkpoint rm command to remove a checkpoint"}} docker/ps -.-> lab-555068{{"How to use docker checkpoint rm command to remove a checkpoint"}} docker/stop -.-> lab-555068{{"How to use docker checkpoint rm command to remove a checkpoint"}} docker/rm -.-> lab-555068{{"How to use docker checkpoint rm command to remove a checkpoint"}} docker/pull -.-> lab-555068{{"How to use docker checkpoint rm command to remove a checkpoint"}} end

Create and checkpoint a container

In this step, we will learn how to create a Docker container and then create a checkpoint of its current state. Checkpointing allows you to save the state of a running container and restore it later. This is useful for debugging, migration, or creating snapshots of your application.

First, we need an image to run a container from. We will use the ubuntu image. Since the LabEx VM environment does not have all images pre-pulled, we will pull the ubuntu image first.

docker pull ubuntu

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

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

Now, let's run a simple container from the ubuntu image. We will run it in detached mode (-d) and give it a name (--name checkpoint-test). We will also run a command that keeps the container running, like sleep infinity.

docker run -d --name checkpoint-test ubuntu sleep infinity

You should see a long string of characters, which is the container ID.

<container_id>

To verify that the container is running, you can use the docker ps command.

docker ps

You should see the checkpoint-test container listed with a status of Up.

CONTAINER ID   IMAGE     COMMAND           CREATED         STATUS         PORTS     NAMES
<container_id>   ubuntu    "sleep infinity"   X seconds ago   Up X seconds             checkpoint-test

Now that we have a running container, we can create a checkpoint of its state. We will use the docker checkpoint create command, followed by the container name and the name for the checkpoint. Let's name our checkpoint my-checkpoint.

docker checkpoint create checkpoint-test my-checkpoint

If the command is successful, you will not see any output. This means the checkpoint has been created.

List existing checkpoints

In the previous step, we created a checkpoint named my-checkpoint for the container checkpoint-test. In this step, we will learn how to list the existing checkpoints for a container.

To list the checkpoints for a specific container, we use the docker checkpoint ls command followed by the container name.

docker checkpoint ls checkpoint-test

You should see the name of the checkpoint we created in the previous step listed in the output.

CHECKPOINT ID
my-checkpoint

This command shows all the checkpoints that have been created for the specified container. If you had created multiple checkpoints, they would all be listed here.

Remove a specific checkpoint

In the previous steps, we created a container and a checkpoint for it, and then listed the existing checkpoints. In this step, we will learn how to remove a specific checkpoint.

To remove a checkpoint, we use the docker checkpoint rm command, followed by the container name and the name of the checkpoint you want to remove. We will remove the my-checkpoint checkpoint from the checkpoint-test container.

docker checkpoint rm checkpoint-test my-checkpoint

If the command is successful, you will not see any output. This indicates that the checkpoint has been removed.

Removing a checkpoint does not affect the running container. The container will continue to run in its current state.

Verify the checkpoint is removed

In the previous step, we removed the my-checkpoint checkpoint from the checkpoint-test container. In this step, we will verify that the checkpoint has been successfully removed by listing the checkpoints again.

To verify that the checkpoint is removed, we will use the docker checkpoint ls command for the checkpoint-test container, just like we did in Step 2.

docker checkpoint ls checkpoint-test

This time, you should see no output, or an error message indicating that there are no checkpoints for this container. This confirms that the my-checkpoint checkpoint has been removed.

If you still see my-checkpoint listed, please go back to the previous step and ensure you correctly executed the docker checkpoint rm command.

After verifying the checkpoint is removed, we can clean up the container we created. We will stop and then remove the checkpoint-test container.

First, stop the container:

docker stop checkpoint-test

You should see the container name printed as output.

checkpoint-test

Then, remove the container:

docker rm checkpoint-test

You should see the container name printed as output again.

checkpoint-test

Now, if you run docker ps, you should not see the checkpoint-test container listed.

docker ps

This command should show only running containers. If no other containers are running, the output will only show the header row.

Summary

In this lab, we learned how to create a Docker container and then create a checkpoint of its current state using the docker checkpoint create command. We started by pulling the ubuntu image and running a container named checkpoint-test in detached mode with the command sleep infinity. We verified the container was running using docker ps. Finally, we created a checkpoint named my-checkpoint for the checkpoint-test container.