Create an Sql Server Container with Northwind and Adventureworks built-in
Reference
Referenced this article:- Dockerize SqlServer with build in Adventureworks and Northwinds
Changed it for my specific use case.
Steps
-
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
-
Build the image
docker build -t sql-server-2022 .
-
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
-
Log in to the container
docker exec -it sqlserver1 "bash"
-
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"
-
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"'