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
- 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.
- 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
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>
<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
- 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.
- Stop and Remove the Container with command docker stop
- 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.