Using Docker-Compose to Build Up a MSSQL Image

Install docker-compose

In powershell with Admin right:

# since GitHub now requires TLS1.2, run the following:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Download docker-compose
Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\Docker\docker-compose.exe

Test installation:

docker-compose --version

docker-compose version 1.24.0, build 01110ad01

dockerfile structure

version: '3'
services:
 
  sqlserver:
    image: microsoft/mssql-server-windows-developer:latest-14393
    container_name: sqlserver2
    ports:
      ["1433:1433"]
    volumes:
      - c:\MSSQL Data:c:\MSSQL Data
    environment:
      sa_password: Atalces!1
      accept_eula: Y
      # the container will attach to the host's database 
      attach_dbs: "[{'dbName':'trunk','dbFiles':['c:\\\\MSSQL Data\\\\trunk.mdf','c:\\\\MSSQL Data\\\\trunk_Log.ldf']}]"
    networks:
      default:
        ipv4_address: 172.20.32.244
        aliases:
          - qsql
  
networks:
  default:
    external:
      name: nat

Run docker-compose

Route to the folder which contains the docker-compose.yml file, run the following:

docker-compose up -d

Last updated

Was this helpful?