Setup Local SQL Server Server on Docker - gecko-8/devwiki GitHub Wiki
- Download and install Docker for Mac (https://www.docker.com/)
- Pull down the latest image for SQL Server (optional, will be pulled by next command if you don’t have it)
sudo docker pull mcr.microsoft.com/mssql/server:latest
- Create and run the container
Note: is a directory where you’ll be able to drop .bak files, etc. for easy access within the container. Example: /Users/MyData/Databases Note: This creates a Docker Container Volume with the name “mssql”.
sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=<password>' -p 1433:1433 -v mssql:/var/opt/mssql -v <local db directory>:/var/opt/mssql/backups --name mssql-server -h sql1 -d microsoft/mssql-server-linux:latest
- To connect an external program, just use localhost, port of 1433, user of sa, and password of .
- To connect a .NET app, use the following connection string format
Data Source=localhost;Initial Catalog=<database name>;User id=sa;Password=<password>;MultipleActiveResultSets=True
- Stop the container
docker stop mssql-server
- Delete the container
docker rm mssql-server
- Delete the volume
docker volume rm mssql
- Delete unused images (optional)
docker image prune -a -f
- Connect to the container with the command:
docker exec -it mssql-server bash
- Navigate to the backups folder:
cd /var/opt/mssql/backups
- Execute the script with the command:
/opt/mssql-tools/bin/sqlcmd -U sa -P <password> -i <script file>