Docker – How to run SQL Server in a Docker container

By | 05/01/2022

In this post, we will see how to run SQL Server in a Docker container using a docker-compose file.

We start opening VS Code and we create a file docker-compose.yaml where, we will add this code:

[DOCKER-COMPOSE.YAML]

version: "3.9"
services:
  sql-server-db:
    container_name: sqlserver
    image: mcr.microsoft.com/mssql/server:latest
    ports:
      - "1439:1433"
    environment:
      SA_PASSWORD: "password1234"
      ACCEPT_EULA: "Y"
      MSSQL_PID: Express
    volumes:
      - sqlvolume:/var/opt/mssql

# ... volumes section
volumes:
  sqlvolume: 
    driver: local


I want to explain some rows:
line 5 => we get latest version of mssql
line 7 => we define the port 1439 for the host, in order to avoid possible conflicts if we have previously
installed SQL Server in the Host
line 9 => we define password for SA user
line 13 => we define a volume to avoid losing data

Now, we run the file and then, we will use SQL Server Management Studio to connect at this SQL Server instance:

docker-compose up -d






Leave a Reply

Your email address will not be published. Required fields are marked *