Create a checkpoint with a custom directory
In this step, we will learn how to create a checkpoint in a specific directory of our choice. By default, Docker stores checkpoints in a standard location within the Docker data root directory. However, you might want to store checkpoints in a different location, for example, on a different disk or a shared storage.
To specify a custom directory for the checkpoint, we use the --checkpoint-dir
flag with the docker checkpoint create
command. First, let's create a new directory in our home directory where we will store the checkpoint.
mkdir ~/project/my-checkpoints
Now, we can create another checkpoint for our running container my-checkpoint-container
, but this time, we will specify the ~/project/my-checkpoints
directory as the checkpoint location. Let's name this new checkpoint my-second-checkpoint
.
docker checkpoint create --checkpoint-dir ~/project/my-checkpoints my-checkpoint-container my-second-checkpoint
This command will create the checkpoint data within the ~/project/my-checkpoints
directory. You can verify the contents of this directory to see the checkpoint files.
ls ~/project/my-checkpoints/my-second-checkpoint
You should see several files and directories created by the checkpointing process.
Even though we specified a custom directory, the checkpoint is still associated with the container. You can list the checkpoints for the container again, and you will see both my-first-checkpoint
and my-second-checkpoint
listed.
docker checkpoint ls my-checkpoint-container
This shows that Docker keeps track of checkpoints regardless of their storage location. Using a custom directory gives you more flexibility in managing your checkpoint data.