Home Running SQL Server using Docker Compose
Post
Cancel

Running SQL Server using Docker Compose

This was much easier than I thought. Using the following docker compose file, you can run SQL Server locally in docker. It is critical to use a volume for the mssql directory, otherwise you will lose all your data when the container restarts. The image is first party (published by Microsoft) listed in docker hub, though the container is pulled down from Microsoft’s registry directly I think.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# docker-compose.yaml

services:
  sql-server-db:
    container_name: sql-server-db
    image: mcr.microsoft.com/mssql/server:2022-latest
    ports:
      - "1433:1433"
    environment:
      SA_PASSWORD: ${SA_PASSWORD}
      ACCEPT_EULA: "Y"
      UID: 1000
    volumes:
      - ./mssql:/var/opt/mssql:rw

You’ll also need to change the sa account password, or create an .env file.

1
2
3
# .env

SA_PASSWORD=some_random_password

Now you should be able to get things running with docker compose up -d. Check the logs with docker compose logs -f. Once this is up and running, you can access it normally through SSMS or Azure Data Studio. The connection will require you to use encryption, though that should be handled automatically.

This post is licensed under CC BY 4.0 by the author.