Installing SqlServer on Linux

· 322 words · 2 minute read

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
and type the following: (The configuration below will run the sql server container in the developer edition)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
version: '3'
services:
  sqlserver:
    image: mcr.microsoft.com/mssql/server:latest
    container_name: sqlserver1
    restart: always
    environment:
      - "ACCEPT_EULA=Y"
      - "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>"
    volumes:
      - ./data/sqlserver1/:/var/opt/mssql
    ports:
      - "1433:1433"

  • 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
you should see the following ![alt text](/imgs/0002 - sql server on linux.jpg “SqlServer”)

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.