How to start SQL Server Docker container in few simple steps

sql server on docker

SQL Server 2017 is the first SQL Server version that is available on Windows, Linux, and in Docker containers. In this blog post, I will show you how to create your first SQL Server Docker container in a few very simple steps.

What is Docker?

Docker is an open-source container platform provider written in GO programming language. It’s available for Linux, Windows, and MacOS. In addition, it also works in Azure and AWS environments. Containers allow developers to package up an application with all of the parts it needs, such as libraries and other dependencies, and deliver it all out as one package. It’s something similar to Virtual Machines but without the guest operating system. They’re isolated, but they share Host OS. That makes them smaller and more lightweight.

container vs vm

Docker installation

Currently, for Windows users, Docker is available in two editions. Docker Community Edition for Windows (CE) is a free solution designed for Windows 10 users. Docker Enterprise Edition for Windows Server (EE) is dedicated for Windows Server 2016 users. There is also third (legacy) solution – Docker Toolbox with support for Windows 7 and 8. However, this edition has some additional requirements and limitations, for example, it supports only Linux containers.

Docker CE

To install Docker CE you need to follow two very simple steps:

  1. Download Docker CE installer from Docker Store.
  2. Double-click Docker for Windows Installer.exe and follow the install wizard to accept the license, authorize the installer, and proceed with the install.
Docker EE

Installation of Docker EE is more automated and can be performed using PowerShell:

  1. Open PowerShell command prompt and run following command to install Docker:
    Install-Module DockerProvider -Force
    Install-Package Docker -ProviderName DockerProvider -Force
  2. If prompted to install any prerequisites such as NuGet, type in “Y”.
  3. Run the following command to check if a reboot is required:
    (Install-WindowsFeature Containers).RestartNeeded
  4.  If the result is Yes, restart your computer with this command:
    Docker Toolbox

Installation of Docker Toolbox is quite similar to the installation of Docker CE.

  1. Download Docker Toolbox installer.
  2. Install Docker Toolbox by double-clicking the installer.

The installer installs following software on your machine:

  • Docker Client for Windows
  • Docker Toolbox management tool and ISO
  • Oracle VM VirtualBox
  • Git MSYS-git UNIX tools

Installation validation

When Docker is already installed and running you may want to check if it works properly. For Docker CE and EE, start PowerShell command prompt. For Docker Toolbox, open Docker Toolbox Terminal (Docker QuickStart  Terminal). Then run the following command to check your installed version:

docker --version

docker version

Next step is to check if Docker can pull and run containers:

docker run hello-world

docker run hello-world

Creating SQL Server Docker container

Currently, Microsoft provides three SQL Server Docker containers:

You may look for them on Docker Hub page or you also may run the following command to list available images:

docker search microsoft

docker search microsoft

Pull needed image

The first thing to start your container is to pull the image from the repository. Depending on what image you want to use you need to execute one of the following commands:

docker pull microsoft/mssql-server-linux
docker pull microsoft/mssql-server-windows-developer
docker pull microsoft/mssql-server-windows-express

Important: Docker Toolbox supports only Linux containers. Docker CE and EE support Linux and windows containers, however, to pull and run docker image without any issues you need to ensure that your Docker installation is running in the proper mode. You may do it by right-clicking on the Docker whale icon in your tray docker icon.

I decided to download SQL Server Developer on Windows image.

docker pull

To check what images are downloaded run the following command:

docker images

docker images

Run new container

Finally, you’re ready to run your container. To do it you need to execute docker runcommand and provide few mandatory parameters.

  • --name – provide a name for your container
  • -d – run container in detached mode (in the background)
  • -p – publish a container᾿s port or a range of ports to the host. For example -p 14333:1433 maps port 14333 on the host to port 1433 in the container.
  • -e – create environment variables under the container execution runtime
    • sa_password (to assign the SQL Server SA password)
    • ACCEPT_EULA (to accept end-user license agreement)


docker run --name <CONATINER_NAME> -d -p 14333:1433 -e sa_password=<SA_PASSWORD> -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer

docker run mssql

Here you can find more details about docker run command.

How to connect to your new SQL Server?

The last thing is to connect to new SQL Server instance. To do this open SQL Server Management Studio and as Server name provide localhost with the port you specified for mapping. Then, choose SQL Server authentication and log in using sa account (with the password you specified during container setup).

SSMS - connect

Now you can run any queries you want.

SSMS - query


Share it:

3 thoughts on “How to start SQL Server Docker container in few simple steps”

  1. Great guide to getting started quickly. One question though: on the port parameter, you say:

    -p – publish a container᾿s port or a range of ports to the host. For example -p 14333:1433 maps port 14333 on the host to port 1433 in the container. One is 14333 and the other is 1433 (the first one has an extra 3).

    Then in the example docker run command you show:

    -p 1433:1433

    And finally, in the SQL connection dialog, you show 14333.

    Is the inclusion of the extra 3 in the first part a typo? Or would you really want to map 14333 to 1433? I know that 1433 is the default SQL Server port. Is the extra 3 to keep the local port 1433 open in case you have an actual SQL Server instance?

    Again, thanks for the great quickstart guide!

    1. Hi Jeff,

      Well spotted. It’s a typo in example docker run command. It should be -p 14333:1433 as on the screenshot below the example. I’m fixing this right now.
      Of course, 1433:1433 also works if this port is not already used on your host machine.

      In my example, I used 14333:1433 to easier show which value maps to the port on the host (14333) and which one maps to the container (1433).

      1. Thanks for the quick response! I kind of figured it might be a typo, as there were two instances of 14333. And it makes sense to have it mapped to a different port than the standard 1433, on the chance you have a non-containerized SQL instance running there. (Although why would you not use a container? ;))

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.