Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications which may run either on the same computer or on another computer across a network.
In this guide we are going to explore how to run MS SQL Server 2019 Locally with docker and docker compose. This can be helpful if you want to run MSSQL locally without installing it in your laptop or if you want to run multiple versions of MsSQL seamlessly.
Also check these:
- How to install and set up Ms SQL Server 2019 on Ubuntu 22.04
- Running Postgresql 14 with Docker and Docker-Compose
- Install and set up php to connect to MsSQL Server Rocky Linux 8
- How to run Mysql 8 with Docker and Docker-Compose
- How to run Redis 6 with Docker and Docker-Compose
- How to run Cassandra 4 with Docker and Docker-Compose
To follow along, ensure you have the following:
- Docker installed locally and permissions to use it to launch containers
- Docker compose installed locally
- Basic knowledge of the command line
Running mssql using docker run command
Let’s run mssql server using the docker run like in this command. We are using the
mcr.microsoft.com/mssql/server:2019-latest image in this example
In the above command:
-dinstructs docker container to run as a detached process. It run container in background and print container ID
-pis for port mapping. We are instructing the container to expose the container port externally. Container port
1433is mapped to host port
1433. That means the service can be accessed through
-vdirective is used to mount volumes. In our case we are mounting the container volume
/var/lib/mssqlql/datato host path
~/apps/mssql. Containers are ephemeral devices that will contain its data for the time it is running. Once a container is stopped, its data is lost. Mounting volumes ensures that the data is added to a host path that can be reused when the container is restarted.
-eargument is for the environment variables. The supplied environment variables will be used to set up a accept mssql licence terms, and set up a password for the mssql
To check that our container is running as expected, use the
docker ps command:
In my case the container is running as
my-mssql-server the name we gave it.
Let’s login to the container using the
docker exec command while executing
/bin/bash interactively. Here we are also logging in to the mssql server with the credentials we specified above and checking the version.
If you need to clean up the container when not in use, you can stop and remove the container using this command:
Using the docker-compose tool
We can achieve the same functionality with
docker-compose. Docker Compose is a tool for defining and running multi-container Docker applications. With Docker Compose, you use a YAML file to configure your application’s services.
Docker Compose allows you to define the service (MsSQL in our case) with properties like the
image to use,
ports to expose,
volumes to mount and
Here is how we would use
docker-compose to achieve the functionality above. Save this as
Let’s bring up the container:
upbrings up the container
-din a detached mode
Verify the container processes using the ps command:
To login to the container and login to mssql, use this:
In this guide, we managed to run MsSql 2019 as a container in our system, We explored using the
docker run command while passing the required arguments an alternative approach of simplifying the process with