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:
    Restart-Computer
    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)

Example:

docker run --name <CONATINER_NAME> -d -p 1433: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

-Marek

Share it:
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Leave a Reply

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