Running Sql Server Linux on a Docker Container

One of the new features added to the SQL Server 2016 is the ability to run it on Linux. Along with that, they brought in support for Docker and released an official image which is available in Docker Hub. It has already got over 5 million + pulls from the repository and is gaining momentum day by day. Let's see the various steps for setting up a container based on this image.

Step 1 

Search for the image in the Docker Hub and pull the official image from the Docker hub

docker search microsoft

So the image we are looking for is  mssql-server-linux

docker pull microsoft/mssql-server-linux

To check whether the image is successfully downloaded to your local box, you can use the following command 

docker images

Step 2

Now we have the image, let's spin up a container based on this image

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Test1234!!'  -p 1433:1433 --name SQLLI01   -d microsoft/mssql-server-linux 
  • -e switch is used to set the environment variables and in our case, we use that to accept the User Agreement and set the password for the default admin user "sa"
  • -p is used for port forwarding and whenever there is a request comes in at port #1433 in the host machine it will be redirected to the port 1433 in the container where the SQL server is listening by default
  • -- name is the name for the container
  • -d switch will make sure the container will be running in the background

To verify the status of the container, execute the following command

docker ps 

Step 3

Before we can connect to the SQL Server using any tools we need to whitelist the port in the portal so that the connections will be allowed. This can be done from the Network tab for the VM in the Azure portal

Once this is done we can easily connect to the server using tools such as SQL Server Management Studio, sqlcmd etc. I am going to use a new tool released by Microsoft called SQL Server Operations Studio. It's a free, light-weight and cross-platform tool for modern database development and operations and you can download it from here

Once it's installed, create a new connection with the following details,

  • Server - IP Address/Name of the host machine with the port # you specified in the docker run command
  • Authentication Type - SQL 
  • Username - sa
  • Password - The password you specified in the docker run command

Click on the connect button to connect to the Server and once it's successfully established, you will get a screen like the one below from where you create new databases, execute SQL queries etc


No Comments

Add a Comment

Recent Posts