Last month I blogged about using Docker to run SQL Server as a quick and easy way to get SQL Server up and running. While it continues to be immensely useful, there aren’t any user databases running on it. The only databases present are the system databases. Yes, I could manually create a database, but it would be a lot easier to have a sample database available.
How do we do restore a sample database, in a container, that is running on a Mac laptop? Let’s check it out!
Disclaimer
Not a container expert so there might be various ways of doing it. This is just how I’ve figured out how to make the magic happen.
Also, if you have not read the first blog on how to get SQL Server running in Docker on your Mac, take a few minutes to read through it.
Here are the steps that we will take to make this work,
- Download one of the sample databases from I have a “mssql” directory in my local profile to make things easier
- Make sure the container is started. You can issue a “docker ps” command terminal to see which containers are running
- Create a directory within the container
- Copy the sample database backup file into the directory you just created
- Restore the database onto the SQL instance that is running within the container
Sounds simple, right? Let’s see!
Create a directory
To create a directory within the container (remember that the container is running Linux), we can issue a command to the container that will create the directory. Using Terminal (you can go to Spotlight to find the Terminal program or it is under Utilities in the Applications folder), execute the following command,
- Docker exec -it sql2019 mkdir /var/opt/mssql/backups
Let us break that command down,
- Docker – this indicates that we are going to be doing something with Docker
- Exec – this tells the specified container to exec the command we pass into it
- -it – this basically allows for an interactive session with the container
- Sql2019 – this is the name of the container. You can specify the container name when you start the container or Docker will name it for you
- Mkdir – this is short for “make directory”
- /var/opt/mssql/backups – this is the directory path that is to be created.

Copy the Backup File
Now that the directory has been created, we need to get the backup file of the sample database into the container. In my case, I am using AdventureWorks2017.bak
- Docker cp ./mssql/AdventureWorks2017.bak sql2019:/var/opt/mssql/backups




Join the conversation! Your thoughts help the community grow.