Blog Post

SQL Server 2017 in a Docker Container running on a Mac – Tips and Tricks

,

I started using a MacBook Pro at work, and the very first thing I did was configure SQL Server 2017 running on a docker container, and run it locally within the Mac. In this post I will discuss some tips and tricks which will come handy if you are interested to pursue this route.

Tip 1 : How do I install SQL Server on a Mac?

You can follow the below steps to get started.

sudo docker pull microsoft/mssql-server-linux:2017-latest
  • Docker run
sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=<ReallyStrongPassword>'  -p 1401:1433 --name containername
 -d microsoft/mssql-server-linux:2017-latest

Tip 2 : How to connect to the SQL instance running on a container via SQL Operations Studio?

Tip 3 : How to view the running containers?

Run docker ps

docker ps

Tip 4 : How to stop the running container?

docker stop <container_id>

Tip 5 : How to view the details of containers which are in stopped state?

docker ps -a

Tip 6 : How to connect to the SQL instance running on a container via command line?

Run the below sqlcmd command –

sqlcmd -S YourIP,Port -U SA -P '<ReallyStrongPassword>'

You can issue regular T-SQL commands after you establish the connection.

Tip 7 : How to persist data ?

If you remove the container, the entire database which you might have configured is lost. To avoid this, you can create a data volume container. Below is the command to create container with a data volume with name sqlvolume –

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=ReallyStrongPassword' -p 1433:1433 --name containername 
-v sqlvolume:/var/opt/mssql -d microsoft/mssql-server-linux:2017-latest

The databases which you create will now be persisted until you delete the volume.

Tip 8 : How to share the data volume container with multiple containers ?

If you stop an existing container which is using the data volume,then you can create another container with the same data volume name and databases which were hosted under the data volume will reflect under the new container.

Conclusion:

The ability to spin up and spin down containers and multiple containers is changing the way I test various versions of SQL Server/Databases and its super flexible when it comes to a CI/CD pipeline.

Thanks for reading, and keep watching this space for more.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating