Run and Manage SQL Server 2019 CTP 2.0 RHEL Docker Container
By: Carlos Robles | Comments | Related: More > SQL Server on Linux
Microsoft released a new version of SQL Server on September 23, 2018. Beyond the traditional Windows release, this preview version of SQL Server 2019 also includes a container image we can run on Docker for Linux, Windows or macOS. In this tip, I will show you how to download and run the latest (CTP 2.2) SQL Server 2019 container image on Docker for macOS.
In case you don't have Docker installed already on your laptop, please check this simple guide on how to install the CE edition of Docker for macOS. The guide also contains detailed information about system prerequisites and basic operations.
Check to see if Docker daemon is running
Once Docker is installed, let's make sure Docker's daemon is running. As you may guess, there are multiple ways to do this, but I will include a few in this tip.
Let's start using a graphical tool like Mac Activity Monitoring. In order to open this tool, use the "Spotlight" search at the top right of the status bar:
Please note, the "Spotlight" option will not appear in your status bar if you disable it, you can put it back by enabling it using this guide. In case you want to use the shortcut, try Command (or Cmd) ⌘ + Space bar.
Once spotlight displays the search bar, then simply type Activity Monitor:
Chose the Activity Monitoring icon from the list. Activity monitor, will display every single process running in your mac machine, but I'm interested in information about the "Docker" processes, so I typed "Docker" in the search textbox to filter the results as shown below:
Noticed I highlighted the PID column, the main Docker process is the one with the 5482 ID. We will check that later using the terminal.
Another way to make sure docker is running is checking the desktop top status bar, click on the docker icon and look for the current status as shown below:
Finally using the terminal, this is by far the easier and faster way to check. Look for the terminal application exactly the same way I looked for Activity Monitor using spotlight and type the following command "ps -ef | grep Docker" as shown below:
mylaptop:~ master$ ps -ef | grep Docker 501 5484 1 0 3:04PM ?? 0:00.78 /Applications/Docker.app/Contents/MacOS/Docker 501 5502 5484 0 3:04PM ?? 0:00.08 /Applications/Docker.app/Contents/MacOS/com.docker.supervisor -watchdog fd:0 501 5576 5561 0 3:10PM ttys001 0:00.00 grep Docker
The "ps" command displays all the processes running on the host machine, then I use the "|" pipe command to filter the output of the whole list of processes looking only for "Docker". Look at the highlighted information, the process ID 5584 was listed as well so with that I can confirm the information displayed on the GUI and by the terminal is the same and docker is for sure running on my host machine.
There is also another alternative using one of the Docker commands, we can use the "ps" docker command to list all the containers running and their respective status:
mylaptop:~ master$ docker ps -q -a | wc -l 1
The output of the command above is 1, that's means there is one container running on Docker. In case it returns zero, this is because there is no container running.
Install the Docker Image
Let's focus on Docker now that we know it's installed and running. First, we have to choose the docker image we want to download, in this tip I will focus on SQL Server 2019 CTP 2.2, but we can explore the list of available images in Microsoft Docker hub for SQL Server:
Please note that Microsoft now has two options for Linux containers. The traditional Ubuntu version and now the new RHEL version, which I will use during the explanation of this tip.
The reason why I chose the RHEL version is simple, I consider RedHat a more robust and enterprise type distribution. I consider Ubuntu, an everyday use distribution that doesn't have the rich administration tools like RedHat has out of the box.
In order to download the latest SQL Server 2019 image, you have to pull the image from Microsoft's repository. This image contains SQL Server 2019 pre-installed on RHEL and ready to use.
Run the following command:
mylaptop:~ master$ docker pull mcr.microsoft.com/mssql/rhel/server:vNext-CTP2.2 Password: vNext-CTP2.2: Pulling from mssql/rhel/server c181936b24e2: Pull complete dab9f87f3be2: Pull complete a15f5fdc0403: Pull complete 398970576523: Pull complete Digest: sha256:15f924fad56da2946ae7297656e122d7885cab6d2914172e706dfdd2e1e4b28d Status: Downloaded newer image for mcr.microsoft.com/mssql/rhel/server:vNext-CTP2.2
Once the download starts, Docker will ask for your account prior to start the download. Once it's complete it should show the message "Pull complete" and an ID will be assigned to the image.
Now, that the Linux container image was downloaded to the local machine it's time to start a new container with the image previously downloaded.
In order to start the container, I will use the Docker command "run", combined with multiple options that I will explain later in this tip:
mylaptop:~ master$ docker run > --name dbamastery_rhel > --volume "/Users/master/Documents/Linux":/MyShared > --env 'ACCEPT_EULA=Y' > --env 'SA_PASSWORD=Str0ngP4$$w0rd' > --publish 1433:1433 > --detach mcr.microsoft.com/mssql/rhel/server:vNext-CTP2.2
*Please note, the "\" symbol is used only to break out lines and make the text more readable.
Let's review in detail each parameter I used to start this container:
This parameter is self-explanatory, it is
nothing less than the container name which will be called when running maintenance
or administrative tasks so be careful to use a comprehensive and unique
If no value is passed to this parameter, Docker will generate a random name that could not be convenient for administration purposes.
This parameter consists of two fields separated
by a colon character. The first field is the name of the volume from the
host machine, the second is the name of the container folder that will be
mapped with the host machine volume.
It is always nice to have a shared folder between the container and host machine in order to transfer files like backups, scripts, etc.
|--env: ACCEPT_EULA||Passing "Y" to this variable means we confirm the acceptance of the end user licensing agreement|
|--env: SA_PASSWORD||Pass a strong password value, it must be 8 characters and meets the SQL Server password requirements.|
|--publish||This parameter maps a TCP port between the host machine (first value) and the container (second value), in this example I'm mapping the port 1433 between my local machine and the container, but it's your choice and would definitively change if you have more than one container.|
|--detach||This parameter allows the container to run in the background of the host machine terminal, but it does not receive input or display output.|
At this point, I have successfully created the container using the RHEL SQL Server 2019 image.
Now it's time to learn how to manage the image. The following section will use the built-in macOS terminal, please make sure to follow the instructions I explained at the beginning of this tip on how to open this application.
How to check the container status
The simplest way to check the status of any container is using the docker "ps" command:
mylaptop:~ master$ docker ps -a
Noticed I used the "-a" parameter, which will display the entire list of containers deployed on this docker instance, it also displays the associated image and status (running \ stopped).
Now, imagine you want to know the list of containers where the status is running:
mylaptop:~ master$ docker ps –-filter status=running
The filter command can be extended to all the possible container statuses as:
How to stop container
Remember the importance of choosing a comprehensive name for the container? This parameter uses the name we passed as the parameter when starting the container, it is easier to use that name than the one randomly generated when no parameter is passed.
In order to stop the container, you must combine the "stop" docker command with the container name as follows:
mylaptop:~ master$ docker stop dbamastery_rhel
How to start container
In order to start the container, you must combine the "start" docker command with the container name as follows:
mylaptop:~ master$ docker start dbamastery_rhel
How to connect to SQL Server inside the container
Ok, so we learned the basics of how to stop and start the container, but what about managing the container image from the inside? In order to achieve this, we need to use the "exec" docker command and use the "-I" parameter that means interactive. This command can be also combined with the "-t" parameter which means "tty" as any devices that acts like teletype in a terminal.
mylaptop:~ master$ docker exec -it dbamastery_rhel "bash"
[[email protected] /]# [[email protected] /]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.5 (Maipo)
As you can see above, I was able to connect and check the version for the container image OS in this case it's a RHEL 7.5.
Let's connect to SQL Server through SQLCMD and let's find out the SQL Server version:
mylaptop:~ master$ docker exec -it dbamastery_rhel "bash" [[email protected] /]# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA Password: 1> select @@version; 2> go ------------------------------------------------------------------------------------- Microsoft SQL Server vNext (CTP2.2) - 15.0.1200.24 (X64) Dec 18 2018 02:32:04 Copyright (C) 2018 Microsoft Corporation Developer Edition (64-bit) on Linux (Red Hat Enterprise Linux Server 7.5
Now we have a fully functional SQL Server 2019 CTP 2.2 running on RedHat Linux which can be used as a temporary sandbox and discarded afterwards.
- Learn more about Docker Volumes
- Learn how to make SQL Server data persistent in the host machine file systems
- Learn how to transfer files between the host machine and Docker
- Learn how to connect to SQL Server using Azure Data Studio
About the author
View all my tips