Microsoft SQL Server is a sturdy and extensively used database administration system (DBMS). Traditionally, SQL Server databases have been arrange on devoted servers or digital machines, however Docker has modified all that.
Let’s take a take a look at how one can arrange a SQL Server occasion on a Linux container with Docker.
Advantages of Running SQL Server in Docker
If you might be a software program engineer contemplating whether or not you need to run SQL Server in Docker, effectively, listed here are a number of the benefits that Docker provides:
- Cost-effective and light-weight: You don’t want to arrange a devoted server or digital machine
- Docker is comparatively straightforward to arrange and configure
- You can simply automate the deployment and setup course of with scripts
- Docker permits you to simply create uniform environments, and you should use the identical docker picture on any working system together with macOS, Windows, or Linux
Docker is a highly effective instrument and it could possibly massively remodel the way you deploy or provision your software program techniques.
Step 1: Getting the SQL Server Docker Image
You’ll want Docker model 1.8 or above to give you the option to arrange SQL Server on Docker. If you might be utilizing Ubuntu Linux, here’s how to install Docker. Check out the official Docker site on how to set up Docker on different Linux distros.
Pull the SQL Server Docker picture from the official Microsoft Docker repository utilizing the command under. Docker will first search for the picture on your PC, and if it doesn’t discover it domestically it is going to seek for the picture on distant repositories through the web.
sudo docker pull mcr.microsoft.com/mssql/server:2019-latest
SQL Server 2019 is the most recent supported model of SQL Server on Docker on the time of this writing.
You can drop sudo from the command above in the event you’ve configured your Docker to run with a non-root person.
Step 2: Running the Docker Image
Once the docker picture is completed downloading, you may listing or view all Docker photographs on your PC by operating the next command:
sudo docker photographs
If your SQL Server picture is listed, then you might be prepared to run it. But earlier than you do, listed here are some Docker command parameters that you ought to be conscious of.
Docker Command Parameters Description
- -e “ACCEPT_EULA=Y”: Used for accepting End-User License Agreement phrases
- -e “SA_PASSWORD=Adminxyz22#”: Used for setting the SA password of the Docker picture. In this case, the password is about to Adminxyz22#. Make certain you employ a robust password that’s at the very least eight characters lengthy.
- -p 1433:1433: By default, SQL Server runs on port 1433. This parameter merely says: use port 1433 on the host machine to join to port 1433 on the Docker picture.
- –name: Use this feature to specify a title in your docker picture, in any other case, Docker will generate a random title for you.
- –hostname: Use this feature for assigning a hostname to your SQL Server. Docker will generate a random hostname in the event you do not assign one.
It is vital that you simply assign a significant title and hostname to your Docker picture as a result of that is what you’ll use in your connection strings to join to your database.
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
You can join to the SQL Server occasion on Docker utilizing SQL Server purchasers such because the command line, Microsoft SQL Server Management Studio, Azure Data Studio, and so forth. Azure Data Studio is light-weight and obtainable on macOS, Windows, and Linux. Here’s how to install Azure Data Studio on Ubuntu.
Let’s use the Ubuntu terminal to join to the SQL Server operating on Docker. First, run the next command to entry the terminal of the docker container:
sudo docker exec -it sql1 "bash"
When you’ve got accessed the interactive terminal on the Docker picture, run the next command to join to the SQL Server:
/choose/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Adminxyz22#"
The default username for the SQL Server picture on Docker is SA. Also, bear in mind to use the right password that you have assigned to your SQL Server occasion.
Once linked, you may listing obtainable databases utilizing the command:
SELECT Name FROM sys.Databases
Then kind GO in the subsequent immediate and press Enter to execute your SQL question:
Running Microsoft SQL Server on a Docker Container
We’ve checked out how to run SQL Server 2019 inside a Linux container on Docker. Docker is extensively utilized by many software program engineers for deploying functions and establishing advanced environments with ease.
6 Reasons to Use Docker Virtualization Software
About The Author