Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Docker for a .NET web developer

179 views

Published on

You have probably heard about Docker, these days it is a popular topic with cloud computing. But what does it take for a .NET developer to start with Docker? And where can you use it? Of course, you can deploy an application to the cloud using Docker. But you can also use Docker very effectively as a support tool when developing or testing. In this session, Maurice de Beijer will show you some of the many opportunities to use Docker.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Docker for a .NET web developer

  1. 1. Docker for a .NET web developer Mauricede Beijer-@mauricedb
  2. 2. Topics  What is a Container and Docker?  Docker onWindows  Docker andVS2017  Docker and SQL Server © ABL - The Problem Solver 3
  3. 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
  4. 4. Containers
  5. 5. Virtual Machine vs Container
  6. 6. Linux
  7. 7. Windows
  8. 8. 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 
  9. 9. 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
  10. 10. Simple Dockerfile FROM microsoft/aspnetcore-build:2.0 WORKDIR /app EXPOSE 80 COPY MyApp . ENTRYPOINT ["dotnet", "run", "--no-launch-profile"]
  11. 11. 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
  12. 12. 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 
  13. 13. 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
  14. 14. 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"]
  15. 15. VisualStudio 2017
  16. 16. Docker Compose  A tool for defining and running multi-container Docker applications.  Used byVisual Studio 2017
  17. 17. Docker Compose version: '3' services: dockerdemo: image: dockerdemo build: context: ./DockerDemo dockerfile: Dockerfile
  18. 18. 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
  19. 19. 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
  20. 20. Docker Compose version: '3' services: dockerdemo: image: dockerdemo build: context: ./DockerDemo dockerfile: Dockerfile depends_on: - demodata demodata: image: "demodata:10"
  21. 21. Service name is host name protected override void OnConfiguring( DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer( "Server=DemoData;Database=DemoDB;user=sa;password=Password1;"); }
  22. 22. 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
  23. 23. Maurice de Beijer @mauricedb maurice.de.beijer @gmail.com © ABL - The Problem Solver 26

×