Over the past couple of blog posts, I have been talking about the versatility of deploying SQL Server with Docker. This combination is a great way to quickly and easily spin up local SQL Server instances. In the most recent post, I talked about a method to copy and restore a sample database into a Docker container that is running SQL Server. In this post, I am going to talk about an easier way to accomplish this by attaching a persistent volume to the container. With this method you don’t have to copy any files into the container, and it makes the overall process easier and repeatable.
First, before we get into the code, let’s talk about what a volume is. Essentially, a volume is a location on the host machine that can be referenced by the container. I think of this as a shared folder that the container can see. Once attached to the container, it can then read or write to the volume. You can easily declare the volume when you create the container with a simple switch in the command.
John’s examples are on a Mac, but the concepts are essentially the same for Windows or Linux.