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.