Docker for a .NET web developer Mauricede Beijer-@mauricedb
Topics  What is a Container and Docker?  Docker onWindows  Docker andVS2017  Docker and SQL Server © ABL - The Problem Solver 3
 Maurice de Beijer  The Problem Solver  MicrosoftAzure MVP  Freelance developer/instructor  Twitter: @mauricedb  Web: http://www.TheProblemSolver.nl  E-mail: maurice.de.beijer@gmail.com 4
Containers
Virtual Machine vs Container
Linux
Windows
Nano server vs Windows ServerCore  OnWindows Docker containers can either run Nano Server or Windows Server Core  The microsoft/nanoserver  The image is 1.08GB  microsoft/windowsservercore  The image is 10.3GB 
Container runtimes Windows Server Containers docker run --isolation=process  Uses a shared kernel  Process & namespace isolation  Trusted code only  Windows Server 2016 only Hyper-V Isolation docker run --isolation=hyperv  Kernel is not shared.  Optimized virtual machine  Execute untrusted code  Windows 10 or server 2016
Simple Dockerfile FROM microsoft/aspnetcore-build:2.0 WORKDIR /app EXPOSE 80 COPY MyApp . ENTRYPOINT ["dotnet", "run", "--no-launch-profile"]
The problem  Using source code in production  4.64MB the initial application  Optionally:  RUN dotnet build  ENTRYPOINT ["dotnet", " MyWebApp.dll"]  Large image with complete SDK and NuGet packages  2.75GB on Windows  1.86GB on Linux  Based on 100MB Debian
The solution  Only release binaries in container image  Just 2.72MB for the initial application   Much smaller image  1.25GB onWindows  283MB on Linux  Based on 100MB Debian with .NET Core 2.0  Alpine Linux is just 3.97MB and can be used with .NET Core 2.1 
Multi stage Dockerfile (Builder) # Build and publish source code in image "builder" FROM microsoft/aspnetcore-build:2.0 AS builder WORKDIR /src COPY *.sln ./ COPY MyApp/MyApp.csproj MyApp/ RUN dotnet restore COPY . . WORKDIR /src/MyApp RUN dotnet publish -c Release -o /MyApp
Multi stage Dockerfile (Runtime) # Build actual runtime container image FROM microsoft/aspnetcore:2.0 WORKDIR /MyApp EXPOSE 80 WORKDIR /app COPY --from=builder /MyApp . ENTRYPOINT ["dotnet", " MyApp.dll"]
VisualStudio 2017
Docker Compose  A tool for defining and running multi-container Docker applications.  Used byVisual Studio 2017
Docker Compose version: '3' services: dockerdemo: image: dockerdemo build: context: ./DockerDemo dockerfile: Dockerfile
SQLServer 2016 on Docker  Both onWindows and Linux   TheWindows image is 13GB   Based on Windows Server Core  Linux image is 1.4GB  Base on Ubuntu 16
Building a test database # Build a test data image FROM microsoft/mssql-server-windows COPY . . RUN sqlcmd -i CreateAndPopulateDatabase.sql SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop’; $ProgressPreference = 'SilentlyContinue';"] CMD .start -sa_password Password1 -ACCEPT_EULA Y -Verbose
Docker Compose version: '3' services: dockerdemo: image: dockerdemo build: context: ./DockerDemo dockerfile: Dockerfile depends_on: - demodata demodata: image: "demodata:10"
Service name is host name protected override void OnConfiguring( DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer( "Server=DemoData;Database=DemoDB;user=sa;password=Password1;"); }
Conclusion © ABL - The Problem Solver 25  Docker is a great way of shipping and hosting applications  Works well on Linux andWindows  Also great at development time
Maurice de Beijer @mauricedb maurice.de.beijer @gmail.com © ABL - The Problem Solver 26

Docker for a .NET web developer

Editor's Notes

  • #6 https://pixabay.com/nl/container-haven-laden-gestapeld-2687310/
  • #9 https://pixabay.com/nl/pingu%C3%AFns-dierlijke-dierenwereld-2746468/
  • #26 https://www.flickr.com/photos/krupptastic/4738992473