Easy way to run SQL Server on Mac or Windows via Docker

Running SQL Server on Docker is a great way to quickly set up a database for testing, development or even production use cases. Here are the steps to run SQL Server on Docker

SQL Server

  1. Install Docker: If you don’t have Docker installed on your machine, you can download it from the Docker website. Make sure you have a stable version installed to avoid any compatibility issues.
  2. The next step is to run the following command to pull the official SQL Server Docker image from the Docker hub and start the container

docker run --platform linux/amd64 --restart always -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<password>' \ -p 1433:1433 -d mcr.microsoft.com/mssql/server:<version>

If you would like to create volume and persist the data, provide volume argument -v docker_mssql_volume:/var/opt/mssql

docker run --platform linux/amd64 --restart always -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<password>' \ -v docker_mssql_volume:/var/opt/mssql -p 1433:1433  -d --name mssql mcr.microsoft.com/mssql/server:<version>

3. Replace <version> with the version of SQL Server that you pulled in step 2 and <password> with the password that you want to use for the sa (system administrator) account. The -p option maps the host’s port 1433 to the container’s port 1433 so that you can connect to the SQL Server instance from outside the container.

Connect to SQL Server

  1. To connect to SQL Server running in a Docker container, you can use any SQL Server client that supports connecting to SQL Server over a network, such as SQL Server Management Studio or sqlcmd. You will need the hostname or IP address of the machine running Docker, the port number (1433), and the login credentials you specified in step 3.
  2. Stop and Remove the Container with command docker stop mssql
  3. and then remove it using the following command docker rm mssql

With these simple steps, you can easily run SQL Server on Docker. This is a quick and efficient way to get a database up and running for testing, development or even production use cases.

Pavan Kumar Jadda
Pavan Kumar Jadda
Articles: 36

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.