---
title: "How to Install SQL Server on Docker"
slug: "install-sql-server-in-docker-quick-guide"
published_at: "2022-10-02T05:08:19.000Z"
categories: "Advanced SQL, SQL Installation manual, SQL Integrations, SQL Tutorials"
tags: "Docker, Installation, Management, Server, SQL Server, SSMS, Studio"
---

# How to Install SQL Server on Docker

> How to Install SQL Server on Docker
SQL Server can be installed on Linux distributions, one of them is a Docker Containter. Let’s get started!

As you may know, SQL Server can be installed on Linux distributions, one of them is a Docker Container, to follow this little tutorial (If you are using a Windows system) you should have installed WSL2 (Windows Subsystem for Linux 2) installed, [here you have a little something to get you started](https://learn.microsoft.com/en-us/windows/wsl/install).

Let’s Start Installing Docker

![](/blog/install-sql-server-in-docker-quick-guide/image-17.png)

### Installing Docker

Go to this [LINK](https://docs.docker.com/get-docker/ "Docker-Installation"). Download the Docker of your choice

![](/blog/install-sql-server-in-docker-quick-guide/image-4-1024x313.png)

### I am using a Mac, what should I do now?

First of all, download Docker.dmg, open a Terminal in the location of the **Docker.dmg** (If your Mac has an intel chip click [HERE](https://desktop.docker.com/mac/main/amd64/Docker.dmg?utm_source=docker&utm_medium=webreferral&utm_campaign=docs-driven-download-mac-amd64) and if it has an apple chip click [HERE](https://desktop.docker.com/mac/main/arm64/Docker.dmg?utm_source=docker&utm_medium=webreferral&utm_campaign=docs-driven-download-mac-arm64)) and write the following commands:

```sql
 # With this command you attach the Docker file to Mac 
 sudo hdiutil attach Docker.dmg
 # Now you should install it
 sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
 # Finally, detach the volume
 sudo hdiutil detach /Volumes/Docker
```

That’s all, easy right? Now you should have docker installed on your Mac.

### Using Windows, this is what you should do

You can start by downloading **[Docker Desktop Install.exe](https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe)** and execute it, if you have installed **WSL2** as I told you before the installation process is very straightforward, you shouldn’t have any problem here.

### What about Linux? what should I do now?

Well, this will depend on the Linux distro, Docker supports **Ubuntu, Debian, Fedora and Arch (Currently as experimental) installations**, and come with a package for each one of them.

![](/blog/install-sql-server-in-docker-quick-guide/image-5-1024x265.png)

```sql
modprobe kvm
#If you have an intel chip
modprobe kvm_intel
#Else, if you have an AMD chip  
modprobe kvm_amd    
sudo usermod -aG kvm $USER #Add your USER to the kvm group to access the kvm device
```

If you still have problems running Docker after this, you should read [Docker Official Documentation on Linux Installation](https://docs.docker.com/desktop/install/linux-install/) in order to make some troubleshooting.

### Did all this, have Docker running, now lets Install Microsoft SQL Server in a Docker Container!

Lucky for us, Microsoft already took care of ourselves and make different images for SQL Server.

**On Windows open a Powershell and run the following code:**

```bash
docker pull mcr.microsoft.com/mssql/server:2022-latest
```

**Otherwise, on Linux or Mac, kind of the same thing but with sudo ahead**:

```bash
sudo docker pull mcr.microsoft.com/mssql/server:2022-latest
```

In case you want to use **other SQL Server versions** run one of the followings instead:

```bash
docker pull mcr.microsoft.com/mssql/server:2019-latest # SQL Server 2019
docker pull mcr.microsoft.com/mssql/server:2017-latest # SQL Server 2017
```

Ready! We have an SQL Server Image installing in our Docker Container, If you go to your docker images you should see it.

![](/blog/install-sql-server-in-docker-quick-guide/image-6.png)

### Configuring our SQL Server Installation

Now that we have our SQL Server Installation, Microsoft asks us to run it Accepting EULA before, so we should run this command:

```bash
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=[put your new password here]" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest # Take note this is only for server:2022-latest, in case you install other SQL server, you should change the last part of this line
```

If everything go Smoothly it will give you a hash line and in your docker Images you will see a “IN USE” label on your MCR image.

![](/blog/install-sql-server-in-docker-quick-guide/image-7.png)

![](/blog/install-sql-server-in-docker-quick-guide/image-8.png)

### Connecting to our Docker container

We already have our Docker container with SQL Server up and running, one way to connect to run SQL commands is through **sqlcmd inside the container**, to connect to it use the following commands:

```bash
PS> docker ps -a # We will use this command to find out our container name
CONTAINER ID   IMAGE                                        COMMAND                  CREATED          STATUS                        PORTS                                         NAMES
463f5132aa17   mcr.microsoft.com/mssql/server:2022-latest   "/opt/mssql/bin/perm…"   12 minutes ago   Up 12 minutes                 0.0.0.0:1433->1433/tcp                        vigorous_rosalind
1c16dedd96f6   recordviewer_nginx                           "/docker-entrypoint.…"   2 months ago     Exited (255) 44 minutes ago   0.0.0.0:8080->80/tcp, 0.0.0.0:8443->443/tcp   recordviewer_nginx_1
69740c6d6ef1   recordviewer_web                             "bash -c 'node app.j…"   2 months ago     Exited (255) 44 minutes ago                                                 recordviewer_web_1

PS> docker exec -it vigorous_rosalind "bash" # In my case the Container was called vigorous_rosalind so let's run bash on it

# if all goes well, you are inside the SQL container right now

mssql@463f5132aa17:/$  /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "[PUT YOUR PASSWORD HERE]"
1> CREATE DAtABASE TestDB;
2> SELECT Name from sys.databases;
3> GO
Name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
TestDB
1> QUIT
mssql@463f5132aa17:/$ exit
```

Perfect, we could run a command inside our SQL Server, everything is running smoothly.

### Connect Using SQL Server Management Studio (SSMS)

If you are in Windows and followed our tutorial [here](/install-ssms-sql-server-quick-guide) you already have **SSMS** installed on your PC, in case you are on Linux or Mac consider using **[Azure Data Studio](https://learn.microsoft.com/en-us/sql/azure-data-studio/?view=sql-server-ver16)** that comes with tools to manage an SQL server running on Linux

On SSMS, We should go to **File > Connect Object Explorer…**

![](/blog/install-sql-server-in-docker-quick-guide/image-9.png)

On **Authentication > Select SQL Server Authentication**

On **Server Name** > \[IP Address (If you are using the same machine, would be **127.0.0.1**\],\[PORT (If you follow this tutorial step by step, would be **1433**, you can change it when you run your Docker container)\] (In my case: **127.0.0.1,1433**)

Login: User (**SA**) as Default, to add new users we will make another tutorial, for now let’s start with this.

Password: The password you define when you create your Docker Container

![](/blog/install-sql-server-in-docker-quick-guide/image-10.png)

![](/blog/install-sql-server-in-docker-quick-guide/image-11.png)

### Conclusion

We have installed docker, clone an Image of a SQL Server, Dockerize it and connect to it. You could use this to make an staging development or to make a test environment.

Now you can Dockerize your SQL Servers! Hope this tutorial was useful!

