Deploying .net core apps to Docker - dotnetConf Local Bengaluru

Download Deploying .net core apps to Docker - dotnetConf Local Bengaluru

Post on 15-Apr-2017

180 views

Category:

Technology

0 download

Embed Size (px)

TRANSCRIPT

dotnetConf LocalBengaluru | September 24, 2016

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

dotnetConf 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.9/24/2016 8:20 PM1

Deploying .NET Core applications using Docker ContainersSwaminathan VetriMicrosoft MVP@svswaminathanhttp://wannabeegeek.com

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

dotnetConf 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.9/24/2016 8:20 PM2

Shipping ManifestThe Big Picture for working with ContainersContainer VocabularyContainer ArchitectureMicro Services and Containerization .NET CoreVisual StudioVisual Studio Team ServicesAzure Container Service

VocabularyAgentClientComposeContainer DockerfileHostImage MasterOrchestratorRegistryScaffoldSchedulerSlaveTagVolume LayersLabelsRegistrySwarmContainer ServicesTagsServicePorts

CommandsDocker-Machine Create, Env, Ip, Start, Restart, ActiveDocker build, login, pull, push, run, search, tagDocker-Compose Up, Build, Scale

Container Lingua Franca

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80Host OS - HardwareHyper VisorGuest OS #2Start on Earth Docker Hello-WorldDocker Containers and VMsGuest OS #1 (Virtual Machine)Docker Daemon

ServerHost OSHypervisorServerHost OSDocker EngineGuest OSGuest OSGuest OSBins/LibsBins/LibsBins/LibsApp AApp AApp BBins/LibsBins/LibsApp AApp AApp BApp BApp BApp BApp BApp BContainers are isolated, but share OS and, where appropriate, bins/libraries

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80Demo

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80Cool, but where did helloworld come from?

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

Docker RegistryStores docker imagesSearchablePublic Registry Hub.Docker.comPrivate Registries Instanced for youCan be hosted in Docker, Azure, AWS, Google,

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80DemoPS docker search microsoftNAME DESCRIPTION STARS OFFICIAL AUTOMATEDmicrosoft/dotnet Preview images for the .NET Core command l... 107 [OK]microsoft/azure-cli Docker image for Microsoft Azure Command L... 52 [OK]microsoft/iis Internet Information Services (IIS) instal... 11microsoft/oms Monitor your containers using the Operatio... 3 [OK]microsoft/applicationinsights Application Insights for Docker helps you ... 3 [OK]microsoft/sample-dotnet .NET Core running in a Nano Server container 1microsoft/dotnet35 1

PS docker pull microsoft/dotnetUsing default tag: latestlatest: Pulling from microsoft/aspnet604d05dfd165: Extracting [====================================================> ] 34.78 MB/37.19 MBa3ed95caeb02: Download completeaf271166b5e5: Download completeffff72610562: Pull complete82633c2ea8fc: Pull complete1ec63dc1715b: Downloading [=========================> ] 29.72 MB/64.67 MB9be54d5ae146: Pull completec3abf6246d6a: Pull completeDigest: sha256:cbbc0a7be0926d017ffd952799c4864c2c6cf812cbb70862bf2c8539401aa1e3Status: Downloaded newer image for microsoft/dotnet:latest

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

DOCKER_HOST

Images Cache

Containers

Registry

ClientDocker pullDocker daemon

Docker runDocker APIDotNetDotNetDotNet

DotNet

dotnetConf 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.9/24/2016 8:20 PM11

VocabularyHostA VM running the Docker Daemon to host a collection of Docker ContainersClientWhere docker commands are executed (client/server)Image An ordered collection of filesystems* to be used when instancing a container * see layers, later onContainer A runtime instance of an imageRegistryA collection of docker images

CommandsDocker runThe process of instancing an Image as a running containerDocker searchSearches the current registryDocker pullPulls a Docker Image to your Docker Host cache

Understanding the Docker Architecture

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80Building Docker Images

Demo - buildPS dotnet newPS Code .# add a docker filePS dotnet build c releasePS dotnet publish c release o appPS Docker build t helloworld .Sending build context to Docker daemon 667.6 kBStep 1 : FROM microsoft/dotnet:1.0.0-rc2-core ---> c7a9cf9c81f5Step 2 : WORKDIR /app ---> Using cache ---> eb9360aaf982Step 3 : COPY /app /app ---> Using cache ---> 80e66eaa09e0Step 4 : ENTRYPOINT dotnet DotNetHelloWorld.dll ---> Using cache ---> e559e0c38fbdSuccessfully built e559e0c38fbdPS docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhelloworld latest ae30949a3358 5 seconds ago 242.4 MBPS docker run helloworldHello World!

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

Registry

DOCKER_HOST

Images

Containers

Docker build0001Program.cs110HelloWorld.dll111010111011011010Code/Binaries

ClientDocker buildDocker daemonFROM microsoft/dotnet:latestWORKDIR /appCOPY /app /appENTRYPOINT dotnet HelloWorld.dlldockerfile

Private Registry

Docker runDocker push

Demo push

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80VocabularyHostA VM running the Docker Daemon to host a collection of Docker ContainersImage An ordered collection of filesystems* to be used when instancing a containerContainer A runtime instance of an imageRegistryA collection of docker imagesDockerfileCommands to build a Docker image TagA version identifier for an image, plus the registry namedocker tag [registrypath]/image:[version]

CommandsDocker searchSearches the current registryDocker pullPulls a Docker Image to your Docker Host cacheDocker runThe process of instancing an Image as a running containerDocker loginLogs into the registry so you can push imagesDocker buildCreates an image, using a dockerfile as the definitionDocker tagRenames an image: [registryname]/[user]/[imagename]:[tag]Docker pushPushes an image to a registryUnderstanding the Docker Architecture

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

Host OSNetworking

DOCKER_HOST

Container1Docker daemon

docker0: 192.168.1.100:80:8001:8002:8003eth0: 172.17.0.2

Container2eth0: 172.17.0.3

Container3eth0: 172.17.0.4

Container4eth0: 172.17.0.5eth0: 10.100.2.100veth5998974veth473629aveth2726149bveth736321cDocker Networking uses NAT to route inbound traffic to each containerEach container can use the same port, internal to its container, but must be addressable outside by unique ports per HOST

Load Balancers and Service Discovery are new important topics

Note: networking may vary based on your orchestration engine

Docker Layers

ImageLayers.io

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80Persistent StorageDocker Containers are ImmutableTo save data, you must provide external storageScenarios:LogsDatabase FilesInner Loop Development mounting your source

Volume Drivers

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80Docker VolumeDocker run -v hostpath:/containerpathPS docker run -it -v /c/Users/Swami:/wormhole busybox/ # lsbin dev etc home proc root sys tmp usr var wormhole/ # cd wormhole/wormhole # touch a.txt/wormhole # touch b.txt/wormhole # lsa.txt b.txt/wormhole # cat a.txtHello from the other side of the wormhole/wormhole #

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80Docker VolumeUsing VirtualBox (local), be sure to sit below c/Users, and confirm case sensitivity. (Linux)

*Docker for Windows beta makes this much easierhttp://beta.docker.com

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80VocabularyHostA VM running the Docker Daemon to host a collection of Docker ContainersImage An ordered collection of filesystems* to be used when instancing a container * see layers, later onContainer A runtime instance of an imageRegistryA collection of docker imagesDockerfileCommands to build a Docker image TagA version identifier for an imageVolumeA means to provide persistent storage from an immutable container

CommandsDocker runThe process of instancing an Image as a running containerDocker loginLogs into the registry so you can push imagesDocker buildCreates an image, using a dockerfile as the definitionDocker tagRenames an image: [registryname]/[user]/[imagename]:[tag]Docker pushPushes an image to a registryDocker run v h:cCreate a wormhole from the host to the container, represented as a volumeRefer to docker-compose for common usage scenarios

Docker-compose Volumes

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80You have a local Docker HOST local developmentSeveral hosts in Azure Dev/Test labs as part of your isolated development environmentNeed to troubleshoot issues in your clusterHow do you maintain and manage the certs for each?Working with multiple hosts

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

Docker-Machine.exeManages your various host configurationsStored in %USERPROFILE%\.docker\machine\

PS docker-machine lsNAME ACTIVE DRIVER STATE URL DOCKERdefault - virtualbox Running tcp://docker v1/10.1dockerhost-linux - azure Running tcp://dockerhost-linux.cloudapp.net:2376 v1.10.2PS docker-machine env dockerhost-linux$Env:DOCKER_TLS_VERIFY = "1"$Env:DOCKER_HOST = "tcp://dockerhost-linux.cloudapp.net:2376"$Env:DOCKER_CERT_PATH = "C:\Users\SteveLas\.docker\machine\machines\dockerhost-linux"$Env:DOCKER_MACHINE_NAME = "dockerhost-linux"# Run this command to configure your shell:# Docker-machine env dockerhost-linux | Invoke-ExpressionPS docker-machine activedockerhost-linuxPS docker-machine ip dockerhost-linuxdockerhost-linux.cloudapp.netNote: Docker Machine not required when working with Docker for Windows

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80

Docker-Machine - CreateProvisions Docker Hosts In Azure Linux for now, Windows ComingPS docker-machine create -d azure --azure-subscription-id "[your azure sub id]" --azure-open-port 80 mydockerhost

Docker Docs - Docker-machine create -d azure... Azure Docs - Docker-machine create -d azure ...

GreenR:16 G:124 B:16OrangeR:216 G:59 B:1BlueR:0 G:120 B:215Light GrayR:210 G:210 B:210Light OrangeR:255 G:140 B:0YellowR:255 G:185 B:0Main colorsSecondary colors (use only when necessary)Dark RedR:168 G:0 B:0Light BlueR:16 G:124 B:16Dark BlueR0 G32 B80CommandsDocker-machine createProvisions a VM with the Docker daemon installed and configured locally for useDocker-machine envSwitches between host entriesDocker-machine lsLists the currently configured hostsDocker-machine activeThe currently configured hostDocker...