├── .vs ├── ProjectSettings.json ├── slnx.sqlite ├── VSWorkspaceState.json └── mssql-server-samplesdb │ └── v16 │ └── .suo ├── Backups ├── Pubs.bak └── Northwind.bak ├── .gitignore ├── .env ├── entrypoint.sh ├── setup.instance.sql ├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── setup.bigdatabases.attach.sql ├── Dockerfile ├── prerequisites.create_local_directories.sh ├── docker-compose-docker-registry.yml ├── setup.other_databases.attach.sql ├── setup.bigdatabases.restore.sql ├── docker-compose-demo4.yml ├── docker-compose.yml ├── setup.other_databases.restore.sql ├── Makefile ├── setup.attach.sql ├── setup.restore.sql ├── Demo3-PublishImageToDocker.md ├── Dockerfile-prepared-for-registry ├── setup.sh ├── CODE_OF_CONDUCT.md ├── Dockerfile-2017 ├── prerequisites.download_databases.sh ├── Demo4-running in ACI.md ├── LICENSE ├── Demo1-ManuallyRunContainer.md ├── Demo2-CreateImageWithData.md └── README.md /.vs/ProjectSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "CurrentProjectSetting": null 3 | } -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enriquecatala/mssql-server-samplesdb/HEAD/.vs/slnx.sqlite -------------------------------------------------------------------------------- /Backups/Pubs.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enriquecatala/mssql-server-samplesdb/HEAD/Backups/Pubs.bak -------------------------------------------------------------------------------- /Backups/Northwind.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enriquecatala/mssql-server-samplesdb/HEAD/Backups/Northwind.bak -------------------------------------------------------------------------------- /.vs/VSWorkspaceState.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExpandedNodes": [ 3 | "", 4 | "\\Backups" 5 | ], 6 | "PreviewInSolutionExplorer": false 7 | } -------------------------------------------------------------------------------- /.vs/mssql-server-samplesdb/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enriquecatala/mssql-server-samplesdb/HEAD/.vs/mssql-server-samplesdb/v16/.suo -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | local_mountpoint/data/* 2 | local_mountpoint/shared_folder/* 3 | Backups/* 4 | !Backups/Northwind.bak 5 | !Backups/Pubs.bak 6 | config.log -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | LOCAL_MOUNTPOINT=./local_mountpoint/data/ 2 | SHARED_FOLDER=./local_mountpoint/shared_folder/ 3 | FORCE_ATTACH_IF_MDF_EXISTS=0 4 | INCLUDE_ALL_DATABASES=0 -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Enrique Catalá: 4 | # Web: https://www.clouddataninjas.com 5 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 6 | # Support: https://github.com/sponsors/enriquecatala 7 | 8 | 9 | # Start SQL Server 10 | /opt/mssql/bin/sqlservr & /var/opt/mssql/setup/setup.sh 11 | eval $1 -------------------------------------------------------------------------------- /setup.instance.sql: -------------------------------------------------------------------------------- 1 | -- Enrique Catalá: 2 | -- Web: https://www.clouddataninjas.com 3 | -- Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | -- Support: https://github.com/sponsors/enriquecatala 5 | 6 | -- Script for prepare the instance 7 | -- Allow contained databases 8 | -- 9 | exec sp_configure 'contained database authentication',1 10 | go 11 | RECONFIGURE 12 | go -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [enriquecatala] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ["https://www.paypal.me/enriquecatala"] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /setup.bigdatabases.attach.sql: -------------------------------------------------------------------------------- 1 | -- Enrique Catalá: 2 | -- Web: https://www.clouddataninjas.com 3 | -- Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | -- Support: https://github.com/sponsors/enriquecatala 5 | 6 | -- Restoring databases 7 | -- 8 | -- AdventureWorksDW2017 9 | -- 10 | CREATE DATABASE [AdventureWorksDW2017] ON 11 | (FILENAME= N'/var/opt/mssql/data/AdventureWorksDW2017.mdf' ), 12 | (FILENAME= N'/var/opt/mssql/data/AdventureWorksDW2017_log.ldf') 13 | FOR ATTACH; 14 | 15 | -- -- StackOverflow2010 16 | -- -- 17 | -- CREATE DATABASE [StackOverflow2010] ON 18 | -- ( FILENAME = N'/var/opt/mssql/data/StackOverflow2010.mdf' ), 19 | -- ( FILENAME = N'/var/opt/mssql/data/StackOverflow2010_log.ldf' ) 20 | -- FOR ATTACH 21 | -- GO -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/mssql/server:2019-latest 2 | EXPOSE 1433 3 | 4 | LABEL "MAINTAINER" "Enrique Catalá Bañuls " 5 | LABEL "Project" "Microsoft SQL Server image with sample databases" 6 | 7 | RUN mkdir -p /var/opt/mssql/setup 8 | 9 | # Copy the backup files to the container 10 | WORKDIR /var/opt/mssql/setup 11 | 12 | COPY setup.* ./ 13 | COPY entrypoint.sh ./ 14 | 15 | # Since SQL Server 2019 is non-root container, we need to force this to install packages 16 | USER root 17 | RUN chown -R 10001:0 setup.sh entrypoint.sh 18 | 19 | # Get to the default user 20 | USER 10001 21 | RUN chmod +x setup.sh entrypoint.sh 22 | 23 | # This entrypoint start sql server, restores data and waits infinitely 24 | ENTRYPOINT ["./entrypoint.sh"] 25 | CMD ["sleep infinity"] -------------------------------------------------------------------------------- /prerequisites.create_local_directories.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Enrique Catalá: 4 | # Web: https://www.clouddataninjas.com 5 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 6 | # Support: https://github.com/sponsors/enriquecatala 7 | 8 | 9 | # Define the base directory and backups directory 10 | BASE_DIR="./local_mountpoint" 11 | BACKUPS_DIR="./Backups" 12 | 13 | # Create directories 14 | mkdir -p "$BASE_DIR/data/" 15 | mkdir -p "$BASE_DIR/shared_folder/" 16 | mkdir -p "$BACKUPS_DIR" 17 | 18 | # Set ownership for mssql user (requires sudo) 19 | sudo chown 10001:0 "$BASE_DIR/data/" 20 | sudo chown 10001:0 "$BASE_DIR/shared_folder/" 21 | 22 | # Set permissions (requires sudo) 23 | sudo chmod +rwx "$BASE_DIR/data/" 24 | sudo chmod +rwx "$BASE_DIR/shared_folder/" 25 | 26 | echo "Directories created and permissions set." 27 | -------------------------------------------------------------------------------- /docker-compose-docker-registry.yml: -------------------------------------------------------------------------------- 1 | version: '2.2' 2 | 3 | # Enrique Catalá: 4 | # Web: https://www.clouddataninjas.com 5 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 6 | # Support: https://github.com/sponsors/enriquecatala 7 | 8 | services: 9 | db1: 10 | container_name: mssql-server-samplesdb 11 | build: 12 | context: . 13 | dockerfile: Dockerfile-prepared-for-registry 14 | hostname: 15 | mssql-server 16 | domainname: 17 | enriquecatala.com 18 | environment: 19 | MSSQL_SA_PASSWORD: "PaSSw0rd" 20 | ACCEPT_EULA: "Y" 21 | MSSQL_PID: "Developer" 22 | FORCE_ATTACH_IF_MDF_EXISTS: "0" 23 | volumes: 24 | - ${LOCAL_MOUNTPOINT}:/var/opt/mssql/data 25 | ports: 26 | - "14330:1433" 27 | mem_limit: 8Gb 28 | cpu_count: 4 29 | -------------------------------------------------------------------------------- /setup.other_databases.attach.sql: -------------------------------------------------------------------------------- 1 | -- Enrique Catalá: 2 | -- Web: https://www.clouddataninjas.com 3 | -- Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | -- Support: https://github.com/sponsors/enriquecatala 5 | 6 | CREATE DATABASE [AdventureWorks2016] ON 7 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2016.mdf' ), 8 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2016_log.ldf') 9 | FOR ATTACH; 10 | 11 | CREATE DATABASE [AdventureWorks2014] ON 12 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2014.mdf' ), 13 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2014_log.ldf') 14 | FOR ATTACH; 15 | 16 | 17 | CREATE DATABASE [AdventureWorks2012] ON 18 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2012.mdf' ), 19 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2012_log.ldf') 20 | FOR ATTACH; 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /setup.bigdatabases.restore.sql: -------------------------------------------------------------------------------- 1 | -- Enrique Catalá: 2 | -- Web: https://www.clouddataninjas.com 3 | -- Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | -- Support: https://github.com/sponsors/enriquecatala 5 | 6 | -- NOTE: Since there is a bug with WSL2 on Windows10, we can´t restore databases directly and first require a deploy of empty data, thats the reason for the CREATE DATABASE commands 7 | -- AdventureworksDW2017 8 | -- 9 | 10 | RESTORE DATABASE [AdventureWorksDW2017] FROM 11 | DISK = N'/var/opt/mssql/backup/AdventureWorksDW2017.bak' WITH 12 | FILE = 1, MOVE N'AdventureWorksDW2017' TO N'/var/opt/mssql/data/AdventureWorksDW2017.mdf', 13 | MOVE N'AdventureWorksDW2017_log' TO N'/var/opt/mssql/data/AdventureWorksDW2017_log.ldf', 14 | REPLACE, NOUNLOAD, STATS = 2; 15 | 16 | 17 | -- -- StackOverflow2010 18 | -- -- 19 | -- CREATE DATABASE [StackOverflow2010] ON 20 | -- ( FILENAME = N'/var/opt/mssql/data/StackOverflow2010.mdf' ), 21 | -- ( FILENAME = N'/var/opt/mssql/data/StackOverflow2010_log.ldf' ) 22 | -- FOR ATTACH 23 | -- GO -------------------------------------------------------------------------------- /docker-compose-demo4.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | # Enrique Catalá: 4 | # Web: https://www.clouddataninjas.com 5 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 6 | # Support: https://github.com/sponsors/enriquecatala 7 | 8 | services: 9 | db1: 10 | container_name: mssql-server-samplesdb 11 | image: enriquecatala/mssql-server-samplesdb:2019-latest 12 | hostname: 13 | mssql-server 14 | domainname: 15 | enriquecatala.com 16 | environment: 17 | MSSQL_SA_PASSWORD: "PaSSw0rd" 18 | ACCEPT_EULA: "Y" 19 | MSSQL_PID: "Developer" 20 | FORCE_ATTACH_IF_MDF_EXISTS: "0" 21 | # Local volumes not supported 22 | #volumes: 23 | # - ${LOCAL_MOUNTPOINT}:/var/opt/mssql/data 24 | # Port mapping not supported. You will be required to map to the same port 25 | ports: 26 | - "1433:1433" 27 | deploy: 28 | resources: 29 | limits: 30 | cpus: '2' 31 | memory: 8Gb 32 | reservations: 33 | cpus: '1' 34 | memory: 2Gb 35 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2.4' 2 | 3 | # Enrique Catalá: 4 | # Web: https://www.clouddataninjas.com 5 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 6 | # Support: https://github.com/sponsors/enriquecatala 7 | 8 | services: 9 | db1: 10 | container_name: mssql-server-samplesdb 11 | build: 12 | context: . 13 | dockerfile: Dockerfile 14 | hostname: 15 | mssql-samplesdb 16 | domainname: 17 | enriquecatala.com 18 | environment: 19 | MSSQL_SA_PASSWORD: "PaSSw0rd" 20 | ACCEPT_EULA: "Y" 21 | MSSQL_PID: "Developer" 22 | MSSQL_AGENT_ENABLED: "true" 23 | FORCE_ATTACH_IF_MDF_EXISTS: "${FORCE_ATTACH_IF_MDF_EXISTS}" 24 | INCLUDE_ALL_DATABASES: "${INCLUDE_ALL_DATABASES}" 25 | volumes: 26 | - ${LOCAL_MOUNTPOINT}:/var/opt/mssql/data 27 | - ${SHARED_FOLDER}:/var/opt/mssql/shared_folder 28 | - ./Backups:/var/opt/mssql/backup 29 | ports: 30 | - "14330:1433" 31 | cpu_count: 4 32 | mem_limit: 8Gb 33 | 34 | -------------------------------------------------------------------------------- /setup.other_databases.restore.sql: -------------------------------------------------------------------------------- 1 | -- Enrique Catalá: 2 | -- Web: https://www.clouddataninjas.com 3 | -- Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | -- Support: https://github.com/sponsors/enriquecatala 5 | 6 | RESTORE DATABASE [AdventureWorks2016] FROM DISK = N'/var/opt/mssql/backup/AdventureWorks2016.bak' WITH 7 | FILE = 1, MOVE N'AdventureWorks2016_Data' TO N'/var/opt/mssql/data/AdventureWorks2016_Data.mdf', 8 | MOVE N'AdventureWorks2016_Log' TO N'/var/opt/mssql/data/AdventureWorks2016_Log.ldf', 9 | REPLACE, NOUNLOAD, STATS = 2 10 | 11 | 12 | RESTORE DATABASE [AdventureWorks2014] FROM DISK = N'/var/opt/mssql/backup/AdventureWorks2014.bak' WITH 13 | FILE = 1, MOVE N'AdventureWorks2014_Data' TO N'/var/opt/mssql/data/AdventureWorks2014_Data.mdf', 14 | MOVE N'AdventureWorks2014_Log' TO N'/var/opt/mssql/data/AdventureWorks2014_Log.ldf', 15 | REPLACE, NOUNLOAD, STATS = 2; 16 | 17 | 18 | RESTORE DATABASE [AdventureWorks2012] FROM DISK = N'/var/opt/mssql/backup/AdventureWorks2012.bak' WITH 19 | FILE = 1, MOVE N'AdventureWorks2012' TO N'/var/opt/mssql/data/AdventureWorks2012.mdf', 20 | MOVE N'AdventureWorks2012_log' TO N'/var/opt/mssql/data/AdventureWorks2012_log.ldf', 21 | REPLACE, NOUNLOAD, STATS = 2 -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Enrique Catalá: 2 | # Web: https://www.clouddataninjas.com 3 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | # Support: https://github.com/sponsors/enriquecatala 5 | 6 | .PHONY: create-local-directories download-databases download-all-databases prerequisites build start all clean 7 | 8 | # Step 1: Create local directories 9 | create-local-directories: 10 | @echo "Creating local directories..." 11 | ./prerequisites.create_local_directories.sh 12 | 13 | # Step 2: Download databases with INCLUDE_ALL_DATABASES set to 1 14 | download-databases: 15 | @echo "Downloading databases to './Backups' folder..." 16 | INCLUDE_ALL_DATABASES=0 ./prerequisites.download_databases.sh 17 | 18 | download-all-databases: 19 | @echo "Downloading ALL databases to './Backups' folder..." 20 | INCLUDE_ALL_DATABASES=1 ./prerequisites.download_databases.sh 21 | 22 | # Prerequisites: Executes the creation of the directory and the download of the databases 23 | prerequisites: create-local-directories download-all-databases 24 | 25 | # Step 3: Build the Docker container 26 | build: 27 | @echo "Building Docker container..." 28 | docker compose build 29 | 30 | # Step 4: Start the Docker container 31 | start: 32 | @echo "Starting Docker container..." 33 | docker compose up 34 | 35 | # Default make target to run all steps 36 | all: 37 | @echo "Setting up the environment..." 38 | $(MAKE) prerequisites 39 | $(MAKE) build 40 | $(MAKE) start 41 | 42 | clean: 43 | @echo "Cleaning up everything, including databases..." 44 | docker compose down 45 | sudo rm -rf ./Backups/AdventureWorks* 46 | sudo rm -rf ./Backups/WideWorldImporters* 47 | sudo rm -rf ./local_mountpoint/ 48 | 49 | -------------------------------------------------------------------------------- /setup.attach.sql: -------------------------------------------------------------------------------- 1 | -- Enrique Catalá: 2 | -- Web: https://www.clouddataninjas.com 3 | -- Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | -- Support: https://github.com/sponsors/enriquecatala 5 | 6 | -- NOTE: Since there is a bug with WSL2 on Windows10, we can´t restore databases directly and first require a deploy of empty data, thats the reason for the CREATE DATABASE commands 7 | -- pubs 8 | CREATE DATABASE [Pubs] ON 9 | (FILENAME= N'/var/opt/mssql/data/Pubs.mdf' ), 10 | (FILENAME= N'/var/opt/mssql/data/Pubs_log.ldf') 11 | FOR ATTACH; 12 | 13 | -- Northwind 14 | CREATE DATABASE [Northwind] ON 15 | (FILENAME= N'/var/opt/mssql/data/Northwind.mdf' ), 16 | (FILENAME= N'/var/opt/mssql/data/Northwind_log.ldf') 17 | FOR ATTACH; 18 | 19 | -- AdventureWorks databases 20 | 21 | CREATE DATABASE [AdventureWorks2017] ON 22 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2017.mdf' ), 23 | (FILENAME= N'/var/opt/mssql/data/AdventureWorks2017_log.ldf') 24 | FOR ATTACH; 25 | 26 | -- WideWorldImporters 27 | -- 28 | CREATE DATABASE [WideWorldImporters] ON 29 | (FILENAME = N'/var/opt/mssql/data/WideWorldImporters.mdf'), 30 | (FILENAME = N'/var/opt/mssql/data/WideWorldImporters_UserData.ndf'), 31 | (FILENAME = N'/var/opt/mssql/data/WideWorldImporters_InMemory_Data_1'), 32 | (FILENAME = N'/var/opt/mssql/data/WideWorldImporters.ldf') 33 | FOR ATTACH; 34 | 35 | -- WideWorldImportersDW 36 | -- 37 | CREATE DATABASE [WideWorldImportersDW] ON 38 | (FILENAME = N'/var/opt/mssql/data/WideWorldImportersDW.mdf'), 39 | (FILENAME = N'/var/opt/mssql/data/WideWorldImportersDW_UserData.ndf'), 40 | (FILENAME = N'/var/opt/mssql/data/WideWorldImportersDW_InMemory_Data_1'), 41 | (FILENAME = N'/var/opt/mssql/data/WideWorldImportersDW.ldf') 42 | FOR ATTACH; -------------------------------------------------------------------------------- /setup.restore.sql: -------------------------------------------------------------------------------- 1 | -- Enrique Catalá: 2 | -- Web: https://www.clouddataninjas.com 3 | -- Linkedin: https://www.linkedin.com/in/enriquecatala/ 4 | -- Support: https://github.com/sponsors/enriquecatala 5 | 6 | 7 | -- Restoring databases 8 | -- 9 | RESTORE DATABASE [Pubs] FROM DISK = N'/var/opt/mssql/backup/Pubs.bak' WITH 10 | FILE = 1, MOVE N'pubs' TO N'/var/opt/mssql/data/Pubs.mdf', 11 | MOVE N'pubs_log' TO N'/var/opt/mssql/data/Pubs_log.ldf', 12 | REPLACE, NOUNLOAD, STATS = 5; 13 | 14 | -- Northwind 15 | -- 16 | RESTORE DATABASE [Northwind] FROM DISK = N'/var/opt/mssql/backup/Northwind.bak' WITH 17 | FILE = 1, MOVE N'Northwind' TO N'/var/opt/mssql/data/Northwind.mdf', 18 | MOVE N'Northwind_log' TO N'/var/opt/mssql/data/Northwind_log.ldf', 19 | REPLACE, NOUNLOAD, STATS = 5; 20 | 21 | -- AdventureWorks databases 22 | -- 23 | RESTORE DATABASE [AdventureWorks2017] FROM DISK = N'/var/opt/mssql/backup/AdventureWorks2017.bak' WITH 24 | FILE = 1, MOVE N'AdventureWorks2017' TO N'/var/opt/mssql/data/AdventureWorks2017.mdf', 25 | MOVE N'AdventureWorks2017_log' TO N'/var/opt/mssql/data/AdventureWorks2017_log.ldf', 26 | REPLACE, NOUNLOAD, STATS = 2; 27 | 28 | -- 29 | RESTORE DATABASE [WideWorldImporters] 30 | FROM DISK = N'/var/opt/mssql/backup/WideWorldImporters-Full.bak' WITH 31 | FILE = 1, MOVE N'WWI_Primary' TO N'/var/opt/mssql/data/WideWorldImporters.mdf', 32 | MOVE N'WWI_UserData' TO N'/var/opt/mssql/data/WideWorldImporters_UserData.ndf', 33 | MOVE N'WWI_Log' TO N'/var/opt/mssql/data/WideWorldImporters.ldf', 34 | MOVE N'WWI_InMemory_Data_1' TO N'/var/opt/mssql/data/WideWorldImporters_InMemory_Data_1', 35 | REPLACE, NOUNLOAD, STATS = 2; 36 | 37 | -- 38 | RESTORE DATABASE [WideWorldImportersDW] 39 | FROM DISK = N'/var/opt/mssql/backup/WideWorldImportersDW-Full.bak' WITH 40 | FILE = 1, MOVE N'WWI_Primary' TO N'/var/opt/mssql/data/WideWorldImportersDW.mdf', 41 | MOVE N'WWI_UserData' TO N'/var/opt/mssql/data/WideWorldImportersDW_UserData.ndf', 42 | MOVE N'WWI_Log' TO N'/var/opt/mssql/data/WideWorldImportersDW.ldf', 43 | MOVE N'WWIDW_InMemory_Data_1' TO N'/var/opt/mssql/data/WideWorldImportersDW_InMemory_Data_1', 44 | REPLACE, NOUNLOAD, STATS = 2; 45 | -------------------------------------------------------------------------------- /Demo3-PublishImageToDocker.md: -------------------------------------------------------------------------------- 1 |
2 | GitHub Sponsors 3 | Data Engineering with Enrique Catalá 4 | Data Engineering with Enrique Catalá 5 | LinkedIn Enrique Catalá Bañuls 6 | Twitter @enriquecatala 7 | Data Engineering: Canal youtube de Enrique Catalá 8 |
9 | 10 | # How to publish an image to docker 11 | 12 | To manually publish your image go docker, you must follow this: 13 | 14 | ## Get the IMAGE_ID of your image 15 | 16 | docker image list will show all the images you have, so check all the images and search for the one you just created 17 | 18 | ```powershell 19 | PS D:\git\mssql-samples-db> docker image list 20 | REPOSITORY TAG IMAGE ID CREATED SIZE 21 | mssql-server-samplesdb_db1 latest __IMAGE_ID_VALUE__ About a minute ago 2.06GB 22 | ``` 23 | 24 | ## Push the image 25 | 26 | Now that you have the IMAGE_ID you want to push to your docker image registry, 27 | 28 | And now you can instantiate a container from the image: 29 | 30 | ```powershell 31 | docker tag 9e4b368a45e8 enriquecatala/mssql-server-samplesdb:2019-CU4-ubuntu-16.04 32 | docker login 33 | docker push enriquecatala/mssql-server-samplesdb 34 | ``` 35 | 36 | -------------------------------------------------------------------------------- /Dockerfile-prepared-for-registry: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/mssql/server:2017-CU20-ubuntu-16.04 2 | EXPOSE 1433 3 | 4 | LABEL "MAINTAINER" "Enrique Catalá Bañuls " 5 | LABEL "Project" "Microsoft SQL Server container with sample databases" 6 | 7 | # Since SQL Server 2019 is non-root container, we need to force this to install packages 8 | USER root 9 | RUN apt-get update && apt-get install -y \ 10 | curl \ 11 | apt-transport-https 12 | 13 | # Create the local_mountpoint folder where the restores will be happening 14 | RUN mkdir -p /var/opt/mssql/data 15 | RUN chown 10001:0 /var/opt/mssql/data 16 | RUN chmod +rwx /var/opt/mssql/data 17 | 18 | # Get to the default user 19 | USER 10001 20 | 21 | RUN mkdir -p /var/opt/mssql/backup 22 | 23 | 24 | WORKDIR /var/opt/mssql/backup 25 | 26 | ############################################################## 27 | # DATABASES SECTION 28 | # 1) Add here the databases you want to have in your image 29 | # 2) Edit setup.sql and include the RESTORE commands 30 | # 31 | 32 | # Adventureworks databases 33 | # 34 | RUN curl -k -L -o AdventureWorks2017.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2017.bak 35 | RUN curl -k -L -o AdventureWorks2016.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2016.bak 36 | RUN curl -k -L -o AdventureWorks2014.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2014.bak 37 | RUN curl -k -L -o AdventureWorks2012.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2012.bak 38 | 39 | 40 | # WideWorldImporters databases 41 | # 42 | RUN curl -k -L -o WideWorldImporters-Full.bak https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak 43 | 44 | # Tpcc, Pubs and Northwind 45 | # 46 | COPY ./Backups/Pubs.bak ./ 47 | COPY ./Backups/Northwind.bak ./ 48 | 49 | ############################################################## 50 | 51 | RUN mkdir -p /usr/config 52 | WORKDIR /var/opt/mssql/setup/ 53 | 54 | COPY setup.* ./ 55 | COPY entrypoint.sh ./ 56 | 57 | # Since SQL Server 2019 is non-root container, we need to force this to install packages 58 | USER root 59 | RUN chown -R 10001:0 setup.sh 60 | RUN chown -R 10001:0 entrypoint.sh 61 | # Get to the default user 62 | USER 10001 63 | 64 | RUN chmod +x setup.sh 65 | RUN chmod +x entrypoint.sh 66 | 67 | # This entrypoint start sql server, restores data and waits infinitely 68 | ENTRYPOINT ["./entrypoint.sh"] 69 | 70 | CMD ["sleep infinity"] 71 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Enrique Catalá: 4 | # Web: https://www.clouddataninjas.com 5 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 6 | # Support: https://github.com/sponsors/enriquecatala 7 | 8 | 9 | # wait for MSSQL server to start 10 | export STATUS=1 11 | i=0 12 | 13 | while [[ $STATUS -ne 0 ]] && [[ $i -lt 60 ]]; do 14 | i=$i+1 15 | echo "*************************************************************************" 16 | echo "Waiting for SQL Server to start (it will fail until port is opened)..." 17 | /opt/mssql-tools/bin/sqlcmd -t 1 -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -Q "select 1" >> /dev/null 18 | STATUS=$? 19 | sleep 1 20 | done 21 | 22 | if [ $STATUS -ne 0 ]; then 23 | echo "Error: MSSQL SERVER took more than 60 seconds to start up." 24 | echo "CHECK PERMISSIONS for './local_mountpoint' in the ''How to run the image section of the readme''" 25 | exit 1 26 | fi 27 | 28 | echo "======= MSSQL SERVER STARTED ========" | tee -a ./config.log 29 | 30 | echo "*********** Preparing SQL Server instance features: Contained databases " | tee -a ./config.log 31 | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -d master -i /var/opt/mssql/setup/setup.instance.sql 32 | 33 | # If the wideworldimportersdw is restored, we don´t need to restore it again 34 | # 35 | file="/var/opt/mssql/data/Pubs.mdf" 36 | 37 | echo "INCLUDE_ALL_DATABASES: $INCLUDE_ALL_DATABASES" | tee -a ./config.log 38 | echo "FORCE_ATTACH_IF_MDF_EXISTS: $FORCE_ATTACH_IF_MDF_EXISTS" | tee -a ./config.log 39 | 40 | if [ ! -f "$file" ] 41 | then 42 | echo "*********** Restoring databases: WideWorldImporters, Adventureworks, tpcc ..." | tee -a ./config.log 43 | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -d master -i /var/opt/mssql/setup/setup.restore.sql 44 | 45 | case $INCLUDE_ALL_DATABASES in 46 | 1) echo "*********** Restoring big databases: WideWorldImportersDW, AdventureworksDW, StackOverflow..." | tee -a ./config.log 47 | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -d master -i /var/opt/mssql/setup/setup.other_databases.restore.sql 48 | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -d master -i /var/opt/mssql/setup/setup.bigdatabases.restore.sql 49 | ;; 50 | *) echo "INCLUDE_ALL_DATABASES is not set; defaulting to not include all databases." | tee -a ./config.log 51 | ;; 52 | esac 53 | else 54 | case $FORCE_ATTACH_IF_MDF_EXISTS in 55 | 1) echo "*********** Attaching previously restored databases..." | tee -a ./config.log 56 | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -d master -i /var/opt/mssql/setup/setup.attach.sql 57 | 58 | case $INCLUDE_ALL_DATABASES in 59 | 1) echo "*********** Attaching previously restored big databases..." | tee -a ./config.log 60 | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -d master -i /var/opt/mssql/setup/setup.other_databases.attach.sql 61 | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P $MSSQL_SA_PASSWORD -d master -i /var/opt/mssql/setup/setup.bigdatabases.attach.sql 62 | ;; 63 | *) echo "INCLUDE_ALL_DATABASES is not set; defaulting to not include all databases." | tee -a ./config.log 64 | ;; 65 | esac 66 | ;; 67 | *) echo "FORCE_ATTACH_IF_MDF_EXISTS is not set; defaulting to not attach databases." | tee -a ./config.log 68 | ;; 69 | esac 70 | 71 | fi 72 | echo "======= MSSQL CONFIG COMPLETE =======" | tee -a ./config.log -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at enrique@enriquecatala.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /Dockerfile-2017: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/mssql/server:2017-latest 2 | EXPOSE 1433 3 | # You must set this variable with --build-arg INCLUDE_ALL_DATABASES=1 in case you want to restore all databases 4 | ARG INCLUDE_ALL_DATABASES=0 5 | # Depending on the value of the ARG, the bash script will try to restore/attach 6 | ENV INCLUDE_ALL_DATABASES $INCLUDE_ALL_DATABASES 7 | 8 | LABEL "MAINTAINER" "Enrique Catalá Bañuls " 9 | LABEL "Project" "Microsoft SQL Server image with sample databases" 10 | 11 | 12 | # Since SQL Server 2019 is non-root container, we need to force this to install packages 13 | #USER root 14 | 15 | RUN apt-get update && apt-get install -y \ 16 | curl \ 17 | apt-transport-https \ 18 | p7zip-full 19 | 20 | # Create the local_mountpoint folder where the restores will be happening 21 | # This is critical if you want to use this as a local mountpoint to enable stateful deployments 22 | RUN mkdir -p /var/opt/mssql/data 23 | RUN chown 10001:0 /var/opt/mssql/data 24 | RUN chmod +rwx /var/opt/mssql/data 25 | 26 | # Get to the default user (mssql = 10001) 27 | #USER 10001 28 | 29 | RUN mkdir -p /var/opt/mssql/shared_folder 30 | RUN mkdir -p /var/opt/mssql/backup 31 | WORKDIR /var/opt/mssql/backup 32 | 33 | ############################################################## 34 | # DATABASES SECTION 35 | # 1) Add here the databases you want to have in your image 36 | # 2) Edit setup.sql and include the RESTORE commands 37 | # 38 | 39 | # Local .bak files 40 | # 41 | COPY ./Backups/Pubs.bak ./ 42 | COPY ./Backups/Northwind.bak ./ 43 | 44 | RUN curl -k -L -o WideWorldImporters-Full.bak https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak 45 | RUN curl -k -L -o AdventureWorks2017.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2017.bak 46 | 47 | 48 | ## The rest of the databases can be added-dropped manually 49 | RUN if [ "$INCLUDE_ALL_DATABASES" = "1" ] ; then curl -k -L -o AdventureWorks2016.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2016.bak ; else echo 'AdventureWorks2016 skipped since INCLUDE_ALL_DATABASES=0'; fi 50 | RUN if [ "$INCLUDE_ALL_DATABASES" = "1" ] ; then curl -k -L -o AdventureWorks2014.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2014.bak ; else echo 'AdventureWorks2014 skipped since INCLUDE_ALL_DATABASES=0'; fi 51 | RUN if [ "$INCLUDE_ALL_DATABASES" = "1" ] ; then curl -k -L -o AdventureWorks2012.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2012.bak ; else echo 'AdventureWorks2012 skipped since INCLUDE_ALL_DATABASES=0'; fi 52 | 53 | ## BIG DATABASES 54 | # 55 | RUN if [ "$INCLUDE_ALL_DATABASES" = "1" ] ; then curl -k -L -o AdventureWorksDW2017.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorksDW2017.bak; else echo 'AdventureWorksDW2017 skipped since INCLUDE_ALL_DATABASES=0'; fi 56 | RUN if [ "$INCLUDE_ALL_DATABASES" = "1" ] ; then curl -k -L -o WideWorldImportersDW-Full.bak https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImportersDW-Full.bak; else echo 'WideWorldImportersDW-Full skipped since INCLUDE_ALL_DATABASES=0'; fi 57 | 58 | 59 | # StackOverflow2010 60 | # 61 | RUN if [ "$INCLUDE_ALL_DATABASES" = "1" ] ; then curl -k -L -o StackOverflow2010.7z http://downloads.brentozar.com.s3.amazonaws.com/StackOverflow2010.7z; else echo 'StackOverflow2010 skipped since INCLUDE_ALL_DATABASES=0'; fi 62 | # This is going to unzip the 10Gb StackOverflow sample database 63 | # 64 | RUN if [ "$INCLUDE_ALL_DATABASES" = "1" ] ; then 7za x StackOverflow2010.7z -o/var/opt/mssql/data/; fi 65 | 66 | 67 | ############################################################## 68 | 69 | RUN mkdir -p /usr/config 70 | WORKDIR /var/opt/mssql/setup/ 71 | 72 | COPY setup.* ./ 73 | COPY entrypoint.sh ./ 74 | 75 | # Since SQL Server 2019 is non-root container, we need to force this to install packages 76 | #USER root 77 | RUN chown -R 10001:0 setup.sh 78 | RUN chown -R 10001:0 entrypoint.sh 79 | # Get to the default user 80 | #USER 10001 81 | 82 | RUN chmod +x setup.sh 83 | RUN chmod +x entrypoint.sh 84 | 85 | # This entrypoint start sql server, restores data and waits infinitely 86 | ENTRYPOINT ["./entrypoint.sh"] 87 | 88 | CMD ["sleep infinity"] -------------------------------------------------------------------------------- /prerequisites.download_databases.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Enrique Catalá: 4 | # Web: https://www.clouddataninjas.com 5 | # Linkedin: https://www.linkedin.com/in/enriquecatala/ 6 | # Support: https://github.com/sponsors/enriquecatala 7 | 8 | 9 | # Define the backups directory 10 | BACKUPS_DIR="./Backups" 11 | 12 | # check if WideWorldImporters-Full.bak exists 13 | if [ ! -f "$BACKUPS_DIR/WideWorldImporters-Full.bak" ]; then 14 | echo "*********** Downloading WideWorldImporters-Full.bak..." | tee -a ./config.log 15 | curl -k -L -o $BACKUPS_DIR/WideWorldImporters-Full.bak https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak 16 | else 17 | echo "*********** WideWorldImporters-Full.bak already exists. Skipping download." | tee -a ./config.log 18 | fi 19 | 20 | # check if AdventureWorks2017.bak exists 21 | if [ ! -f "$BACKUPS_DIR/AdventureWorks2017.bak" ]; then 22 | echo "*********** Downloading AdventureWorks2017.bak..." | tee -a ./config.log 23 | curl -k -L -o $BACKUPS_DIR/AdventureWorks2017.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2017.bak 24 | else 25 | echo "*********** AdventureWorks2017.bak already exists. Skipping download." | tee -a ./config.log 26 | fi 27 | 28 | # Conditional downloads based on INCLUDE_ALL_DATABASES environment variable 29 | # If INCLUDE_ALL_DATABASES is set to 1, download all databases 30 | # INCLUDE_ALL_DATABASES=1 ./prerequisites.download_databases.sh 31 | if [ "${INCLUDE_ALL_DATABASES}" = "1" ]; then 32 | #check if AdventureWorks2016.bak exists 33 | if [ ! -f "$BACKUPS_DIR/AdventureWorks2016.bak" ]; then 34 | echo "*********** Downloading AdventureWorks2016.bak..." | tee -a ./config.log 35 | curl -k -L -o $BACKUPS_DIR/AdventureWorks2016.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2016.bak 36 | else 37 | echo "*********** AdventureWorks2016.bak already exists. Skipping download." | tee -a ./config.log 38 | fi 39 | 40 | #check if AdventureWorks2014.bak exists 41 | if [ ! -f "$BACKUPS_DIR/AdventureWorks2014.bak" ]; then 42 | echo "*********** Downloading AdventureWorks2014.bak..." | tee -a ./config.log 43 | curl -k -L -o $BACKUPS_DIR/AdventureWorks2014.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2014.bak 44 | else 45 | echo "*********** AdventureWorks2014.bak already exists. Skipping download." | tee -a ./config.log 46 | fi 47 | 48 | #check if AdventureWorks2012.bak exists 49 | if [ ! -f "$BACKUPS_DIR/AdventureWorks2012.bak" ]; then 50 | echo "*********** Downloading AdventureWorks2012.bak..." | tee -a ./config.log 51 | curl -k -L -o $BACKUPS_DIR/AdventureWorks2012.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2012.bak 52 | else 53 | echo "*********** AdventureWorks2012.bak already exists. Skipping download." | tee -a ./config.log 54 | fi 55 | 56 | #check if AdventureWorksDW2017.bak exists 57 | if [ ! -f "$BACKUPS_DIR/AdventureWorksDW2017.bak" ]; then 58 | echo "*********** Downloading AdventureWorksDW2017.bak..." | tee -a ./config.log 59 | curl -L -o $BACKUPS_DIR/AdventureWorksDW2017.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorksDW2017.bak 60 | else 61 | echo "*********** AdventureWorksDW2017.bak already exists. Skipping download." | tee -a ./config.log 62 | fi 63 | #check if WideWorldImportersDW-Full exists 64 | if [ ! -f "$BACKUPS_DIR/WideWorldImportersDW-Full.bak" ]; then 65 | echo "*********** Downloading WideWorldImportersDW-Full.bak..." | tee -a ./config.log 66 | curl -L -o $BACKUPS_DIR/WideWorldImportersDW-Full.bak https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImportersDW-Full.bak 67 | else 68 | echo "*********** WideWorldImportersDW-Full.bak already exists. Skipping download." | tee -a ./config.log 69 | fi 70 | 71 | # # check if StackOverflow2010.7z exists 72 | # if [ ! -f "$BACKUPS_DIR/StackOverflow2010.7z" ]; then 73 | # echo "*********** Downloading StackOverflow2010.7z..." | tee -a ./config.log 74 | # curl -k -L -o $BACKUPS_DIR/StackOverflow2010.7z http://downloads.brentozar.com.s3.amazonaws.com/StackOverflow2010.7z 75 | # # Unzip StackOverflow2010 76 | # 7za x $BACKUPS_DIR/StackOverflow2010.7z -o$BASE_DIR/data/ 77 | # else 78 | # echo "*********** StackOverflow2010.7z already exists. Skipping download." | tee -a ./config.log 79 | # fi 80 | 81 | else 82 | echo 'Only selected databases are downloaded as INCLUDE_ALL_DATABASES is not set to 1.' 83 | echo 'To download all databases: INCLUDE_ALL_DATABASES=1 ./prerequisites.download_databases.sh' 84 | fi 85 | -------------------------------------------------------------------------------- /Demo4-running in ACI.md: -------------------------------------------------------------------------------- 1 |
2 | GitHub Sponsors 3 | Data Engineering with Enrique Catalá 4 | Data Engineering with Enrique Catalá 5 | LinkedIn Enrique Catalá Bañuls 6 | Twitter @enriquecatala 7 | Data Engineering: Canal youtube de Enrique Catalá 8 |
9 | 10 | # Runing image in Azure Container Instance 11 | 12 | The docker [version >2.3.2](https://docs.docker.com/docker-for-windows/edge-release-notes/) lets you run your docker images on Azure Container Instances. 13 | 14 | - [Runing image in Azure Container Instance](#runing-image-in-azure-container-instance) 15 | - [1) Publish your image to docker hub](#1-publish-your-image-to-docker-hub) 16 | - [2) Create an ACI context](#2-create-an-aci-context) 17 | - [3) Switch to the new ACI context](#3-switch-to-the-new-aci-context) 18 | - [4) Run the container](#4-run-the-container) 19 | - [5) Check the status of the container](#5-check-the-status-of-the-container) 20 | - [Check the logs](#check-the-logs) 21 | - [Apendix](#apendix) 22 | - [Create new context](#create-new-context) 23 | - [List context](#list-context) 24 | - [Stop the app](#stop-the-app) 25 | - [Delete old contexts](#delete-old-contexts) 26 | 27 | # 1) Publish your image to docker hub 28 | 29 | Please follow the [Demo3](Demo3-PublishImageToDocker.md) 30 | 31 | # 2) Create an ACI context 32 | 33 | Once you have the docker [version >2.3.2](https://docs.docker.com/docker-for-windows/edge-release-notes/), you will need to get started by logging into an Azure account using the Docker CLI: 34 | 35 | ```powershell 36 | # login to azure 37 | docker login azure 38 | # create the context 39 | docker context create aci myaci 40 | # List the new context 41 | docker context list 42 | ``` 43 | 44 | # 3) Switch to the new ACI context 45 | 46 | ```powershell 47 | docker context use myaci 48 | ``` 49 | 50 | # 4) Run the container 51 | 52 | To run container, you simply use the new sintax "_docker compose_" 53 | >NOTE: We are not using '-', the command is **_docker compose_** with a space in the midle 54 | 55 | ```powershell 56 | ❯ docker compose -f .\docker-compose-demo4.yml up 57 | [+] Running 2/2 58 | - Group mssqlserversamplesdb Created 5.3s 59 | - db1 Done 92.5s 60 | ``` 61 | 62 | >NOTE: To check the status while deploying __docker ps -a__ 63 | 64 | ```powershell 65 | ❯ docker ps -a 66 | CONTAINER ID IMAGE COMMAND STATUS PORTS 67 | mssqlserversamplesdb_db1 enriquecatala/mssql-server-samplesdb:2019-latest Waiting 52.155.222.157:1433->1433/tcp 68 | ``` 69 | 70 | # 5) Check the status of the container 71 | 72 | ```powershell 73 | ❯ docker ps 74 | CONTAINER ID IMAGE STATUS PORTS 75 | mssqlserversamplesdb_db1 enriquecatala/mssql-server-samplesdb:2019-latest Running 52.155.222.157:1433->1433/tcp 76 | ``` 77 | 78 | ## Check the logs 79 | 80 | ```powershell 81 | docker logs mssqlserversamplesdb_db1 82 | 83 | ❯ docker logs mssqlserversamplesdb_db1 84 | ************************************************************************* 85 | Waiting for SQL Server to start (it will fail until port is opened)... 86 | 2020-09-28 22:00:55.24 Server Microsoft SQL Server 2019 (RTM-CU4) (KB4548597) - 15.0.4033.1 (X64) 87 | Mar 14 2020 16:10:35 88 | Copyright (C) 2019 Microsoft Corporation 89 | Developer Edition (64-bit) on Linux (Ubuntu 18.04.4 LTS) 90 | 2020-09-28 22:00:55.24 Server UTC adjustment: 0:00 91 | 2020-09-28 22:00:55.24 Server (c) Microsoft Corporation. 92 | 2020-09-28 22:00:55.25 Server All rights reserved. 93 | 2020-09-28 22:00:55.25 Server Server process ID is 40. 94 | 2020-09-28 22:00:55.25 Server Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'. 95 | 2020-09-28 22:00:55.25 Server Registry startup parameters: 96 | -d /var/opt/mssql/data/master.mdf 97 | -l /var/opt/mssql/data/mastlog.ldf 98 | ... 99 | ``` 100 | 101 | # Apendix 102 | 103 | ## Create new context 104 | 105 | ```bash 106 | docker context create aci --help 107 | 108 | ``` 109 | ## List context 110 | 111 | ```bash 112 | > docker context --help 113 | ❯ docker context list 114 | NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR 115 | aci-context aci mycontainerinstances@northeurope 116 | default * moby Current DOCKER_HOST based configuration npipe:////./pipe/docker_engine swarm 117 | ``` 118 | 119 | ## Stop the app 120 | 121 | ```powershell 122 | docker compose down 123 | ``` 124 | 125 | ## Delete old contexts 126 | 127 | ```bash 128 | docker context rm aci-context 129 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /Demo1-ManuallyRunContainer.md: -------------------------------------------------------------------------------- 1 |
2 | GitHub Sponsors 3 | Data Engineering with Enrique Catalá 4 | Data Engineering with Enrique Catalá 5 | LinkedIn Enrique Catalá Bañuls 6 | Twitter @enriquecatala 7 | Data Engineering: Canal youtube de Enrique Catalá 8 |
9 | 10 | # How to manually run the container without docker-compose 11 | 12 | In this demo we will instantiate a docker image with the latest SQL Server 2017 13 | 14 | ## Pull the image from repository 15 | 16 | ```powershell 17 | docker pull mcr.microsoft.com/mssql/server:2017-latest 18 | ``` 19 | 20 | ## Run the container 21 | 22 | Execute the container exposing port 14333 and connecting the local volue d:/ inside the container. This is very interesting when you want to get data from your local storage outside the container 23 | 24 | ```powershell 25 | docker run -p 14333:1433 -it -v d:/:/data -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=PaSSw0rd' --name my-container-sql2017 mcr.microsoft.com/mssql/server:2017-latest 26 | ``` 27 | 28 | _-d parameter will open the container and return the execution to the bash runtime_ 29 | 30 | ## Connect to the container 31 | 32 | ```powershell 33 | sqlcmd -S laptop,14333 -U sa -P 'PaSSw0rd' -Q "select @@version" 34 | ``` 35 | 36 | Try to restore a database from your local path: 37 | 38 | ```powershell 39 | sqlcmd -S laptop,14333 -U sa -P 'PaSSw0rd' -Q " USE [master]; RESTORE DATABASE [pubs] FROM DISK = N'/data/Git_ecb/mssql-server-samplesdb/Backups/Pubs.bak' WITH FILE = 1, MOVE N'pubs' TO N'/var/opt/mssql/data/pubs.mdf', MOVE N'pubs_log' TO N'/var/opt/mssql/data/pubs_log.ldf', NOUNLOAD, STATS = 5" 40 | ``` 41 | 42 | _or try to do the same and use SQL Server Management studio_ 43 | 44 | ## Stop the container 45 | 46 | By pressyng ctrl+z 47 | 48 | ## Try to start again the container 49 | 50 | ```powershell 51 | docker run -p 14333:1433 -it -v d:/:/data -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=PaSSw0rd' --name my-container-sql2017 mcr.microsoft.com/mssql/server:2017-latest 52 | ``` 53 | 54 | This time it will throw you an error: 55 | # How to manually run a container 56 | 57 | In this demo we will instantiate a docker image with the latest SQL Server 2017 58 | 59 | ## Pull the image from repository 60 | 61 | ```powershell 62 | docker pull mcr.microsoft.com/mssql/server:2017-latest 63 | ``` 64 | >NOTE: valid tags: https://hub.docker.com/_/microsoft-mssql-server?tab=description 65 | 66 | ## Run the container 67 | 68 | Execute the container as SQL Server **Express**, exposing **port 14333** and **4Gb of RAM**. 69 | 70 | ```powershell 71 | docker run --memory=4g -p 14333:1433 -it -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=PaSSw0rd' -e 'MSSQL_PID=Express' --name my-container-sql2017 mcr.microsoft.com/mssql/server:2017-CU20-ubuntu-16.04 72 | ``` 73 | >NOTE: Resource tags https://docs.docker.com/config/containers/resource_constraints/ 74 | 75 | ## See all the containers running(or not) 76 | 77 | ```powershell 78 | docker container list -a 79 | ``` 80 | 81 | ## Connect to the container 82 | 83 | ```powershell 84 | sqlcmd -S localhost,14333 -U sa -P 'PaSSw0rd' -Q "select @@version" 85 | ``` 86 | 87 | ## Create a database with some data 88 | 89 | ```sql 90 | USE [master] 91 | go 92 | create database test 93 | go 94 | use test 95 | go 96 | create table mytable(a int, b varchar(100)) 97 | go 98 | insert into mytable(a,b) values(1,'hola'),(2,'mundo') 99 | go 100 | select * from mytable 101 | go 102 | ``` 103 | 104 | ## Stop the container 105 | 106 | By pressyng ctrl+c 107 | 108 | ## Try to start again the container 109 | 110 | ```powershell 111 | docker run --memory=4g -p 14333:1433 -it -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=PaSSw0rd' -e 'MSSQL_PID=Express' --name my-container-sql2017 mcr.microsoft.com/mssql/server:2017-CU20-ubuntu-16.04 112 | ``` 113 | 114 | This time it will throw you an error: 115 | 116 | _C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: Conflict. The container name "/my-container-sql2017" is already in use by container "70de3443a42ad37f55de9e8db4177a7a846b7067c39faf16db3410ad330dc50a". You have to remove (or rename) that container to be able to reuse that name. 117 | See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'._ 118 | 119 | So list the containers with 120 | 121 | ```powershell 122 | docker container list -a 123 | ``` 124 | 125 | 126 | | CONTAINER ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES | 127 | |--------------|--------------------------------------------|------------------------|---------------|-------------------------------|----------------------|-------| 128 | | 70de3443a42a | mcr.microsoft.com/mssql/server:2017-CU20-ubuntu-16.04 | "/opt/mssql/bin/sqls…" | 9 minutes ago | Exited (0) About a minute ago | | my-container-sql2017 | 129 | | | | | | | | | 130 | 131 | and execute the container with the name you gave it: 132 | 133 | ```powershell 134 | docker start -i my-container-sql2017 135 | ``` 136 | 137 | >NOTE: The data still exists within the container...until you delete it 138 | 139 | ## Clean up container 140 | 141 | With the following execution, you will delete all exited containers 142 | 143 | ```powershell 144 | docker rm my-container-sql2017 145 | ``` 146 | 147 | 148 | _C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: Conflict. The container name "/my-container-sql2017" is already in use by container "70de3443a42ad37f55de9e8db4177a7a846b7067c39faf16db3410ad330dc50a". You have to remove (or rename) that container to be able to reuse that name. 149 | See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'._ 150 | 151 | So list the containers with 152 | 153 | ```powershell 154 | docker container list -a 155 | ``` 156 | 157 | 158 | | CONTAINER ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES | 159 | |--------------|--------------------------------------------|------------------------|---------------|-------------------------------|----------------------|-------| 160 | | 70de3443a42a | mcr.microsoft.com/mssql/server:2017-latest | "/opt/mssql/bin/sqls…" | 9 minutes ago | Exited (0) About a minute ago | | my-container-sql2017 | 161 | | | | | | | | | 162 | 163 | and execute the container with the name you gave it: 164 | 165 | ```powershell 166 | docker start -i my-container-sql2017 167 | ``` 168 | 169 | ## Clean up container 170 | 171 | With the following execution, you will delete all exited containers 172 | 173 | ```powershell 174 | docker rm $(docker ps -q -f status=exited) 175 | ``` 176 | 177 | -------------------------------------------------------------------------------- /Demo2-CreateImageWithData.md: -------------------------------------------------------------------------------- 1 |
2 | GitHub Sponsors 3 | Data Engineering with Enrique Catalá 4 | Data Engineering with Enrique Catalá 5 | LinkedIn Enrique Catalá Bañuls 6 | Twitter @enriquecatala 7 | Data Engineering: Canal youtube de Enrique Catalá 8 |
9 | 10 | # How to create an image with data 11 | 12 | To manually run the container without using the docker-compose, you must follow this: 13 | 14 | ## Create the image 15 | 16 | With this command we are going to create our own image 17 | 18 | ```powershell 19 | docker-compose -f docker-compose-docker-registry.yml build 20 | ``` 21 | 22 | And [this is the expected output](##Output-of-docker-build) 23 | 24 | 25 | ## Check that your image has been created 26 | 27 | docker image list will show all the images you have, so check all the images and search for the one you just created 28 | 29 | ```powershell 30 | PS D:\git\mssql-samples-db> docker image list 31 | REPOSITORY TAG IMAGE ID CREATED SIZE 32 | mssql-server-samplesdb_db1 latest 1fd0d8711d7d About a minute ago 2.06GB 33 | ``` 34 | 35 | ## Run the container (optional) 36 | 37 | You can check if your container has all the databases and configuration you scripted 38 | 39 | ```powershell 40 | docker-compose -f docker-compose-docker-registry.yml up 41 | ``` 42 | >NOTE: You don´t need to start your image to upload to the docker´s registry 43 | 44 | ### Connect to the container 45 | 46 | ```powershell 47 | sqlcmd -S laptop,14333 -U sa -P 'PaSSw0rd' -Q "select @@version" 48 | ``` 49 | 50 | Validate that this image contains databases restored in it: 51 | 52 | 53 | ## Output of docker build 54 | 55 | This is the expected output of the docker build 56 | 57 | ```powershell 58 | Sending build context to Docker daemon 13.14MB 59 | Step 1/24 : FROM mcr.microsoft.com/mssql/server:2019-CTP2.5-ubuntu 60 | 2019-CTP2.5-ubuntu: Pulling from mssql/server 61 | 59ab41dd721a: Already exists 62 | 57da90bec92c: Already exists 63 | 06fe57530625: Already exists 64 | 5a6315cba1ff: Already exists 65 | 739f58768b3f: Already exists 66 | 0b751601bca3: Already exists 67 | bcf04a22644a: Already exists 68 | 6efede4b0bec: Pull complete 69 | e9b26e17c29a: Pull complete 70 | Digest: sha256:74adb0d809b4012f5b06e28a5e19e0ef20434db4aa99b92b37ae67f516305980 71 | Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2019-CTP2.5-ubuntu 72 | ---> 5494536a73c1 73 | Step 2/24 : EXPOSE 1433 74 | ---> Running in 487b0351e022 75 | Removing intermediate container 487b0351e022 76 | ---> 793eff29d144 77 | Step 3/24 : LABEL "MAINTAINER" "Enrique Catalá Bañuls " 78 | ---> Running in 276c5abc1bed 79 | Removing intermediate container 276c5abc1bed 80 | ---> a2aeb9f02a51 81 | Step 4/24 : LABEL "Project" "Microsoft SQL Server container with sample databases" 82 | ---> Running in ce15a60f4ae8 83 | Removing intermediate container ce15a60f4ae8 84 | ---> 71f2552c0f41 85 | Step 5/24 : RUN apt-get update && apt-get install -y curl apt-transport-https 86 | ---> Running in a37c7df4aff1 87 | Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB] 88 | Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB] 89 | Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [129 kB] 90 | Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB] 91 | Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB] 92 | Get:6 https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease [3226 B] 93 | Get:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [827 kB] 94 | Get:8 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB] 95 | Get:9 https://packages.microsoft.com/ubuntu/16.04/prod xenial/main amd64 Packages [92.1 kB] 96 | Get:10 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB] 97 | Get:11 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [553 kB] 98 | Get:12 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6113 B] 99 | Get:13 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB] 100 | Get:14 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB] 101 | Get:15 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB] 102 | Get:16 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB] 103 | Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [320 kB] 104 | Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1237 kB] 105 | Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB] 106 | Get:20 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [965 kB] 107 | Get:21 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [19.1 kB] 108 | Get:22 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7942 B] 109 | Get:23 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8532 B] 110 | Fetched 26.1 MB in 17s (1491 kB/s) 111 | Reading package lists... 112 | Reading package lists... 113 | Building dependency tree... 114 | Reading state information... 115 | apt-transport-https is already the newest version (1.2.31). 116 | The following NEW packages will be installed: 117 | curl 118 | 0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded. 119 | Need to get 139 kB of archives. 120 | After this operation, 339 kB of additional disk space will be used. 121 | Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 curl amd64 7.47.0-1ubuntu2.12 [139 kB] 122 | debconf: delaying package configuration, since apt-utils is not installed 123 | Fetched 139 kB in 0s (520 kB/s) 124 | Selecting previously unselected package curl. 125 | (Reading database ... 10796 files and directories currently installed.) 126 | Preparing to unpack .../curl_7.47.0-1ubuntu2.12_amd64.deb ... 127 | Unpacking curl (7.47.0-1ubuntu2.12) ... 128 | Setting up curl (7.47.0-1ubuntu2.12) ... 129 | Removing intermediate container a37c7df4aff1 130 | ---> a7628e367445 131 | Step 6/24 : RUN mkdir -p /var/opt/mssql/backup 132 | ---> Running in 811d7e31b109 133 | Removing intermediate container 811d7e31b109 134 | ---> 0a07f188b519 135 | Step 7/24 : WORKDIR /var/opt/mssql/backup 136 | ---> Running in 662bd37132e5 137 | Removing intermediate container 662bd37132e5 138 | ---> 87a8ad9730e2 139 | Step 8/24 : RUN curl -L -o AdventureWorks2017.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2017.bak 140 | ---> Running in 1fcf83be649c 141 | % Total % Received % Xferd Average Speed Time Time Time Current 142 | Dload Upload Total Spent Left Speed 143 | 100 612 0 612 0 0 1312 0 --:--:-- --:--:-- --:--:-- 1310 144 | 100 47.9M 100 47.9M 0 0 2774k 0 0:00:17 0:00:17 --:--:-- 7794k 145 | Removing intermediate container 1fcf83be649c 146 | ---> 16756f6851e2 147 | Step 9/24 : RUN curl -L -o AdventureWorks2016.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2016.bak 148 | ---> Running in ecbeb05bc492 149 | % Total % Received % Xferd Average Speed Time Time Time Current 150 | Dload Upload Total Spent Left Speed 151 | 100 612 0 612 0 0 1409 0 --:--:-- --:--:-- --:--:-- 1410 152 | 100 46.4M 100 46.4M 0 0 11.3M 0 0:00:04 0:00:04 --:--:-- 16.5M 153 | Removing intermediate container ecbeb05bc492 154 | ---> 75b275955bc1 155 | Step 10/24 : RUN curl -L -o AdventureWorks2014.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2014.bak 156 | ---> Running in 964971530fa2 157 | % Total % Received % Xferd Average Speed Time Time Time Current 158 | Dload Upload Total Spent Left Speed 159 | 100 612 0 612 0 0 1206 0 --:--:-- --:--:-- --:--:-- 1204 160 | 100 44.5M 100 44.5M 0 0 6226k 0 0:00:07 0:00:07 --:--:-- 10.3M 161 | Removing intermediate container 964971530fa2 162 | ---> 9a73fb6db22b 163 | Step 11/24 : RUN curl -L -o AdventureWorks2012.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2012.bak 164 | ---> Running in 687a2a1c63ba 165 | % Total % Received % Xferd Average Speed Time Time Time Current 166 | Dload Upload Total Spent Left Speed 167 | 100 612 0 612 0 0 1368 0 --:--:-- --:--:-- --:--:-- 1372 168 | 100 44.8M 100 44.8M 0 0 2559k 0 0:00:17 0:00:17 --:--:-- 7164k 169 | Removing intermediate container 687a2a1c63ba 170 | ---> 34487e76cf94 171 | Step 12/24 : RUN curl -L -o AdventureWorksDW2017.bak https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorksDW2017.bak 172 | ---> Running in 56e6fdfc9989 173 | % Total % Received % Xferd Average Speed Time Time Time Current 174 | Dload Upload Total Spent Left Speed 175 | 100 614 0 614 0 0 1363 0 --:--:-- --:--:-- --:--:-- 1364 176 | 100 22.3M 100 22.3M 0 0 5783k 0 0:00:03 0:00:03 --:--:-- 7159k 177 | Removing intermediate container 56e6fdfc9989 178 | ---> 692a78b418cd 179 | Step 13/24 : RUN curl -L -o WideWorldImportersDW-Full.bak https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImportersDW-Full.bak 180 | ---> Running in 6751e2d6ac75 181 | % Total % Received % Xferd Average Speed Time Time Time Current 182 | Dload Upload Total Spent Left Speed 183 | 100 619 0 619 0 0 1406 0 --:--:-- --:--:-- --:--:-- 1410 184 | 100 47.7M 100 47.7M 0 0 2671k 0 0:00:18 0:00:18 --:--:-- 7066k 185 | Removing intermediate container 6751e2d6ac75 186 | ---> eb1fcf1e2b64 187 | Step 14/24 : RUN curl -L -o WideWorldImporters-Full.bak https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak 188 | ---> Running in 253d2ad7b1d1 189 | % Total % Received % Xferd Average Speed Time Time Time Current 190 | Dload Upload Total Spent Left Speed 191 | 100 617 0 617 0 0 1333 0 --:--:-- --:--:-- --:--:-- 1332 192 | 100 121M 100 121M 0 0 11.4M 0 0:00:10 0:00:10 --:--:-- 13.7M 193 | Removing intermediate container 253d2ad7b1d1 194 | ---> f405600809f1 195 | Step 15/24 : COPY ./Backups/Pubs.bak ./ 196 | ---> 07671e037bd1 197 | Step 16/24 : COPY ./Backups/Northwind.bak ./ 198 | ---> 8e65549e3954 199 | Step 17/24 : RUN mkdir -p /usr/config 200 | ---> Running in b4935a036c15 201 | Removing intermediate container b4935a036c15 202 | ---> 313bc14d74dd 203 | Step 18/24 : WORKDIR /var/opt/mssql/setup/ 204 | ---> Running in 113baa1f44ff 205 | Removing intermediate container 113baa1f44ff 206 | ---> 71e13a85c09c 207 | Step 19/24 : COPY setup.* ./ 208 | ---> ac5b2ad0de18 209 | Step 20/24 : COPY entrypoint.sh ./ 210 | ---> b6deb416ee0d 211 | Step 21/24 : RUN chmod +x setup.sh 212 | ---> Running in 5470f49df807 213 | Removing intermediate container 5470f49df807 214 | ---> efcf2c674d02 215 | Step 22/24 : RUN chmod +x entrypoint.sh 216 | ---> Running in cc903a643a0c 217 | Removing intermediate container cc903a643a0c 218 | ---> 43b3c4824c7c 219 | Step 23/24 : ENTRYPOINT ["./entrypoint.sh"] 220 | ---> Running in d68fd492abc5 221 | Removing intermediate container d68fd492abc5 222 | ---> b4bf68c3bb46 223 | Step 24/24 : CMD ["sleep infinity"] 224 | ---> Running in 00f3a7cb72c5 225 | Removing intermediate container 00f3a7cb72c5 226 | ---> 209405f1d529 227 | Successfully built 209405f1d529 228 | Successfully tagged my-image:latest 229 | SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories. 230 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | 23 | 24 | # mssql-server-samplesdb 25 | 26 | Easily deploy a Docker instance with SQL Server and all Microsoft Sample databases. Choose between stateless or stateful deployment for your SQL Server needs. Perfect for developers and DBAs looking for a quick and reliable database setup. 27 | 28 | 29 | ## Quick Start 30 | 31 | Run the image instantly with `make all`. For more control use the following commands: 32 | 33 | ```bash 34 | make prerequisites # setup 35 | make build # build the image 36 | docker compose up # run the image 37 | ``` 38 | 39 | Connect to your SQL Server instance at `localhost,14330` using `sa` and `PaSSw0rd` (configurable in `docker-compose.yml`). 40 | 41 | **Table of Contents:** 42 | - [mssql-server-samplesdb](#mssql-server-samplesdb) 43 | - [Quick Start](#quick-start) 44 | - [Features](#features) 45 | - [Installation](#installation) 46 | - [Prerequisites](#prerequisites) 47 | - [Steps](#steps) 48 | - [How to run the image](#how-to-run-the-image) 49 | - [Databases included](#databases-included) 50 | - [Enable all databases](#enable-all-databases) 51 | - [Stateless deployment](#stateless-deployment) 52 | - [Stateful deployment](#stateful-deployment) 53 | - [Permissions](#permissions) 54 | - [Setting Up Local Directories for Container Mounts](#setting-up-local-directories-for-container-mounts) 55 | - [How to Use the Script](#how-to-use-the-script) 56 | - [Force Attach (optional)](#force-attach-optional) 57 | - [Customization](#customization) 58 | - [How to change the SQL Server base image](#how-to-change-the-sql-server-base-image) 59 | - [How to add new databases to the image](#how-to-add-new-databases-to-the-image) 60 | - [How to change the sa password](#how-to-change-the-sa-password) 61 | - [FAQ](#faq) 62 | - [How does it works?](#how-does-it-works) 63 | - [Restoring databases](#restoring-databases) 64 | - [Entrypoint](#entrypoint) 65 | - [Avoid container to stop after deploy](#avoid-container-to-stop-after-deploy) 66 | 67 | 68 | ## Features 69 | - **Easy Setup**: Deploy SQL Server in Docker with a simple command. 70 | - **Multiple Databases**: Includes popular databases like - Northwind, Pubs, and AdventureWorks. 71 | - **Customizable**: Options for stateless and stateful deployment. 72 | - **Community Driven**: Open for contributions and enhancements. 73 | 74 | ## Installation 75 | ### Prerequisites 76 | - Docker 77 | - Make (optional) 78 | 79 | ## Steps 80 | 1) Clone the repository: git clone https://github.com/enriquecatala/mssql-server-samplesdb. 81 | 2) Navigate to the directory and run make prerequisites. 82 | 3) Build the image: make build. 83 | 4) Start the container: docker compose up. 84 | 85 | 86 | ## How to run the image 87 | 88 | You can run the image with just executing **`make all`**, but if you want more control, you can execute the following commands: 89 | 90 | ```bash 91 | # Create the folder where the databases will be restored and download the databases 92 | # into ./Backups folder 93 | # 94 | make prerequisites 95 | 96 | # Build the image 97 | make build 98 | 99 | # Run the image 100 | docker compose up 101 | ``` 102 | 103 | 104 | Now you can open your favorite SQL Server client and connect to your local SQL Server instance. By default: 105 | - Server localhost,14330 106 | - user:sa 107 | - Password: PaSSw0rd 108 | 109 | >NOTE: You can find the credentials in the docker-compose.yml file 110 | 111 | ```yaml 112 | environment: 113 | MSSQL_SA_PASSWORD: "PaSSw0rd" 114 | ports: 115 | - "14330:1433" 116 | ``` 117 | 118 | ### Databases included 119 | 120 | Databases included: 121 | - Pubs 122 | - Northwind 123 | - WideWorldImporters 124 | - WideWorldImportersDW 125 | - AdventureWorks2017 126 | - _AdventureWorksDW2017*_ 127 | - _AdventureWorks2016*_ 128 | - _AdventureWorks2014*_ 129 | - _AdventureWorks2012*_ 130 | - _StackOverflow2010*_ 131 | 132 | 133 | > NOTE: Databases marked with * must be [switched on during build](#enable-all-databases) 134 | 135 | ## Enable all databases 136 | 137 | Only common databases are deployed by default. To deploy ALL databases in your container, please edit the **[.env](.env)** file and set the following variable to 1: 138 | 139 | ```bash 140 | INCLUDE_ALL_DATABASES=1 141 | ``` 142 | 143 | ```cmd 144 | # to make sure that all databases are deployed, you can execute 145 | make clean 146 | # to build the image and run it 147 | make all 148 | ``` 149 | 150 | **IMPORTANT:** StackOverflow2010 database is huge and it will require a couple of minutes to initialize. Please be patient. You can work and play within the other databases while the StackOverflow database is being prepared 151 | 152 | ## Stateless deployment 153 | 154 | Edit the [docker-compose.yml](./docker-compose.yml) file and comment the following lines: 155 | 156 | ```yml 157 | #volumes: 158 | # - ${LOCAL_MOUNTPOINT}:/var/opt/mssql/data 159 | ``` 160 | >NOTE: Doing that, will disable mounting the local folder specified in the **[.env](.env)** file 161 | 162 | Then, you can create and run the image with the following command: 163 | 164 | ```cmd 165 | docker compose up --build 166 | ``` 167 | 168 | 169 | **IMPORTANT:** StackOverflow2010 database is huge and it will require a couple of minutes to initialize. Please be patient. You can work and play within the other databases while the StackOverflow database is being prepared 170 | 171 | ## Stateful deployment 172 | 173 | With the [docker-compose.yml](./docker-compose.yml) file you will deploy all databases in a persistent folder in the host (remind to configure the [.env](/.env) file with a valid local folder): 174 | 175 | - LOCAL_MOUNTPOINT 176 | 177 | The folder must exist ( for example: /home/enrique/your/path/to/volume/) 178 | 179 | - SHARED_FOLDER 180 | 181 | The folder must exists. This shared folder can be used for example, to deploy backups or easily copy-paste between container and host 182 | 183 | > IMPORTANT: There is some kind of bug with WSL2 and if you want to use stateful deployment, you need to start your container inside the wsl2 image. You cant execute docker-compose up from windows 184 | 185 | ### Permissions 186 | 187 | When working with Docker containers that mount local volumes, managing file and directory permissions is crucial. These permissions ensure that the container has the appropriate access rights to the data stored on these volumes. To simplify this process, we have a script named [prerequisites.create_local_directories.sh](./prerequisites.create_local_directories.sh) that automatically sets up the necessary directories and permissions. 188 | 189 | >NOTE: This is automatically done when you execute **`make prerequisites`** 190 | 191 | #### Setting Up Local Directories for Container Mounts 192 | 193 | The [prerequisites.create_local_directories.sh](./prerequisites.create_local_directories.sh) script is designed to create local directories and configure their permissions to match the requirements of the Docker container. By running this script, you avoid the manual process of setting up these directories and permissions. 194 | 195 | To understand what the script does, here's an overview of the steps involved: 196 | 197 | 1. **Create Local Directories**: The script creates directories on your host system that will be mounted into the Docker container. This includes data and shared folders. 198 | 199 | ```bash 200 | mkdir -p ./local_mountpoint/data/ 201 | mkdir -p ./local_mountpoint/shared_folder/ 202 | ``` 203 | 204 | 2. **Set Ownership**: It changes the ownership of these directories to the user ID (`UID`) and group ID (`GID`) that the SQL Server in the Docker container runs as. This is typically `UID 10001` and `GID 0`. 205 | 206 | ```bash 207 | sudo chown 10001:0 ./local_mountpoint/data/ 208 | sudo chown 10001:0 ./local_mountpoint/shared_folder/ 209 | ``` 210 | 211 | 3. **Adjust Permissions**: The script sets the necessary read, write, and execute permissions on these directories to ensure that the container can access and modify the data as required. 212 | 213 | ```bash 214 | sudo chmod +rwx ./local_mountpoint/data/ 215 | sudo chmod +rwx ./local_mountpoint/shared_folder/ 216 | ``` 217 | 218 | #### How to Use the Script 219 | 220 | >NOTE: This is automatically done when you execute **`make prerequisites`** 221 | 222 | 223 | Simply run the `prerequisites.create_local_directories.sh` script to automatically set up the directories and permissions: 224 | 225 | ```bash 226 | ./prerequisites.create_local_directories.sh 227 | ``` 228 | 229 | This approach streamlines the setup process and ensures consistency in the permissions, allowing your Docker container to function correctly with the mounted volumes. 230 | 231 | And now, in the docker-compose.yml, you can reference that path, for example 232 | 233 | ```yaml 234 | volumes: 235 | - ${LOCAL_MOUNTPOINT}:/var/opt/mssql/data 236 | ``` 237 | 238 | Now, when you start the container, you will see how the files are deployed locally 239 | 240 | ```bash 241 | mssql-server-samplesdb | 2020-05-25 16:23:11.74 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'. 242 | 2020-05-25 16:23:12.05 Server Did not find an existing master data file /var/opt/mssql/data/master.mdf, copying the missing default master and other system database files. If you have moved the database location, but not moved the database files, startup may fail. To repair: shutdown SQL Server, move the master database to configured location, and restart. 243 | 2020-05-25 16:23:12.11 Server Setup step is copying system data file 'C:\templatedata\mastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'. 244 | 2020-05-25 16:23:12.15 Server Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql/data/model.mdf'. 245 | .... 246 | ``` 247 | 248 | 249 | ### Force Attach (optional) 250 | 251 | >NOTE: This is a hack for anyone who is still using Windows10 with WSL2 (win11 is fixed) 252 | 253 | - FORCE_ATTACH_IF_MDF_EXISTS 254 | 255 | 1 -> if you don´t want to "restore" and the files exists, you can attach those databases 256 | 0 -> if you did´nt executed docker-compose down, you can still "up" your container with previously restored databases 257 | 258 | You can create and run the image with the following command: 259 | 260 | ```cmd 261 | docker compose up --build 262 | ``` 263 | 264 | ## Customization 265 | 266 | ### How to change the SQL Server base image 267 | 268 | The [Dockerfile](./Dockerfile) specifies which base SQL Server Instance you want to use for your image. 269 | 270 | In case you want to change the version of the SQL Server used, please go edit the first line of the [Dockerfile](./Dockerfile) and select your prefered version. For example 271 | 272 | Change 273 | 274 | ```docker 275 | FROM mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04 276 | ``` 277 | 278 | To 279 | 280 | ```docker 281 | FROM mcr.microsoft.com/mssql/server:2017-latest-ubuntu 282 | ``` 283 | 284 | To get the latest SQL Server 2017 version with applied CU 285 | 286 | __NOTE:__ To see which SQL Server versions, please go [here](https://hub.docker.com/_/microsoft-mssql-server) and select your "tag" 287 | 288 | ### How to add new databases to the image 289 | 290 | It´s as easy as modifying the [Dockerfile](./Dockerfile), and adding the new backups you want to restore, and modifying the [setup.sql](./setup.sql) file with the RESTORE command. 291 | 292 | ### How to change the sa password 293 | 294 | The password for the "sa" account is specified at the [docker-compose.yml](./docker-compose.yml) file. 295 | 296 | ## FAQ 297 | ### How does it works? 298 | 299 | [![deploy sql server in docker with mssql-server-samplesdb](http://img.youtube.com/vi/ULL5nntWn1A/0.jpg)](http://www.youtube.com/watch?v=ULL5nntWn1A "mssql-server-samplesdb") 300 | 301 | 302 | > NOTE: If you want me to make a translation of this video to english, please show me a little of your support! and when I reach 150€ I´ll do it! GitHub Sponsors 303 | 304 | As you can see, its a little tricky but when you find how it works, its very simple and stable: 305 | 306 | [Dockerfile](/Dockerfile) makes 3 mayor steps 307 | 308 | #### Restoring databases 309 | 310 | This is the tricky part since involves 2 scripts and the final command to keep alive the image 311 | 312 | ##### Entrypoint 313 | 314 | ```docker 315 | COPY setup.* ./ 316 | COPY entrypoint.sh ./ 317 | 318 | RUN chmod +x setup.sh 319 | RUN chmod +x entrypoint.sh 320 | 321 | # This entrypoint start sql server, restores data and waits infinitely 322 | ENTRYPOINT ["./entrypoint.sh"] 323 | ``` 324 | 325 | #### Avoid container to stop after deploy 326 | 327 | To avoid the container to stop after first run, you need to ensure that is waiting for something. the best solution is to add a sleep infinity...as simple as it sounds :) 328 | 329 | ```docker 330 | CMD ["sleep infinity"] 331 | ``` 332 | 333 | --------------------------------------------------------------------------------