How to Snapshot Your Windows Container in Docker

Saving the state of a container in Docker is an anti-pattern. You should create your containers in a way that you can throw them away and start with a new one. However, there are some use-cases in which a snapshot of your current container is of great help.

One such use-case is creating a snapshot of your database container for integration testing. Instead of creating a fresh database from scratch and adding the seed data before every test run, I could do that once and reuse this known good starting point. This will save a lot of time and I get the feedback of my tests faster.

Creating a snapshot with Linux containers is easy and works without any problems. If you run the same command with a windows container, then you get this error:

Error response from daemon: windows does not support commit of a running container

If you google this problem, you find many explanations but no solution. It took me a while until I figured out that you can stop the container and Docker will not immediately removing it. Therefore, we can create a snapshot of a stopped container and bring that back to life. (replace mydb with the name of your container)

We now can run the database with the data as we would with any other container:

 

Conclusion

This is another little obstacle when you run Docker on Windows using Windows containers. Stopping the container before you make your snapshot is not complicated, but it is so poorly documented that you may never find it. I hope this post could help you.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.