This document discusses Docker containers on Windows. It begins by explaining the difference between virtual machines and containers, and the options for container runtimes on Windows like Nano Server and Windows Server Core. It then provides an example of a simple Dockerfile and discusses strategies for reducing image sizes like using a multi-stage Dockerfile. The document also covers using Docker with Visual Studio 2017 and SQL Server, and concludes with contact information for the author.
10. 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
11. 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
13. 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
14. 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
Alpine Linux is just 3.97MB
15. 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 MyWebApp/MyWebApp.csproj MyWebApp/
RUN dotnet restore
COPY . .
WORKDIR /src/MyWebApp
RUN dotnet build -c Release -o /app
RUN dotnet publish -c Release -o /app
16. Multi stage
Dockerfile
(Runtime)
# Build actual runtime container image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
EXPOSE 80
WORKDIR /app
COPY --from=builder /app .
ENTRYPOINT ["dotnet", " MyWebApp.dll"]
21. 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
22. 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
24. Service name
is host name
protected override void OnConfiguring(
DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
"Server=DemoData;Database=DemoDB;user=sa;password=Password1;");
}