In this tutorial we will pull a Sql Server docker image, create a docker-compose script and connect to this new server using SSMS (sql server management studio)
I keep all my databases, queues and other infrastructure tools on a linux box running as docker containers. Docker gives me the flexibility of installing multiple things without messing up my dev environment and I recently added SqlServer
Pull the docker image into your linux box
sudo docker pull mcr.microsoft.com/mssql/server
Install docker compose (if you don’t have it)
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
Create a new docker-compose.yml file
sudo nano docker-compose.yml
- Line 4 - Specifies the docker image we have just pulled.
- Line 6 - Tells the container it will always be restarted.
- Line 8-9 - Specific variables required by Sql Server. Note we are supplying the sa password here.
- Line 11 - It specifies where the data will be persisted. If you don’t specify anything here and remove the sql server container you will lose all the data.
- Line 13 - It exposes the container outside the docker. You want to map the port otherwise you won’t have access to sql server from your dev environment.
now we can start docker compose
sudo docker-compose up
and make sure sql server is up
sudo docker ps -a
Connecting via SSMS
Now that the server is up and running and the container is exposed to connections outside the docker, we are able to use it normally and connect to it via SSMS or our application.