Published on

August 2, 2021

Running SQL Server Containers with Docker

As a database administrator, have you ever wondered if there is an easier way to test different SQL Server versions and editions without going through lengthy preparations and installations? Well, there is! Docker provides a simple solution for running SQL Server containers on various operating systems. In this article, we will explore how to run Docker containers on Windows 10 for SQL Server 2017/2019 on Linux and SQL Server 2017 on Windows. We will also cover how to share a data directory with the host for databases and how to start SQL Server Agent on containers.

Install Docker on Windows 10

To get started, you need to download Docker Desktop for Windows from the official Docker website. Simply follow the installation instructions provided. Once installed, you will see the Docker icon on your taskbar.

By default, Docker runs in Linux container mode. If you want to run Windows containers, you can switch to Windows containers mode by right-clicking the Docker icon and selecting the appropriate option.

Running SQL Server Containers on Linux

Let’s start with running SQL Server containers on Linux. Open a command prompt window and use the following commands to download the SQL Server 2017 and SQL Server 2019 images from the Microsoft Docker Hub:

docker pull mcr.microsoft.com/mssql/server:2019-latest
docker pull mcr.microsoft.com/mssql/server:2017-latest

Once the images are downloaded, you can start the containers using the following commands:

docker run --name sql_2017 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=1Secure*Password1" -e "MSSQL_PID=Enterprise" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest
docker run --name sql_2019_1436 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=1Secure*Password1" -e "MSSQL_PID=Enterprise" -p 1436:1433 -d mcr.microsoft.com/mssql/server:2019-latest

These commands will start the SQL Server 2017 and SQL Server 2019 containers with the specified configurations. You can test the connection to the containers using the docker exec command.

Connecting to SQL Server Instances

To connect to the SQL Server 2017 instance, you can use SQL Server Management Studio (SSMS) and connect to the localhost using the default port 1433. Similarly, you can connect to the SQL Server 2019 instance using port 1436. Once connected, you can check the SQL Server version and perform various database operations.

Running SQL Server Containers on Windows

To run SQL Server containers on Windows, you need to switch Docker to Windows containers mode. Once switched, you can download the SQL Server 2017 image for Windows using the following command:

docker pull microsoft/mssql-server-windows-developer:2017-latest

After downloading the image, you can start the Windows container with the desired configurations. You can also map a folder on the host to the container for data sharing. Once the container is running, you can test the SQL Server connection using sqlcmd or connect to it using SSMS.

Starting SQL Server Agent

By default, the SQL Server Agent is disabled in the containers. To enable it, you can run a series of commands in SSMS. Once enabled, you can start the SQL Server Agent on the container using the appropriate command.

Conclusion

In this article, we have explored how to run SQL Server containers with Docker on both Linux and Windows. Docker provides a convenient way to test different SQL Server versions and editions without the need for complex installations. By following the steps outlined in this article, you can easily set up and manage SQL Server containers for your testing and development needs. Have fun experimenting with SQL Server containers!

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.