I'm having some trouble figuring out how to make a comprehensive snapshot of my Docker container so that I can restore it later to the exact same state. This means I need everything to be included: the root filesystem, port mappings, temporary filesystem, volumes, bind mounts, network settings, entrypoint, labels... you name it.
Here's the deal: the container takes a long time to reach a stable state, and once it does, I want to run some experiments that could potentially mess things up. So, ideally, I want to snapshot the container when it's in good shape, then delete it after my experiments if things go south, and restore it to try again. I'm looking for a robust solution, whether that's through the CLI or a GUI, with no concern for performance or storage efficiency. Note that I can't use the checkpoint function since CRIU is Linux-only, and I'm currently on a Mac. I'm considering spinning up a Linux VM to run Docker there, but there might be an easier way, and I'm hoping you all can help!
3 Answers
You might want to check out the Docker checkpoint command, but I know you mentioned CRIU isn't an option since you're on a Mac. If you do decide to try a Linux VM down the line, that could open up more possibilities for you.
It sounds like your container has a lengthy setup time. If possible, try putting all the setup commands in your Dockerfile. That way, when you run Docker, it builds the image directly to that stable state without the long wait.
Exactly! It’s a server that does a lot of processing initially. I’m trying to avoid that wait time, which is why I'm looking for snapshot options to streamline things.
One common mistake is treating containers like VMs where you can just exec into them and make arbitrary changes. Instead, it's way more effective to build a Dockerfile that reflects the entire process to get your container to the desired state. This way, you can reconstruct the container anytime you need it.
You're spot on! Automating the whole process is key. I'm working on a script myself to handle the set-up after the initial state. My container polls and processes data, and once it's ready, I can start configuring again.

I really appreciate that tip! Just to clarify, though, I've already ruled out CRIU since it won't work for my current setup on Mac.