How to Run SQL Server Container on Ubuntu 18.04

Hello everyone, welcome to my Linux tutorial. Today, we are going to learn how to run SQL Server Container on Ubuntu 18.04. Of course, I am talking about Docker. I am running Docker on my Debian 9. It should be no issue even if you installed your Docker on other Linux distribution. To be honest, I am not a fan of SQL Server. I am MySQL and PostgreSQL user but since it is now available for Linux via Docker Container, I think it is worth it to try.

We will learn the following article:

  • Run SQL Server Container
  • Connect and configure SQL Server using Microsoft SQL Server Management Service (SMSS)

Steps to run SQL Server Container on Ubuntu 18.04

Pull SQL Server Docker Image

First, you will need to install Docker on Linux. Read my previous post to install Docker on Ubuntu 18.04. And then let’s pull the SQL Server image with this command

docker pull microsoft/mssql-server-linux:2017-latest

It will download the mssql-server-linux. Actually, you can skip this step because the next step, the docker run command will download this image from the internet if it cannot be found in your local docker image directory.

The download size is about 1.5 GB. Now list Docker images 

docker images

Just to make sure the download process is completed successfully

Run the Container

Now use the following command to run a new container

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' \
-p 1402:1433 --name sqlserver \
-d microsoft/mssql-server-linux:2017-latest

Please note that you will need to change the YourStrong!Passw0rd with your new strong password. Also, you can change sqlserver into something else. As you can see I mapped the port 1402 in my laptop to the default SQL Server port 1433. This would be useful when we have more than one SQL Server instances on our host. 

Now check the docker container, make sure you see your instance there

 

As you can see my mssql-server is there. So, let’s try to connect to it from a command line.

Querying Through Command Line

Now let’s try to execute some queries in the command line. 

docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U sa

As you can see, the command above utilizes the sqlcmd. If you get some errors, this is because you don’t have the sqlcmd tool in your Linux. Navigate to this page to install sqlcmd tool on Linux.

After you log in, execute this query command

select @@version
go

Output

Connect Using SQL Server Management Studio (SSMS)

From a Windows PC, you can connect to the SQL Server container we created earlier easily. Open Management Studio and then enter the following 

In the Server name area, enter your host IP address and then comma port number. For example my host IP address is 192.168.100.14 and SQL Server port number is 1402. So, I typed this in the Server name: 192.168.100.14,1402. And then make sure you select the SQL Server Authentication. Use the sa login and password (YourStrong!Passw0rd ) we created earlier. 

run sql server container on ubuntu

Viola, we can connect to the SQL Server Container using SQL Server Management Studio (SSMS). 

Conclusion

With Docker container, installing and running SQL Server on Linux environment is very easy. In few minutes we can have our own SQL Server up and running. Thank you for reading this how to run SQL Server container on Ubuntu 18.l04.See you in the next tutorial.

2 Trackbacks / Pingbacks

  1. How to Deploy MySQL Server Containers Using Docker | Manjaro dot site
  2. How to Install Microsoft SQL Server 2019 on Ubuntu 19.10 | Manjaro dot site

Leave a Reply

Your email address will not be published.


*