December 8, 2018

Installing SqlServer on Linux

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

Install docker compose (if you don’t have it)

sudo curl -L "$(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)
version: '3'
    container_name: sqlserver1
    restart: always
      - "ACCEPT_EULA=Y"
      - "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>"
      - ./data/sqlserver1/:/var/opt/mssql
      - "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

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.

Copyright © William Leme