Running MS SQL Server using Docker

Step by step guide

  1. Create a directory where you want to store your database.

  2. Copy the command below. Replace yourStrong(!)Password with the password you want to use, and k:\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

  3. Run the modified command from a command prompt.

    command prompt.

  4. Check that you can see the MSSQL database in your Docker containers:

    Docker Container

  5. 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.

    Docker start and final logs

  6. 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: