So, it seems containers are here to stay. Before the release of SQL Server 2017, I really hadn’t paid attention to this space. The thinking was I’d never need to know about any other OS except windows Server. This all changed when Microsoft decided to release SQL Server on linux. I began to panic. I’ve intentionally focused on the Windows platform, and of course SQL Server, over the past 11 years.
Resistance is futile Instead of waiting for SQL Server on Linux (or containers) to become widely adopted I decided to begin learning both Linux and containers. I’ll be creating a series of blog posts as I start down this journey. Each will be related to SQL Server, docker , and Linux.
What is a container?Docker describes a container as being “a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.” They are lightweight and do not require their own OS. For a full description, see https://dockr.ly/2PYAbPy .
SQL Server and ContainersMicrosoft supports running SQL Server within Linux containers beginning with SQL Server 2017. There are several use cases for running SQL Server within containers (a major one being CI/CD for dev and QA environments). When you add on container orchestration platforms, such as Kubernetes, things get real interesting (ability to move containers to new hosts, scale up, scale down etc). As I progress through this path I’ll be setting an Openshift ( OKD ) cluster.
Getting startedI’m using Red Hat Enterprise Linux 7.5. If you choose to use this distro, start with a Red Hat Developer subscription. For more details, see https://developers.redhat.com/.
Proxmox is the hypervisor used within my lab environment. Each of the commands listed below are being run while logged in as root for simplification (I know, this isn’t best practice).
Setup a Red Hat Developer subscription. Download RHEL. Create a VM, or install on bare metal, using the RHEL iso. Configure networking and the hostname. I used the ntmui utility to do this. See here for details. Add the server to your subscription. This allows you to utilize Red Hat repositories, pull updates, etc using yum. As root, or sudo, run the following: # subscription-manager register \ # --username DevSubscriptionUserName \ # --password DevSubscriptionPassword --auto-attach Once registered, pull down the latest updates using yum. (What is yum? https://access.redhat.com/solutions/9934 ) # yum -y update Install Docker. # yum install yum-utils -y # yum-config-manager --enable rhel-7-server-extras-rpms # yum -y install docker Start the docker daemon, set to run automatically on boot, and check the status of docker. # systemctl start docker.service # systemctl enable docker.service # systemctl status docker.service Check the docker version # docker version Example output from docker version.
Docker is installed, now what?
With docker installed we can pull an image of SQL Server using “docker pull.” We’ll grab both a SQL Server 2017 image and SQL Server 2019 (CTP 2.0).
SQL Server 2017 (dev edition) # docker pull mcr.microsoft.com/mssql/server:2017-latest Check the available docker images: # docker images
Create a container using the 2017-latest image # docker run \ # -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrongP@ssword' \ # -p 1433:1433 --name mssql2017 \ # -d mcr.microsoft.com/mssql/server:2017-latest Verify the container is running by entering “docker ps” at the prompt and pressing enter. You should see the following information returned: CONTAINER_ID Unique ID IMAGE Image used to create the container COMMAND running command within the container CREATED Time the container was created STATUS PORTS Defined by the -p argument used within the docker run command. We’ve defined the port as 1433:1433 (host is listening on port 1433 and passing traffic to port 1433 within the container). NAMES Container name. Connect to the SQL Server instance using SSMS, Azure Data Tools, or sqlcmd. You’ll need to connect to the host IP over port 1433 for this example.

SQL Server 2019 CTP 2.0 (RHEL image) # docker pull mcr.microsoft.com/mssql/rhel/server:vNext-CTP2.0 Check the available docker images: # docker images

Create a container using the vNext-CTP2.0 image # docker run \ # -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrongP@ssword' \ # -p 5000:1433 --name mssql2019 \ # -d mcr.microsoft.com/mssql/rhel/server:vNext-CTP2.0 Verify the container is running by entering “docker ps” at the prompt and pressing enter. You should see the following information returned: CONTAINER_ID Unique ID IMAGE Image used to create the container COMMAND running command within the container CREATED Time the container was created STATUS PORTS Defined by the -p argument used within the docker run command. We’ve defined the port as 5000:1433 (host is listening on port 5000 and passing traffic to port 1433 within the container). NAMES Container name. Connect to the SQL Server instance using SSMS, Azure Data Tools, or sqlcmd. You’ll need to connect to the host IP over port 5000 for this example.

Docker Logs
docker logs fetches the logs available within a particular container. Very useful if you can’t connect via SSMS and you need to review the SQL Server error log.
# docker logs mssql2017 CleanupTo cleanup our host we’ll stop each container, remove the container, and then remove the images. One thing to note, once you remove a container all associated data is also removed. By default, a container does NOT persist data if it is removed (docker rm). I’ll revisit this in an upcoming post in which we can ensure any databases created are persisted in the event a container is removed.
# docker stop mssql2017 # docker stop mssql2019 # docker rm mssql2017 # docker rm mssql201