This tutorial intends to teach you MS SQL Server Setup with Docker on RHEL 9, you can easily Install the latest SQL server on AlmaLinux 9 and Rocky Linux 9 by using Docker. SQL Server is one of the best database management engines that you can use on your Linux distributions. You can easily pull the latest SQL server which is SQL 2022 by using Docker on your RHEL 9 server. You can easily follow the rest of the article to see how you can do it.
Steps To MS SQL Server Setup with Docker on RHEL 9
To complete this guide, you need some requirements. So let’s see what we need for MS SQL Server Setup. In this guide, to show you the installation steps we use the AlmaLinux 9 server.
Requirements For SQL Server Installation
First, you must log in to your server as a non-root user with sudo privileges. You can check the AlmaLinux 9 initial server setup guide.
Because we want to use Docker to get an MS SQL server, you must have Docker installed on your server. To do this, you can check the Docker Installation Guide on AlmaLinux 9.
Note: If you use Rocky Linux 9, you can check the Orcacore website and search for the Docker installation on Rocky Linux 9.
Step 1 – Confirm Docker is Running on RHEL 9
First, you must be sure that your Docker is active and running on your server. To do this, you can run the command below:
sudo systemctl status docker.service
Step 2 – Download Latest MS SQL Server Image on RHEL 9
At this point, you can simply use the Docker Pull command to download the latest image for MS SQL. To do this, you can run the following command:
docker pull mcr.microsoft.com/mssql/server:2022-latest
When your download is completed, you will get the following output:
Step 3 – Run MS SQL Docker Container on RHEL 9
At this step, you must create a container for your MS SQL and start to run it. To do this, you can run the following command:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Strong@password" \
-p 1433:1433 --name sql2 --hostname sql2 \
Let’s see what the options mean in the above command:
- -e “ACCEPT_EULA=Y”: Confirm your acceptance of the End-User Licensing Agreement.
- -e “MSSQL_SA_PASSWORD=”: Specify a strong password for the SQL server.
- -p 1433:1433: SQL Server is listening on TCP 1433 in the container and this container port is then exposed to TCP port 1433 on the host.
- –name: Specify a name for the container.
- –hostname: Used to explicitly set the container hostname.
- -d: Run the container in the background.
- mcr.microsoft.com/mssql/server:2022-latest: Docker image name.
Note: Your password must be at least 8 characters and contain uppercase characters, digits, and symbols.
Once you run the command, you will get something similar to this in your output:
Step 4 – Confirm the MS SQL Container is Active and Running
Next, you can confirm that your MS SQL server Docker container is active and running by using the command below:
docker ps -a
Step 5 – Access SQL Server Shell on RHEL 9
At this point when your SQL server container is up and running, you can use the SQL server command-line utility named sqlcmd to connect to your shell.
First, you need to start an interactive shell inside your SQL server container by using the command below:
docker exec -it sql2 "bash"
This will change your prompt to your container.
Then, use the following command tool sqlcmd to connect to your shell: Put the password you have created for your SQL server and press enter.
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Strong@password"
Put the password you have created for your SQL server and press enter. Now you will see your SQL shell as follows:
From your SQL server shell, you can easily run your commands to create databases and manage them.
For example, we create a test database and want to show you the system databases. To do this, run the following commands:
> CREATE DATABASE TestDB;
> SELECT Name from sys.databases;
This will not show you the results, to see the results you must enter the GO command:
That’s it, you are done. As you can see, you can simply use Docker to get the latest MS SQL on your RHEL 9 server and start to run and use it.
To get a List of Microsoft SQL Server queries and commands, you can visit this link.
At this point, you have learned MS SQL Server Setup with Docker on RHEL 9 such as AlmaLinux 9 and Rocky Linux 9. You can easily pull the latest image, create a container for it, run the container, and access the MS SQL server Shell. Hope you enjoy it.
Also, you may interested in these articles: