Step by step guide
-
Create a directory where you want to store your database.
-
Copy the command below. Replace
yourStrong(!)Password
with the password you want to use, andk:\path-to-be-used
with the directory you’ve created.
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" --name mssql2022 -p 1433:1433 -v "k:\path-to-be-used":/var/opt/mssql/backup -d mcr.microsoft.com/mssql/server:2022-latest
-
Run the modified command from a command prompt.
-
Check that you can see the MSSQL database in your Docker containers:
-
Open Docker. In the Containers section, start the mssql2022 container. Wait up to a few minutes for the database to fully load. When you open the container you should see logs. There you can see if the database load is complete.
-
Finally, you can test the connection to the database by running the following command from the command line
docker exec -it mssql2022 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P<yourStrong(!)Password> -Q "Select 1"
.
Where<yourStrong(!)Password>
is replaced by the password you have chosen. The result should look like this: