List checkpoints using a custom checkpoint directory
In the previous steps, we created checkpoints for our container mycontainer
and listed them using the default checkpoint directory. Docker stores checkpoints in a default location, but you can also specify a custom directory to store your checkpoints. This can be useful for organizing checkpoints or storing them on a different volume.
To create a checkpoint in a custom directory, you use the --checkpoint-dir
flag with the docker checkpoint create
command. First, let's create a directory to store our custom checkpoint. We will create a directory named mycheckpoints
in our home directory.
mkdir ~/project/mycheckpoints
Now, let's create a new checkpoint for mycontainer
and store it in the ~/project/mycheckpoints
directory.
docker checkpoint create --checkpoint-dir ~/project/mycheckpoints mycontainer mycheckpoint3
Here's a breakdown of the command:
docker checkpoint create
: This command is used to create a checkpoint.
--checkpoint-dir ~/project/mycheckpoints
: This flag specifies the custom directory where the checkpoint will be stored.
mycontainer
: This is the name of the container you want to checkpoint.
mycheckpoint3
: This is the name you are giving to this new checkpoint.
If the command is successful, you will not see any output. This means the checkpoint mycheckpoint3
has been created in the ~/project/mycheckpoints
directory.
Now, to list checkpoints stored in a custom directory, you need to use the docker checkpoint ls
command with the --checkpoint-dir
flag, specifying the custom directory.
docker checkpoint ls --checkpoint-dir ~/project/mycheckpoints mycontainer
This command will list the checkpoints found in the specified custom directory for the container mycontainer
.
You should see output similar to this, showing only the checkpoint we created in the custom directory:
CHECKPOINT ID
mycheckpoint3
Notice that this command only lists the checkpoints in the specified custom directory (mycheckpoint3
) and does not show the checkpoints stored in the default location (mycheckpoint1
and mycheckpoint2
).
To see all checkpoints for the container, regardless of where they are stored, you would need to list checkpoints from each directory separately or use a tool that aggregates this information. However, for listing checkpoints in a specific custom directory, the --checkpoint-dir
flag is essential.
Finally, let's clean up the container we created.
docker stop mycontainer
docker rm mycontainer
This stops and removes the container mycontainer
.