Share your love
Install Latest MS SQL Server with Docker on Ubuntu 22.04
In this guide, we want to teach you to Install the Latest MS SQL Server, SQL Server 2022 with Docker on Ubuntu 22.04. Currently, SQL Server 2022 has a preview list for Ubuntu 22.04. So you can use Docker to easily install the latest SQL server on Ubuntu 22.04. It is one of the best database management systems that can be used on Linux distros. You can follow the steps below to start your Microsoft SQL Server installation on Ubuntu 22.04 by using the Docker.
Steps To Install the Latest MS SQL Server with Docker on Ubuntu 22.04
Because we want to install an MS SQL server with Docker, we need some requirements first. Let’s see what we need.
Requirements
First, you must have access to your server as a non-root user with sudo privileges. To do this, you can follow the Ubuntu 22.04 Initial Server Setup Guide.
Also, you must have Docker running on your server. For this purpose, you can visit the Docker Installation Guide on Ubuntu 22.04.
Now follow the steps below to complete this guide.
Step 1 – Verify Docker Status on Ubuntu 22.04
First, you need to be sure that Docker is up and running on your server. To do this, you can use the command below:
sudo systemctl status docker
In your output, you should see:
Output
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset>
Active: active (running) since Wed 2023-09-20 07:53:02 UTC; 40s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 8985 (dockerd)
Tasks: 9
Memory: 27.0M
CPU: 549ms
CGroup: /system.slice/docker.service
└─8985 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont>
Step 2 – Pull MS SQL Server Docker Image
At this point, you need to use the docker pull command to download the latest image of the MS SQL server on Ubuntu 22.04. To do this, run the command below:
docker pull mcr.microsoft.com/mssql/server:2022-latest
When your download is completed, you will get the following output:
Output
2022-latest: Pulling from mssql/server
e481c36a257f: Pull complete
7d8f784510c6: Pull complete
c6ac2a806f6c: Pull complete
1b1611617f54: Pull complete
Digest: sha256:d00c97dedf4f5c785bbbd5894f490d50124ff409d7751fbba2d53eb7de9965da
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2022-latest
mcr.microsoft.com/mssql/server:2022-latest
Step 3 – Create and Run MS SQL Server Docker Container on Ubuntu 22.04
At this point, you must create a container for the SQL server that you can use to run it. To do this, you can use the following command:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Strongpassword" \
-p 1433:1433 --name sql1 --hostname sql1 \
-d \
mcr.microsoft.com/mssql/server:2022-latest
The options used in the command mean:
- -e “ACCEPT_EULA=Y”: Confirm your acceptance of the End-User Licensing Agreement.
- -e “MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>”: 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 sql1: Specify a name for the container.
- –hostname sql1: Used to explicitly set the container hostname.
- -d: Run the container in the background.
- mcr.microsoft.com/mssql/server:2022-latest: Docker image name.
When it is done, you will get the following output:
Output
9542b451c2f120f4441da3f7e2f3a410681aa9eacde07191bffea408ab523a75
Note: Your password must be at least 8 characters and contain uppercase characters, digits, and symbols.
Step 3 – Verify your SQL Server Container is Running on Ubuntu 22.04
Now you can verify your Docker container is up and running on your server with the following command:
docker ps -a
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fef8fd9b00be mcr.microsoft.com/mssql/server:2022-latest "/opt/mssql/bin/perm…" 8 seconds ago Up 7 seconds 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp sql1
Step 4 – Connect To SQL Server Command Line Shell
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 sql1 "bash"
This will change your prompt to your container.
mssql@sql1:/$
Then, use the following command tool sqlcmd to connect to your shell:
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "sql-server-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:
> GO
1> CREATE DATABASE TestDB;
2> SELECT Name from sys.databases;
3> GO
Name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
TestDB
(5 rows affected)
1>
To get a List of Microsoft SQL Server queries and commands, you can visit this link.
Conclusion
At this point, you have learned To Install the Latest MS SQL Server with Docker on Ubuntu 22.04. Because the repository of the SQL server doesn’t support the Ubuntu 22.04, you can easily run the SQL server in a Docker container and start using it.
Hope you enjoy it. You may be interested in these articles:
Install a Specific Version of PostgreSQL on Ubuntu 20.04
Fantastic blog you have here but I was curious if you knew
of any community forums that cover the same topics discussed here?
I’d really love to be a part of community where I can get suggestions
from other knowledgeable people that share the same interest.
If you have any recommendations, please let me
know. Kudos!