We independently review everything we recommend. When you buy through our links, we may earn a commission.
Learn how to set up and connect to a Microsoft SQL Server database on a Linux server using Docker containers in this tutorial. Description:
Microsoft SQL Server is a database management system that is both reliable and widely used (DBMS). In the past, SQL Server databases were set up on dedicated servers or virtual machines; however, Docker has changed all of that.
In this section, we’ll go over the process of installing and configuring a SQL Server instance on a Linux container using Docker.
Advantages of Running SQL Server in Docker
When it comes to software engineers debating whether or not to run SQL Server in Docker, here are some of the benefits that Docker has to offer, in no particular order:
- A dedicated server or virtual machine is not required, which saves you money and makes the process more efficient.
- Docker is a lightweight container platform that is reasonably simple to set up and configure.
- Using scripts, you can quickly automate the deployment and configuration processes.
- Docker lets you to quickly and simply construct homogeneous environments, and you can use the same docker image on any operating system, including macOS, Windows, and Linux, without having to worry about compatibility issues.
- Docker is a strong tool that has the potential to significantly improve the way software systems are deployed and provisioned.
Step 1: Getting the SQL Server Docker Image
To be able to set up SQL Server on Docker, you’ll need to have Docker version 1.8 or above installed. This article will show you how to install Docker on Ubuntu Linux if you are using it. For information on how to install Docker on different Linux distributions, visit the official Docker website.
Using the command below, you can download the SQL Server Docker image from the official Microsoft Docker repository on the Microsoft Azure cloud. Initially, Docker will check for the image on your computer, and if it cannot find it there, it will look for the image on remote repositories accessible over the internet.
Currently, SQL Server 2019 is the most recent version of SQL Server that is supported on Docker, as of the time of this writing.
Step 2: Running the Docker Image
Once the docker image is finished downloading, you can list or view all Docker images on your PC by running the following command:
sudo docker images
If your SQL Server image is shown, you are ready to proceed with the installation. Here are certain Docker command arguments that you should be familiar with before proceeding.
Docker Command Parameters Description
- -e “ACCEPT EULA=Y”: This option is used to accept the terms of the End-User License Agreement.
- It is possible to set the SA password of a Docker image with the -e “SA PASSWORD=Adminxyz22#” option. It has been determined that the password is Adminxyz22# in this instance. Always choose a strong password with at least eight characters to protect your information.
- -p 1433:1433: SQL Server is configured to run on port 1433 by default. This argument simply states that the host system should use port 1433 to communicate with the Docker image on port 1433.
- —name: This option allows you to give a name for your Docker image; otherwise, Docker will assign a random name to your container image.
- When you provide a hostname for your SQL Server, it will be assigned to that hostname. If you don’t specify a hostname, Docker will generate one for you at random.
sudo docker run -e “ACCEPT_EULA=Y” -e “SA_PASSWORD=Adminxyz22#” -p 1433:1433 –name sql1 –hostname sql1 -d mcr.microsoft.com/mssql/server:2019-latest
Step 3: Connecting to the SQL Server From Docker Container
SQL Server clients, such as the command line, Microsoft SQL Server Management Studio, Azure Data Studio, and others, can be used to connect to the SQL Server instance running in Docker containers. Azure Data Studio is a lightweight application that is accessible for macOS, Windows, and Linux users to use. The following steps will walk you through installing Azure Data Studio on Ubuntu.
Now, let’s connect to the SQL Server that is running on Docker using the Ubuntu console. To begin, use the following command to gain access to the docker container’s terminal: first.
sudo docker exec -it sql1 “bash”
To connect to the SQL Server, once you’ve opened the interactive terminal on the Docker image, type the following command into your browser:
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P “Adminxyz22#”
Following your connection, you may view a list of accessible databases by running the following command:
SELECT Name FROM sys.Databases
Once you’ve done that, write GO in the next box and hit Enter to run your SQL query:
Running Microsoft SQL Server on a Docker Container
Our investigation on running SQL Server 2019 inside of a Linux container using Docker has concluded. Thousands of software professionals rely on Docker to deploy programs and build up complicated environments in a simple and straightforward manner.