In this article, we will show how to run a database server in Docker. A running database is necessary for any ORIGAM development.
In case you don’t have Docker installed on your computer yet, please do it now. Here are general instructions.
If you are completely new to Docker, you may find useful this and also this video.
Image download
First, you need to download an image from which you can run your container.
If you have an M1 or newer Mac, check this guide.
In your command line (CMD or PowerShell in MS Windows or Terminal on MacOS), run the Docker pull command to download the image with the database server. You can use your own image, find any available in DockerHub or the following one:
docker pull mcr.microsoft.com/mssql/server:2022-latest
Container creation
Once the image is downloaded on your machine, you can create the container. Use your command line again, and this time run the following command. But before you do so, please replace the string yourStrong(!)Password
with any password of your choice.
docker run -d -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" --name mssql2022 -p 1433:1433 mcr.microsoft.com/mssql/server:2022-latest
IMPORTANT INFORMATION ON DATA SECURITY !
It is important to know that all the data stored in the database running in the Docker container is stored only in that container, and if you lose that container (for example, if you accidentally delete the container), you will lose all your data as well.
The solution is to use a Docker volume (save to an isolated Docker repository) or a bind mount (the database and data are saved to a local file on your machine).
Example of using Docker volume:
-v mssql_data:/var/opt/mssql \
Using bind mount:
-v C:\sql-backups:/var/opt/mssql/backup (for MS Windows)
-v $HOME/sql-data:/var/opt/mssql/backup (for MacOS)
So if you want to keep your databases and data on your local disk and you are using MS Windows, create a container using this command:
docker run -d -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" --name mssql2022 -p 1433:1433 -v C:\sql-backups:/var/opt/mssql/backup mcr.microsoft.com/mssql/server:2022-latest
The backup will then be in your local folder C:\sql-backups. You can, of course, customize the name of the local folder in the script.
Once you start the container with the mount, all changes in the database are immediately written to local files in your folder.
Docker mount works in real time - you don’t have to do anything manually. Every INSERT, UPDATE, DELETE is immediately reflected in those local files.
So when you shut down the container and restart it, all the data will be there because it’s physically stored on your machine in that folder.
Now there is a Docker container with the MS SQL database server running in your local Docker.
If you plan to use this database server not just for training purposes but in production, consider also disabling the SA account as best security practice as described here.
In case you are having any trouble, you can check full instructions from Microsoft.