Create an Sql Server Container with Northwind and Adventureworks built-in

general docker sql-server
Table of Contents

Reference

Changed it for my specific use case.

Steps

  1. Create the docker file

    FROM mcr.microsoft.com/mssql/server:2022-latest
    
    USER root
    COPY ./Northwind.bak /var/opt/mssql/data/
    COPY ./AdventureWorks2022.bak /var/opt/mssql/data/
    
    EXPOSE 1433
  2. Build the image

    docker build -t sql-server-2022 .
  3. Create and run the container

    docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" \
       -p 1433:1433 --name sqlserver1 --hostname sqlserver1 \
       -d \
       sql-server-2022
  4. Log in to the container

    docker exec -it sqlserver1 "bash"
  5. Execute the following

    /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P '<YourStrong!Passw0rd>' -Q 'RESTORE DATABASE Northwind FROM DISK = "/var/opt/mssql/data/Northwind.bak" WITH MOVE "Northwind" TO "/var/opt/mssql/data/Northwind.mdf", MOVE "Northwind_log" TO "/var/opt/mssql/data/Northwind_log.ldf"
  6. Execute the following

    /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YourStrong!Passw0rd>' -Q 'RESTORE DATABASE AdventureWorks2022 FROM DISK = "/var/opt/mssql/data/AdventureWorks2022.bak" WITH MOVE "AdventureWorks2022" TO "/var/opt/mssql/data/AdventureWorks2022.mdf", MOVE "AdventureWorks2022_log" TO "/var/opt/mssql/data/AdventureWorks2022_log.ldf"'