Introduction to Containers SQL Server and Docker
Introduction to Containers Chris Taylor Worked with SQL Server since 2002 MCSE – Data Platform Exceptional DBA Award finalist Damn that Jeff Moden and his RBAR and Tally tables ☺ SQLNE PASS Chapter Group Leader SQLRelay Organiser Partnerships: • SentryOne Partner / PAC • Redgate Partner / FORG • Pragmatic Works Partner • Nitrosphere Partner Formerly one of those “dirty devs” @SQLGeordie http://www.tonyvalderama.com/images/viz/sidsexist.gif https://i.pinimg.com/originals/54/55/ac/5455accb7ce75570b750bbe6ecdab906.jpg All images © the official Viz web site http://www.viz.co.uk
Agenda • Session Aim • What are containers? • Containers vs Virtual Machines • Images • Getting Setup • Volumes • Dockerfile • Docker Hub • Briefly: • Logs and troubleshooting • Multi-Container Applications • Licensing • Performance • Q&A
Not on the Agenda • Docker-Machine • Docker-Swarm • Networking and Linking
Session Aim • High(ish) level insight into containers and what you can do with them • Learn by example • Demo’s • My mistakes ☺ • Enough of a taste to get the container bug and start experimenting!
Well, it worked on my machine!
The Problem https://cdn.geekwire.com/wp-content/uploads/2012/02/nerd-bigstock_Extreme_Computer_Nerd_1520708.jpg Those pesky Dev’s!!
The Real Problem • Variances: • Environmental • Hardware • Security
What are Containers • Next evolution in virtualisation • Lightweight, stand alone, executable package of a piece of software • Separation of applications or services on the same container host • Isolated, resource controlled, and portable operating environment • Enables true independence between applications / infrastructure / developers / IT ops “Basically, a container is an isolated place where an application can run without affecting the rest of the system, and without the system affecting the application.” https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/
Container History • 1979 – Unix v7 (chroot) • 2000 – FreeBSD Jails • 2001 – Linux VServer • 2004 – Oracle Solaris Containers • 2005 – Open Virtuzzo • 2006 – Process Containers • 2008 – Linux Containers (LXC) • 2011 – Cloud Foundry Warden • 2013 – Let Me Contain That For You (LMCTFY) • 2013 – Docker and the Future • 2015 – VMWare vSphere and Container Integration (Project Bonneville) • Hybrid virtualisation with vSphere and vCloud Director • 2016 – Windows Server 2016 and Windows 10 (Pro/Anniversary) support http://blog.aquasec.com/a-brief-history-of-containers-from-1970s-chroot-to-docker-2016
What is Docker?
https://www.docker.com/what-container
Kernel • The core of the OS • Application requests will go through this • Controls everything from access to the HDD to memory management • Runs in it’s own memory space “It can be thought of as the program which controls all other programs on the computer” https://simple.wikipedia.org/wiki/Kernel_(computer_science)
Container Overview Physical Server Host Operating System Docker / Container Engine Bins/Libs App A Bins/Libs App B App B App BApp A
Pros • Consolidation: • Average container size can be very small (Not Windows/SQL Server - ~12GB) • Less Resource Intensive • Server can host significantly more containers than virtual machines. • Low Cost: • Potentially decrease your operating cost (less servers, less staff) and your development cost (develop for one consistent runtime environment). • Speed: • Can spin up in seconds • Decrease the time needed for development, testing, and deployment of applications and services • Consistency: • Simplify deployments, no difference between running your application locally, on a test server, or in production. • Great option for microservices, DevOps and continuous deployment.
Cons • Security: • Sharing of the Kernel / OS Components means less isolation • Hyper-V Containers? • OS Flexibility: • Becoming less of an issue with Windows Integration and the Docker CLi. • Networking: • Can be tricky • Maintaining connections whilst maintaining isolation • Management: • Seen as an art • Various tools becoming more popular (ie. Swarm/Kubernetes)
So how are Containers different to VMs?
Virtual Machine vs Containers Virtual Machines • Contain a complete operating system and applications • Hypervisor-based virtualization can be resource intensive • Can be large • Hypervisors used to share and manage hardware • Virtual machines residing on the same host can run different operating systems Windows Containers • Bound by the host operating system / daemon, containers on the same server use the same OS • Smaller size • Windows Images still large(ish) • Virtualizing the underlying operating system • Share the kernel of the host OS to access the hardware • Best Practice - 1 process per container • Portability
Virtual Machine vs Windows Container Virtual Machines Windows Container Physical Server Host Operating System Docker / Container Engine Bins/Libs App A Bins/Libs App B App B App BApp A VM 2 Physical Server Host Operating System Hypervisor VM 1 Guest OS Bins/Libs App A Guest OS Bins/Libs App A VM 3 Guest OS Bins/Libs App B
Windows Containers vs Hyper-V Containers Windows Server containers • Multiple container instances can run concurrently on a host • Provide application isolation through process and namespace isolation technology. • Shares a kernel with the host and all containers running on the host • Simplifies patching! Hyper-V containers • Multiple container instances can run concurrently on a host • Each container runs inside of a special virtual machine. • Kernel level isolation • Windows 10 always runs Hyper-V containers
Windows Containers vs Hyper-V Containers Windows Container Hyper-V Container Physical Server Host Operating System Docker / Container Engine Bins/Libs App A Bins/Libs App B App B App BApp A Hyper-V Container Physical Server Host Operating System Docker / Container Engine Hyper-V Container Base Image Kernel (Isolated Copy) Bins/Libs App A Base Image Kernel (Isolated Copy) Bins/Libs App A Hyper-V Container Base Image Kernel (Isolated Copy) Bins/Libs App B
Containers and VMs Together https://www.docker.com/what-container
Container Terminology – The Basics • Container Host • Physical or Virtual computer system configured with the Windows Container feature. • Container OS Image • Containers are deployed from images. The container OS image is the first layer in potentially many image layers that make up a container. This image provides the operating system environment. • Container Image • A container image contains the base operating system, application, and all application dependencies needed to quickly deploy a container. • Container Registry • Container images are stored in a container registry, and can be downloaded on demand. • Dockerfile • Dockerfiles are used to automate the creation of container images.
What do I need to get setup? • Downloads • Host Machine Setup • Enable Features • Installing the Docker Engine • Hyper-V setup • If you wish to use a VM as the Host
Downloads • Can run Docker direct from host/dev machine • but I don't like installing anything locally I don't have to ☺ • Download: • Docker for Windows (Used for Windows 10) • SSMS 17.X (or other compatible version) • OR SQL Server Operations Studio… https://www.docker.com/community-edition#/download
Host Machine Setup • Enough RAM for VM running Docker (Minimum 3250MB for Docker) • OS – Windows 10 Pro or Anniversary Edition • Host processors require nested virtualisation • Enable Hyper-V on Host • Hyper-V Settings • Create Virtual Switch with External Access
Installing the Docker engine (Windows 10) Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All # Download script and run: .Enable-NestedVm.ps1 "Win10_Docker“ Install Docker for Windows docker container run hello-world:nanoserver
Installing the Docker EE engine (Windows Server 2016) # PowerShell module from Docker Inc. Install-Module -Name DockerProvider –Force (Or use DockerMSFTProvider) # Install package docker from the provide DockerMsftProvider (does not work on Win10) Install-Package -Name docker -ProviderName DockerProvider –Force (Or use DockerMSFTProvider) Restart-Computer -Force # Test running a container docker run hello-world:nanoserver
Enable Features Windows Server 2016 Windows 10
Containers on Azure
Hyper-V Setup – Windows 10 Pro Build a Hyper-V VM with either Windows 10 Pro or Anniversary Edition Enable Hyper-V (Win 10 always Hyper-V Containers) Enable Nested Virtualisation Install Docker for Windows Install SSMS If you wish to use it!
Hyper-V Setup – Windows Server 2016 Build a Hyper-V VM with Windows Server 2016 Install PowerShell Module (DockerProvider) Install PowerShell Package (DockerProvider) Enable Hyper-V (if you wish to use Hyper-V containers) Install SSMS If you wish to use it!
Windows Firewall Issue? • Different menu’s if you have the firewall enabled • Cannot share drives from Host to Container • Possible Fixes: • Port 445 blocked? • Allow connection to 10.0.75.1 port 445 (the Windows host) from 10.0.75.2 (the virtual machine) • Restriction on network profile? • vEthernet (DockerNAT) to Private? • Disable/Enable “File and Printer Sharing for Microsoft Networks”? • Did nothing for me!
Docker Commands • docker version • docker search <imagename> • docker pull <imagename>:<tag> • docker images • docker run <parameters> • docker ps –a • docker inspect <containername> • docker logs <containername> • docker stop <containername> • docker start <containername> • docker commit • docker push <imagename> • docker rm <containername> • docker rmi <imagename>
Volumes vs Mounts Volumes • Does not increase size of the container • Easier to back up or migrate than bind mounts. • Work on both Linux and Windows containers. • Can be safely shared among multiple containers. • Volume drivers allow you to store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality. Bind Mounts • Host file/folder is mounted into a container • Limited functionality compared to volumes • Not portable between images • Rely on the host machine’s filesystem having a specific directory structure available
SQL on Linux Container DEMO
That’s fantastic, but I have a gazillion databases to restore!!! http://giftsforlearning.com/wp/tough-questions-with-no-good-answers-whats-a-parent-to-do/
Dockerfile • Contains instructions (commands) to create an image • Each instruction creates a layer! • Automate builds using docker build • Dockerfile – no file extension docker build -t newimagename .
Beware! • Be careful with creating too many (unnecessary?) instructions • Remember the layering? • Wrap the instructions into minimal layers / commits: Multiple Layer Image Simplified Image FROM microsoft/mssql-server-linux:latest WORKDIR /usr/src COPY ./shell /usr/src/sqlscript RUN chmod +x /usr/src/restoredb1.sh RUN chmod +x /usr/src/restoredb2.sh RUN chmod 755 /usr/src CMD /bin/bash ./entrypoint.sh FROM microsoft/mssql-server-linux:latest WORKDIR /usr/src COPY ./shell /usr/src RUN chmod +x /usr/src/restoredb1.sh && chmod +x /usr/src/restoredb2.sh && chmod 755 /usr/src CMD /bin/bash ./entrypoint.sh
NOTE!! • Repository must be lowercase • docker build imagenamehere . • ENV attach_dbs doesn't work for Linux containers • Works on Windows containers • COPY and run .sql in shell (sh) scripts OR • sqlcmd CREATE DATABASE……FOR ATTACH • sqlservr.sh • opt/mssql/bin/sqlservr.sh doesn't exist anymore • opt/mssql/bin/sqlservr instead • If you don't then SQL Server won't start and no scripts can execute • Run something like /bin/bash script afterwards
Dockerfile DEMO
Image Sharing and Reuse • Export/Import (local) docker save --output= busybox.tar busybox docker load --input busybox.tar • DockerHub (cloud) • Commit a Container docker commit sqllinuxrestore sqllinuxrestore:v1 • Tag an Image docker tag sqllinuxrestore:v1 sqlgeordie/sqlrepository:sqllinuxrestore • Push to Docker Hub docker push sqlgeordie/sqlrepository:sqllinuxrestore
Docker Hub - hub.docker.com
Repository
Images and Tags Make sure you tag your images!
Microsoft Images and Tags mssql-server-linux mssql-server-windows-developer mssql-server-windows-express 2017-latest 2017-CU1 latest 2017-GA 2017-latest latest 2017-GA 2017-CU1 2017 2017-windowsservercore-10.0.14393.1715 2016-sp1 2016-sp1-windowsservercore-10.0.14393.1715 2016-sp1-windowsservercore-10.0.14393.1480 2016-sp1-windowsservercore-10.0.14393.1198 2016-sp1-windowsservercore-10.0.14393.693 2017-latest latest 2017-GA 2017-CU1 2017-windowsservercore-10.0.14393.1715 2017 2016-sp1 2016-sp1-windowsservercore-10.0.14393.1715 2016-sp1-windowsservercore-10.0.14393.1480 2016-sp1-windowsservercore-10.0.14393.1198 2016-sp1-windowsservercore-10.0.14393.693 2016-windowsservercore-10.0.14393.447 2016 2016-sp1-windowsservercore-10.0.14393.447 *Notice there is nothing pre-2016, MSFT do not support these but there are some publicly available – see Andrew Pruski - https://hub.docker.com/u/dbafromthecold/
Docker Hub DEMO
Logs and Trouble Shooting • Limited monitoring out the box • Docker Knowledge Hub • docker logs <container_name> • Docker Cli logs • Could use TP tools • eg. SentryOne, cAdvisor (Google) https://docs.docker.com/docker-for-windows/troubleshoot/
Docker-Compose(Multi-Container Applications) • docker-compose <build> • yml (YAML) files version: "3" services: web: build: . ports: - "8000:80" depends_on: - db db: image: "microsoft/mssql-server-linux" environment: SA_PASSWORD: "your_password" ACCEPT_EULA: "Y"
Licensing (Docker) • Community Edition (CE) • Free! • Enterprise Edition (EE) • 3 Levels (Basic / Standard / Advanced) • $1500 - $3500 / Node / yr • EE Basic free for Windows Server 2016 customers https://www.docker.com/pricing
Licensing (Windows) Production • Licensing is at the host level, • each machine or VM which is running Docker. • run any number of Windows Docker containers on that host. • Windows Server 2016 • support from Microsoft and Docker, Inc. Development • Docker for Windows runs on Windows 10 and is free, open- source software. • Docker for Windows can also run a Linux VM on your machine • Like the server version, run any number of Windows Docker containers. https://blog.docker.com/2017/01/docker-windows-server-image2docker/
Licensing (SQL Server) • Licensing has not been finalised • Express and Developer Editions are free • Standard and Enterprise will have a cost • Think VM Licensing https://github.com/Microsoft/mssql-docker https://www.microsoft.com/en-us/sql-server/sql-server-2017-editions “Regardless of where you run it - VM, Docker, physical, cloud, on prem - the licensing model is the same and it depends on which edition of SQL Server you are using.”
Performance • See link to Simon Sabin’s blog: • https://sabin.io/blog/sql-server-container-performance/ • Summary: • “The container seems a bit faster up to four users, but then trails off with the VM being faster later on.” • Expected the container to outperform the VM by a factor of 10-20%. • Difficult to draw any real conclusions. • Not enough reasons from a performance standpoint to recommend containers for database hosting in an enterprise environment.”
Alternatives and TPVs • WinDocks • Allows images of older versions of SQL Server to be created • Portainer.io • GUI based tool • Kubernetes • Docker Swarm • Amazon Elastic Container Service (ECS) • Azure Container Service • Marathon • CoreOS Fleet • Open Stack Magnum • Diego • Hashicorp Nomad
Conclusion Good • Docker provides a facility to quickly provision environments • Consolidation and space savings can be exceptional • Docker Hub has 1000’s of publicly available repositories / images Not so good • Storage fiddly / not user friendly • Lack of monitoring via Docker • TP tools available – cAdvisor • Platform Independency still in its infancy • Windows Docker Service
Summary • Session Aim • What are containers? • Containers vs Virtual Machines • Images • Getting Setup • Volumes • Dockerfile • Docker Hub • Briefly: • Logs and troubleshooting • Multi-Container Applications • Licensing • Performance
Contact Twitter @SQLGeordie Email chris.taylor@jarrinconsultancy.com Blog www.jarrinconsultancy.comblog www.chrisjarrintaylor.co.uk
Questions?
Links • SQL Server on Linux: • SQLPAL: https://blogs.technet.microsoft.com/dataplatforminsider/2016/12/16/sql-server-on- linux-how-introduction/ • • Getting Started: • Docker 101: https://www.slideshare.net/Docker/docker-101-nov-2016?next_slideshow=2Docker 101 - Nov 2016 • https://www.simple-talk.com/sysadmin/virtualization/working-windows-containers-docker- basics/ • • Simple Hello World on nanoserver: • https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start- windows-10 •
Links • Introduction: • Docker introduction • General: • https://blog.sixeyed.com/windows-containers-and-docker-5-things-you-need-to-know/ • Licensing: • https://blog.docker.com/2017/01/docker-windows-server-image2docker/ • Installing: • https://mathaywardhill.com/2017/04/12/installing-sql-server-vnext-on-linux-using-docker- on-windows-10/ • SQL On Linux: • https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-docker • https://roadtoalm.com/2017/01/06/running-a-linux-sql-server-in-a-docker-container/ • Connecting to SQL via sqlcmd: • http://searchsqlserver.techtarget.com/tip/Use-these-commands-to-deploy-SQL-Server- Docker-containers
Links • Nested Virtualisation (for VMs): • https://www.youtube.com/watch?v=ycCK1EyJG6Y (nested virtualisation) • Windocks: • https://www.windocks.com/blog-2/Windows-Containers-at-Work • Performance: • https://sabin.io/blog/sql-server-container-performance/ • https://facility9.com/2017/01/how-do-i-update-my-sql-server-docker-container/ • Error pushing image (add collaborators): • http://stackoverflow.com/questions/41984399/denied-requested-access-to-the-resource-is-denied- docker/42403423 • Terminology: • http://itproguru.com/expert/2016/10/docker-create-container-change-container-save-as-new-image-and-connect-to- container/ • Volumes: • http://paper.li/e-1483951345?read=http%3A%2F%2Fthedatafarm.com%2Fdata-access%2Fmashup-sql-server-on-linux-in- docker-on-a-mac-with-visual-studio-code%2F • http://www.tricksofthetrades.net/2016/03/14/docker-data-volumes/ • https://www.richard-banks.org/2017/03/connecting-to-sql-on-docker.html
Links • Hyper-V containers: • https://www.simple-talk.com/sysadmin/virtualization/working-windows-containers-docker- stride/?utm_source=simpletalk&utm_medium=pubemail&utm_content=20170512- slota2&utm_term=simpletalkmain • https://hyper-v.nu/archives/hvredevoort/2015/05/nested-hypervisor-in-windows-server- vnext/ • https://blogs.technet.microsoft.com/uktechnet/2016/01/11/windows-containers-what-they- are-and-how-they-work/ • Windows Server and Docker - The Internals Behind Bringing Docker and Containers to Windows by Taylor Brown and John Starks • Tutorials: • Docker Container Tutorial #1 Containers vs Images - Focuses on Ubuntu • Learn Docker in 12 Minutes 🐳 • Learn Docker in 20 Minutes

Introduction to Containers - SQL Server and Docker

  • 1.
  • 2.
    Introduction to Containers Chris Taylor Workedwith SQL Server since 2002 MCSE – Data Platform Exceptional DBA Award finalist Damn that Jeff Moden and his RBAR and Tally tables ☺ SQLNE PASS Chapter Group Leader SQLRelay Organiser Partnerships: • SentryOne Partner / PAC • Redgate Partner / FORG • Pragmatic Works Partner • Nitrosphere Partner Formerly one of those “dirty devs” @SQLGeordie http://www.tonyvalderama.com/images/viz/sidsexist.gif https://i.pinimg.com/originals/54/55/ac/5455accb7ce75570b750bbe6ecdab906.jpg All images © the official Viz web site http://www.viz.co.uk
  • 3.
    Agenda • Session Aim •What are containers? • Containers vs Virtual Machines • Images • Getting Setup • Volumes • Dockerfile • Docker Hub • Briefly: • Logs and troubleshooting • Multi-Container Applications • Licensing • Performance • Q&A
  • 4.
    Not on theAgenda • Docker-Machine • Docker-Swarm • Networking and Linking
  • 5.
    Session Aim • High(ish)level insight into containers and what you can do with them • Learn by example • Demo’s • My mistakes ☺ • Enough of a taste to get the container bug and start experimenting!
  • 6.
    Well, it workedon my machine!
  • 7.
  • 8.
    The Real Problem •Variances: • Environmental • Hardware • Security
  • 9.
    What are Containers •Next evolution in virtualisation • Lightweight, stand alone, executable package of a piece of software • Separation of applications or services on the same container host • Isolated, resource controlled, and portable operating environment • Enables true independence between applications / infrastructure / developers / IT ops “Basically, a container is an isolated place where an application can run without affecting the rest of the system, and without the system affecting the application.” https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/
  • 10.
    Container History • 1979– Unix v7 (chroot) • 2000 – FreeBSD Jails • 2001 – Linux VServer • 2004 – Oracle Solaris Containers • 2005 – Open Virtuzzo • 2006 – Process Containers • 2008 – Linux Containers (LXC) • 2011 – Cloud Foundry Warden • 2013 – Let Me Contain That For You (LMCTFY) • 2013 – Docker and the Future • 2015 – VMWare vSphere and Container Integration (Project Bonneville) • Hybrid virtualisation with vSphere and vCloud Director • 2016 – Windows Server 2016 and Windows 10 (Pro/Anniversary) support http://blog.aquasec.com/a-brief-history-of-containers-from-1970s-chroot-to-docker-2016
  • 11.
  • 12.
  • 13.
    Kernel • The coreof the OS • Application requests will go through this • Controls everything from access to the HDD to memory management • Runs in it’s own memory space “It can be thought of as the program which controls all other programs on the computer” https://simple.wikipedia.org/wiki/Kernel_(computer_science)
  • 14.
    Container Overview Physical Server HostOperating System Docker / Container Engine Bins/Libs App A Bins/Libs App B App B App BApp A
  • 15.
    Pros • Consolidation: • Averagecontainer size can be very small (Not Windows/SQL Server - ~12GB) • Less Resource Intensive • Server can host significantly more containers than virtual machines. • Low Cost: • Potentially decrease your operating cost (less servers, less staff) and your development cost (develop for one consistent runtime environment). • Speed: • Can spin up in seconds • Decrease the time needed for development, testing, and deployment of applications and services • Consistency: • Simplify deployments, no difference between running your application locally, on a test server, or in production. • Great option for microservices, DevOps and continuous deployment.
  • 16.
    Cons • Security: • Sharingof the Kernel / OS Components means less isolation • Hyper-V Containers? • OS Flexibility: • Becoming less of an issue with Windows Integration and the Docker CLi. • Networking: • Can be tricky • Maintaining connections whilst maintaining isolation • Management: • Seen as an art • Various tools becoming more popular (ie. Swarm/Kubernetes)
  • 17.
    So how areContainers different to VMs?
  • 18.
    Virtual Machine vsContainers Virtual Machines • Contain a complete operating system and applications • Hypervisor-based virtualization can be resource intensive • Can be large • Hypervisors used to share and manage hardware • Virtual machines residing on the same host can run different operating systems Windows Containers • Bound by the host operating system / daemon, containers on the same server use the same OS • Smaller size • Windows Images still large(ish) • Virtualizing the underlying operating system • Share the kernel of the host OS to access the hardware • Best Practice - 1 process per container • Portability
  • 19.
    Virtual Machine vsWindows Container Virtual Machines Windows Container Physical Server Host Operating System Docker / Container Engine Bins/Libs App A Bins/Libs App B App B App BApp A VM 2 Physical Server Host Operating System Hypervisor VM 1 Guest OS Bins/Libs App A Guest OS Bins/Libs App A VM 3 Guest OS Bins/Libs App B
  • 20.
    Windows Containers vsHyper-V Containers Windows Server containers • Multiple container instances can run concurrently on a host • Provide application isolation through process and namespace isolation technology. • Shares a kernel with the host and all containers running on the host • Simplifies patching! Hyper-V containers • Multiple container instances can run concurrently on a host • Each container runs inside of a special virtual machine. • Kernel level isolation • Windows 10 always runs Hyper-V containers
  • 21.
    Windows Containers vsHyper-V Containers Windows Container Hyper-V Container Physical Server Host Operating System Docker / Container Engine Bins/Libs App A Bins/Libs App B App B App BApp A Hyper-V Container Physical Server Host Operating System Docker / Container Engine Hyper-V Container Base Image Kernel (Isolated Copy) Bins/Libs App A Base Image Kernel (Isolated Copy) Bins/Libs App A Hyper-V Container Base Image Kernel (Isolated Copy) Bins/Libs App B
  • 22.
    Containers and VMsTogether https://www.docker.com/what-container
  • 23.
    Container Terminology –The Basics • Container Host • Physical or Virtual computer system configured with the Windows Container feature. • Container OS Image • Containers are deployed from images. The container OS image is the first layer in potentially many image layers that make up a container. This image provides the operating system environment. • Container Image • A container image contains the base operating system, application, and all application dependencies needed to quickly deploy a container. • Container Registry • Container images are stored in a container registry, and can be downloaded on demand. • Dockerfile • Dockerfiles are used to automate the creation of container images.
  • 24.
    What do Ineed to get setup? • Downloads • Host Machine Setup • Enable Features • Installing the Docker Engine • Hyper-V setup • If you wish to use a VM as the Host
  • 25.
    Downloads • Can runDocker direct from host/dev machine • but I don't like installing anything locally I don't have to ☺ • Download: • Docker for Windows (Used for Windows 10) • SSMS 17.X (or other compatible version) • OR SQL Server Operations Studio… https://www.docker.com/community-edition#/download
  • 26.
    Host Machine Setup •Enough RAM for VM running Docker (Minimum 3250MB for Docker) • OS – Windows 10 Pro or Anniversary Edition • Host processors require nested virtualisation • Enable Hyper-V on Host • Hyper-V Settings • Create Virtual Switch with External Access
  • 27.
    Installing the Dockerengine (Windows 10) Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All # Download script and run: .Enable-NestedVm.ps1 "Win10_Docker“ Install Docker for Windows docker container run hello-world:nanoserver
  • 28.
    Installing the DockerEE engine (Windows Server 2016) # PowerShell module from Docker Inc. Install-Module -Name DockerProvider –Force (Or use DockerMSFTProvider) # Install package docker from the provide DockerMsftProvider (does not work on Win10) Install-Package -Name docker -ProviderName DockerProvider –Force (Or use DockerMSFTProvider) Restart-Computer -Force # Test running a container docker run hello-world:nanoserver
  • 29.
  • 30.
  • 31.
    Hyper-V Setup –Windows 10 Pro Build a Hyper-V VM with either Windows 10 Pro or Anniversary Edition Enable Hyper-V (Win 10 always Hyper-V Containers) Enable Nested Virtualisation Install Docker for Windows Install SSMS If you wish to use it!
  • 32.
    Hyper-V Setup –Windows Server 2016 Build a Hyper-V VM with Windows Server 2016 Install PowerShell Module (DockerProvider) Install PowerShell Package (DockerProvider) Enable Hyper-V (if you wish to use Hyper-V containers) Install SSMS If you wish to use it!
  • 33.
    Windows Firewall Issue? •Different menu’s if you have the firewall enabled • Cannot share drives from Host to Container • Possible Fixes: • Port 445 blocked? • Allow connection to 10.0.75.1 port 445 (the Windows host) from 10.0.75.2 (the virtual machine) • Restriction on network profile? • vEthernet (DockerNAT) to Private? • Disable/Enable “File and Printer Sharing for Microsoft Networks”? • Did nothing for me!
  • 34.
    Docker Commands • dockerversion • docker search <imagename> • docker pull <imagename>:<tag> • docker images • docker run <parameters> • docker ps –a • docker inspect <containername> • docker logs <containername> • docker stop <containername> • docker start <containername> • docker commit • docker push <imagename> • docker rm <containername> • docker rmi <imagename>
  • 35.
    Volumes vs Mounts Volumes •Does not increase size of the container • Easier to back up or migrate than bind mounts. • Work on both Linux and Windows containers. • Can be safely shared among multiple containers. • Volume drivers allow you to store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality. Bind Mounts • Host file/folder is mounted into a container • Limited functionality compared to volumes • Not portable between images • Rely on the host machine’s filesystem having a specific directory structure available
  • 36.
    SQL on LinuxContainer DEMO
  • 37.
    That’s fantastic, butI have a gazillion databases to restore!!! http://giftsforlearning.com/wp/tough-questions-with-no-good-answers-whats-a-parent-to-do/
  • 38.
    Dockerfile • Contains instructions(commands) to create an image • Each instruction creates a layer! • Automate builds using docker build • Dockerfile – no file extension docker build -t newimagename .
  • 39.
    Beware! • Be carefulwith creating too many (unnecessary?) instructions • Remember the layering? • Wrap the instructions into minimal layers / commits: Multiple Layer Image Simplified Image FROM microsoft/mssql-server-linux:latest WORKDIR /usr/src COPY ./shell /usr/src/sqlscript RUN chmod +x /usr/src/restoredb1.sh RUN chmod +x /usr/src/restoredb2.sh RUN chmod 755 /usr/src CMD /bin/bash ./entrypoint.sh FROM microsoft/mssql-server-linux:latest WORKDIR /usr/src COPY ./shell /usr/src RUN chmod +x /usr/src/restoredb1.sh && chmod +x /usr/src/restoredb2.sh && chmod 755 /usr/src CMD /bin/bash ./entrypoint.sh
  • 40.
    NOTE!! • Repository mustbe lowercase • docker build imagenamehere . • ENV attach_dbs doesn't work for Linux containers • Works on Windows containers • COPY and run .sql in shell (sh) scripts OR • sqlcmd CREATE DATABASE……FOR ATTACH • sqlservr.sh • opt/mssql/bin/sqlservr.sh doesn't exist anymore • opt/mssql/bin/sqlservr instead • If you don't then SQL Server won't start and no scripts can execute • Run something like /bin/bash script afterwards
  • 41.
  • 42.
    Image Sharing andReuse • Export/Import (local) docker save --output= busybox.tar busybox docker load --input busybox.tar • DockerHub (cloud) • Commit a Container docker commit sqllinuxrestore sqllinuxrestore:v1 • Tag an Image docker tag sqllinuxrestore:v1 sqlgeordie/sqlrepository:sqllinuxrestore • Push to Docker Hub docker push sqlgeordie/sqlrepository:sqllinuxrestore
  • 43.
    Docker Hub -hub.docker.com
  • 44.
  • 45.
    Images and TagsMake sure you tag your images!
  • 46.
    Microsoft Images andTags mssql-server-linux mssql-server-windows-developer mssql-server-windows-express 2017-latest 2017-CU1 latest 2017-GA 2017-latest latest 2017-GA 2017-CU1 2017 2017-windowsservercore-10.0.14393.1715 2016-sp1 2016-sp1-windowsservercore-10.0.14393.1715 2016-sp1-windowsservercore-10.0.14393.1480 2016-sp1-windowsservercore-10.0.14393.1198 2016-sp1-windowsservercore-10.0.14393.693 2017-latest latest 2017-GA 2017-CU1 2017-windowsservercore-10.0.14393.1715 2017 2016-sp1 2016-sp1-windowsservercore-10.0.14393.1715 2016-sp1-windowsservercore-10.0.14393.1480 2016-sp1-windowsservercore-10.0.14393.1198 2016-sp1-windowsservercore-10.0.14393.693 2016-windowsservercore-10.0.14393.447 2016 2016-sp1-windowsservercore-10.0.14393.447 *Notice there is nothing pre-2016, MSFT do not support these but there are some publicly available – see Andrew Pruski - https://hub.docker.com/u/dbafromthecold/
  • 47.
  • 48.
    Logs and TroubleShooting • Limited monitoring out the box • Docker Knowledge Hub • docker logs <container_name> • Docker Cli logs • Could use TP tools • eg. SentryOne, cAdvisor (Google) https://docs.docker.com/docker-for-windows/troubleshoot/
  • 49.
    Docker-Compose(Multi-Container Applications) • docker-compose<build> • yml (YAML) files version: "3" services: web: build: . ports: - "8000:80" depends_on: - db db: image: "microsoft/mssql-server-linux" environment: SA_PASSWORD: "your_password" ACCEPT_EULA: "Y"
  • 50.
    Licensing (Docker) • CommunityEdition (CE) • Free! • Enterprise Edition (EE) • 3 Levels (Basic / Standard / Advanced) • $1500 - $3500 / Node / yr • EE Basic free for Windows Server 2016 customers https://www.docker.com/pricing
  • 51.
    Licensing (Windows) Production • Licensingis at the host level, • each machine or VM which is running Docker. • run any number of Windows Docker containers on that host. • Windows Server 2016 • support from Microsoft and Docker, Inc. Development • Docker for Windows runs on Windows 10 and is free, open- source software. • Docker for Windows can also run a Linux VM on your machine • Like the server version, run any number of Windows Docker containers. https://blog.docker.com/2017/01/docker-windows-server-image2docker/
  • 52.
    Licensing (SQL Server) •Licensing has not been finalised • Express and Developer Editions are free • Standard and Enterprise will have a cost • Think VM Licensing https://github.com/Microsoft/mssql-docker https://www.microsoft.com/en-us/sql-server/sql-server-2017-editions “Regardless of where you run it - VM, Docker, physical, cloud, on prem - the licensing model is the same and it depends on which edition of SQL Server you are using.”
  • 53.
    Performance • See linkto Simon Sabin’s blog: • https://sabin.io/blog/sql-server-container-performance/ • Summary: • “The container seems a bit faster up to four users, but then trails off with the VM being faster later on.” • Expected the container to outperform the VM by a factor of 10-20%. • Difficult to draw any real conclusions. • Not enough reasons from a performance standpoint to recommend containers for database hosting in an enterprise environment.”
  • 54.
    Alternatives and TPVs •WinDocks • Allows images of older versions of SQL Server to be created • Portainer.io • GUI based tool • Kubernetes • Docker Swarm • Amazon Elastic Container Service (ECS) • Azure Container Service • Marathon • CoreOS Fleet • Open Stack Magnum • Diego • Hashicorp Nomad
  • 55.
    Conclusion Good • Docker providesa facility to quickly provision environments • Consolidation and space savings can be exceptional • Docker Hub has 1000’s of publicly available repositories / images Not so good • Storage fiddly / not user friendly • Lack of monitoring via Docker • TP tools available – cAdvisor • Platform Independency still in its infancy • Windows Docker Service
  • 56.
    Summary • Session Aim •What are containers? • Containers vs Virtual Machines • Images • Getting Setup • Volumes • Dockerfile • Docker Hub • Briefly: • Logs and troubleshooting • Multi-Container Applications • Licensing • Performance
  • 57.
  • 58.
  • 59.
    Links • SQL Serveron Linux: • SQLPAL: https://blogs.technet.microsoft.com/dataplatforminsider/2016/12/16/sql-server-on- linux-how-introduction/ • • Getting Started: • Docker 101: https://www.slideshare.net/Docker/docker-101-nov-2016?next_slideshow=2Docker 101 - Nov 2016 • https://www.simple-talk.com/sysadmin/virtualization/working-windows-containers-docker- basics/ • • Simple Hello World on nanoserver: • https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start- windows-10 •
  • 60.
    Links • Introduction: • Dockerintroduction • General: • https://blog.sixeyed.com/windows-containers-and-docker-5-things-you-need-to-know/ • Licensing: • https://blog.docker.com/2017/01/docker-windows-server-image2docker/ • Installing: • https://mathaywardhill.com/2017/04/12/installing-sql-server-vnext-on-linux-using-docker- on-windows-10/ • SQL On Linux: • https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-docker • https://roadtoalm.com/2017/01/06/running-a-linux-sql-server-in-a-docker-container/ • Connecting to SQL via sqlcmd: • http://searchsqlserver.techtarget.com/tip/Use-these-commands-to-deploy-SQL-Server- Docker-containers
  • 61.
    Links • Nested Virtualisation(for VMs): • https://www.youtube.com/watch?v=ycCK1EyJG6Y (nested virtualisation) • Windocks: • https://www.windocks.com/blog-2/Windows-Containers-at-Work • Performance: • https://sabin.io/blog/sql-server-container-performance/ • https://facility9.com/2017/01/how-do-i-update-my-sql-server-docker-container/ • Error pushing image (add collaborators): • http://stackoverflow.com/questions/41984399/denied-requested-access-to-the-resource-is-denied- docker/42403423 • Terminology: • http://itproguru.com/expert/2016/10/docker-create-container-change-container-save-as-new-image-and-connect-to- container/ • Volumes: • http://paper.li/e-1483951345?read=http%3A%2F%2Fthedatafarm.com%2Fdata-access%2Fmashup-sql-server-on-linux-in- docker-on-a-mac-with-visual-studio-code%2F • http://www.tricksofthetrades.net/2016/03/14/docker-data-volumes/ • https://www.richard-banks.org/2017/03/connecting-to-sql-on-docker.html
  • 62.
    Links • Hyper-V containers: •https://www.simple-talk.com/sysadmin/virtualization/working-windows-containers-docker- stride/?utm_source=simpletalk&utm_medium=pubemail&utm_content=20170512- slota2&utm_term=simpletalkmain • https://hyper-v.nu/archives/hvredevoort/2015/05/nested-hypervisor-in-windows-server- vnext/ • https://blogs.technet.microsoft.com/uktechnet/2016/01/11/windows-containers-what-they- are-and-how-they-work/ • Windows Server and Docker - The Internals Behind Bringing Docker and Containers to Windows by Taylor Brown and John Starks • Tutorials: • Docker Container Tutorial #1 Containers vs Images - Focuses on Ubuntu • Learn Docker in 12 Minutes 🐳 • Learn Docker in 20 Minutes