deploying applications to windows server 2016 and windows containers

Post on 13-Apr-2017

410 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Deploying Applications to Windows Containers and Windows Server 2016

@Ben_HallBen@BenHall.me.uk

OcelotUproar.com / Katacoda.com

Deploying Applications to Windows Containers and Windows Server 2016

@Ben_HallBen@BenHall.me.uk

OcelotUproar.com / Katacoda.com

@Ben_Hall / Blog.BenHall.me.uk

Docker London OrganiserMicrosoft MVP in Cloud / Datacentre Management

Software Development Studio

WH

O AM

I?

Learn via Interactive Browser-Based LabsKatacoda.com

Agenda• Windows Server 2016• Building and deploying Windows Containers• Differences to Linux• Hyper-V Containers• Docker API / Kubernetes / Swarm• Future

http://www.infoworld.com/article/3072929/linux/containers-101-linux-containers-and-docker-explained.html

Containers are not Virtual Machines

Think of Docker more as a process management

Docker - An open platform for distributed applications for developers and sysadmins.

Batteries included but removable

Three Key Concepts• Docker Containers – Running Processes

• Docker Images – “Layered Zip Files”

• Docker Registry – Where Images are stored

http://windows-wallpapers.net/wp-content/uploads/images/1c/windows-98.png

2016

Windows Server Core

Windows Nano

Windows Containers

Windows Hyper-V

Containers

Windows Containers

Windows KernelWindows Server 2016

SQL Server MSMQ IIS /

ASP.NET Docker Engine

Windows Hyper-V Containers

Windows Kernel

Windows Server 2016

SQL Server MSMQ IIS /

ASP.NET

Windows Kernel

Windows Utility VM

Hyper-V

Docker Engine

Windows Server Core• Nearly Win32 Compatible• Same behaviour of Windows• Install all of the same tooling

Windows Nano• Stripped down• Smallest footprint• 1/20th the size of Windows Server Core• Only essential components– Hyper-V, Clustering, Networking, Storage, .Net,

Core CLR

Windows Server Core => Ubuntu Linux

Windows Nano => Alpine Linux

Windows Server Core => Legacy Apps?

Windows Nano => Modern Apps?

Installing Windows Containers

> Install-Module -Name DockerMsftProvider \ -Repository PSGallery -Force> Install-Package -Name docker \ -ProviderName DockerMsftProvider> Restart-Computer -Force

Layered Zip File

Windows Linux Subsystem• Completely unrelated• Maybe not in the future…

What is a Windows Docker Image?

PS C:\> docker imagesREPOSITORY TAG IMAGE ID CREATEDwindowsservercore 10.0.10586.0 6801d964fda5 2 weeks ago windowsservercore latest 6801d964fda5 2 weeks ago nanoserver 10.0.10586.0 8572198a60f1 2 weeks ago nanoserver latest 8572198a60f1 2 weeks ago

PS C:\> docker run -it \ windowsservercore cmd

Thank you to https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/manage_docker

SSMS

Building Windows based Docker Images

Latest Tag• Official images have a convention of :latest

• Using :latest can introduces problems

• Use CI build number / Semver

Dockerfile

> type DockerfileFROM microsoft/windowsservercore:10.0.14393.693RUN powershell.exe Install-WindowsFeature web-server

> docker build –t iis .

> type DockerfileFROM microsoft/iis:windowsservercore-10.0.14393.693SHELL ["powershell", "-command“]

> type DockerfileFROM microsoft/iis:windowsservercore-10.0.14393.693SHELL ["powershell", "-command"]

RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install-WindowsFeature Web-Asp-Net45

> type DockerfileFROM microsoft/iis:windowsservercore-10.0.14393.693SHELL ["powershell", "-command"]

RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install-WindowsFeature Web-Asp-Net45

RUN Remove-Website -Name 'Default Web Site'; \ mkdir c:\NerdDinner; \ New-Website -Name 'nerd-dinner' \ -Port 80 -PhysicalPath 'c:\NerdDinner' \ -ApplicationPool '.NET v4.5‘

> type DockerfileFROM microsoft/iis:windowsservercore-10.0.14393.693SHELL ["powershell", "-command"]

RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install-WindowsFeature Web-Asp-Net45

RUN Remove-Website -Name 'Default Web Site'; \ mkdir c:\NerdDinner; \ New-Website -Name 'nerd-dinner' \ -Port 80 -PhysicalPath 'c:\NerdDinner' \ -ApplicationPool '.NET v4.5‘

EXPOSE 80

> type DockerfileFROM microsoft/iis:windowsservercore-10.0.14393.693SHELL ["powershell", "-command"]

RUN Install-WindowsFeature NET-Framework-45-ASPNET; Install-WindowsFeature Web-Asp-Net45

RUN Remove-Website -Name 'Default Web Site'; \ mkdir c:\NerdDinner; \ New-Website -Name 'nerd-dinner' \ -Port 80 -PhysicalPath 'c:\NerdDinner' \ -ApplicationPool '.NET v4.5‘

EXPOSE 80

COPY NerdDinner c:\NerdDinner

PS C:\> docker build –t nerddinner .

PS C:\> docker run -d -p 80:80 \ nerddinner

PS C:\> docker build –t nerddinner .

PS C:\> docker run -d -p 80:80 \ nerddinner

PS C:\> docker run -d -p 80:80 \ nerddinner

PS C:\> docker run -d -p 80:80 \ --isolation=hyperv nerddinner

ImmutableDisposable Container Pattern

Windows Updates?

Persisting Data – Data Volumes

> docker run –v <host-dir>:<container-dir> image

-v C:\source:C:\dest

-v C:\container-share\config.ini

-v d:

-v C:\nerddinner\logs:C:\inetpub\logs\LogFiles

Limit CPU Shares> docker run -it --cpu-shares 2 \ --name dockerdemo \ windowsservercore cmd

Powershell APIPS C:\> Get-ContainerImageName Publisher Version IsOSImage---- --------- ------- ---------NanoServer CN=Microsoft 10.0.10584.1000 TrueWindowsServerCore CN=Microsoft 10.0.10584.1000 True

PS C:\> New-Container -ContainerImageName WindowsServerCore -Name demo -ContainerComputerName demo

Name State Uptime ParentImageName---- ----- ------ ---------------demo Off 00:00:00 WindowsServerCore

SQL Server Dependency

docker run --name nerddinnerdb -d -p 1433:1433 -e sa_password=password -e ACCEPT_EULA=Y microsoft/mssql-server-windows-express

PS C:\>docker logs nerddinnerdb

docker run --name nerddinnerdb -d -p 1433:1433 -e sa_password=p@sSw0rd1sl0ngY0 -e ACCEPT_EULA=Y microsoft/mssql-server-windows-express

Docker Compose

> cinst –y docker-compose

> type docker-compose.yml

version: '2.1'networks: default: external: name: natservices: nerddinnerdb: image: microsoft/mssql-server-windows-express:2016-sp1-windowsservercore-10.0.14393.447 ports: - "1433:1433" environment: sa_password: "p@sSw0rd1sl0ngY0" ACCEPT_EULA: "Y"

nerddinnerweb: build: . ports: - "80:80" depends_on: - nerddinnerdb

> docker-compose up -d

> type Dockerfile.windowsFROM microsoft/dotnet:1.0.0-preview2.1-nanoserver-sdk

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]

RUN New-Item -Path \MusicStore\samples\MusicStore.Standalone -Type DirectoryWORKDIR MusicStore

ADD samples/MusicStore.Standalone/project.json samples/MusicStore.Standalone/project.jsonADD NuGet.config .RUN dotnet restore --no-cache .\samples\MusicStore.Standalone

ADD samples samplesRUN dotnet build .\samples\MusicStore.Standalone

EXPOSE 5000ENV ASPNETCORE_URLS http://0.0.0.0:5000CMD dotnet run -p .\samples\MusicStore.Standalone

https://github.com/taylorb-microsoft/MusicStore

> type docker-compose.ymlversion: '2'services: db: image: microsoft/mssql-server-2016-express-windows environment: sa_password: "Password1" ports: - "1433:1433" # for debug. Remove this for production

web: build: context: . dockerfile: Dockerfile.windows environment: - "Data:DefaultConnection:ConnectionString=Server=db,1433;Database=MusicStore;User Id=sa;Password=Password1;MultipleActiveResultSets=True" depends_on: - "db" ports: - "5000:5000"

networks: default: external: name: nat

> docker-compose up –d --build

https://github.com/taylorb-microsoft/MusicStore

> docker tag nerddinner benhall/nerddinner:v2.0> docker push benhall/nerddinner:v2.0

CI/CD PipelineGit Push Gitlab Starts

Build docker build

Gitlab Start Releasedocker push

Docker Compose Pull/Up

docker pull

> cat .gitlab-ci.yml variables: IMAGE_NAME: registry.katacoda.com:4567/root/front-end TAG: $CI_BUILD_IDstages: - build - pushbuild_production: stage: build script: - docker build -t $IMAGE_NAME:$TAG . only: - masterpush_production: stage: build script: - docker push $IMAGE_NAME:$TAG only: - master

How is this different to Linux?

Kernel Virtualisation

http://www.slideshare.net/Docker/windows-server-and-docker-the-internals-behind-bringing-docker-and-containers-to-windows-by-taylor-brown-and-john-starks

http://www.slideshare.net/Docker/windows-server-and-docker-the-internals-behind-bringing-docker-and-containers-to-windows-by-taylor-brown-and-john-starks

Windows Hyper-V Isolation

Windows Hyper-V Isolation• Problem: Shared Kernel• Solution: Super lightweight virtual machines

• Intel Clear Containers• Ubuntu LXD• IBM are working on something

PS C:\> docker run -it -p 80:80 \ --isolation=hyperv app cmd

1) Windows starts 'Utility VM‘ and freezes state2) Forks VM state, brings up a fresh second VM3) Launches container on VM

Properties of Windows Utility VM• Invisible to Docker and containers• All writes are degraded• Separate Kernel to host• SMB file share to access host data

• In the future used for Linux containers?

What about developers?

Install Containers Support on Windows 10> Enable-WindowsOptionalFeature -Online -FeatureName containers -All> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All> Restart-Computer -Force

> Invoke-WebRequest "https://test.docker.com/builds/Windows/x86_64/docker-1.13.0.zip" -OutFile "$env:TEMP\docker-1.13.0-rc4.zip" -UseBasicParsing> Expand-Archive -Path "$env:TEMP\docker-1.13.0.zip" -DestinationPath $env:ProgramFiles> dockerd --register-service> Start-Service Docker

Docker for Windows

https://www.richard-banks.org/2016/09/docker-for-windows-beta-26.html

Docker for Windows

https://www.richard-banks.org/2016/09/docker-for-windows-beta-26.html

Docker for Windows

https://www.richard-banks.org/2016/09/docker-for-windows-beta-26.html

Running Containers in Production

Swarm

Constraint Scheduler$ docker run \ -e constraint:ostypelabel==windowscompat \ windowservercore cmd

$ docker run \ -e constraint:ostypelabel==linuxcompat \ ubuntu bash

Microsoft, Apprenda, Red Hathttps://github.com/kubernetes/kubernetes/issues/22623

Mesosphere DC/OS

Powering Azure Container Service

Host Fingerprinting• Constraints based deployment

• Container is based on Nano Server, within cluster, deploy to server capable of running Nano Server (ie. Windows Server 2016)Host Fingerprinting

Azure Container Service

The Future?

SQL Server as a Container

Visual Studio as a Container?

Everything as a Container

Deploy Anywhere

www.katacoda.com

Next Steps• Katacoda

• Windows Server 2016 on Azure

• Windows 10

Thank you!

@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk

www.Katacoda.com

top related