Contenu connexe Similaire à The How and Why of Windows containers (20) The How and Why of Windows containers1. The Why and How of Windows Containers
@Ben_Hall
Ben@BenHall.me.uk
OcelotUproar.com / Katacoda.com
4. The Why and How of Windows Containers
@Ben_Hall
Ben@BenHall.me.uk
OcelotUproar.com / Katacoda.com
7. Agenda
• Windows Server 2016
• Building and deploying Windows Containers
• Differences to Linux
• Hyper-V Containers
• Docker API / Kubernetes / Swarm
• Future
18. Windows Server Core
• Nearly Win32 Compatible
• Same behaviour of Windows
• Install all of the same tooling
19. 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
20. Windows Server Core => Ubuntu Linux
Windows Nano => Alpine Linux
Windows Server Core => Legacy Apps?
Windows Nano => Modern Apps?
23. C:> Install-WindowsFeature containers
C:> Invoke-WebRequest
"https://get.docker.com/builds/Windows/x86_64/docker
-1.12.0.zip" -OutFile "$env:TEMPdocker-1.12.0.zip" -
UseBasicParsing
C:> dockerd --register-service
C:> Start-Service Docker
31. PS C:> docker images
REPOSITORY TAG IMAGE ID CREATED
windowsservercore 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
32. PS C:> docker run -it
windowsservercore cmd
Thank you to https://msdn.microsoft.com/en-
36. PS C:> docker run -it
--name iisbase
windowsservercore cmd
[iisbase] C:>
Thank you to https://msdn.microsoft.com/en-
us/virtualization/windowscontainers/quick_start/manage_docker
37. PS C:> docker run -it
--name iisbase
windowsservercore cmd
C:> powershell.exe Install-WindowsFeature web-server
C:> exit
PS C:> docker commit iisbase windowsservercoreiis
4193c9f34e320c4e2c52ec52550df225b2243927ed21f014fbfff3f29474
b090
43. C:SourceCode> docker build –t app .
PS C:> docker images
REPOSITORY TAG IMAGE ID CREATED
app latest k23jjin423d 1 minutes ago
iis 10 as4w9c928829 9 minutes ago
windowsservercore 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
46. FROM microsoft/windowsservercore
LABEL Description="Nginx" Vendor=Nginx" Version="1.0.13”
RUN powershell -Command
$ErrorActionPreference = 'Stop';
Invoke-WebRequest -Method Get -Uri http://nginx.org/download/nginx-
1.9.13.zip -OutFile c:nginx-1.9.13.zip ;
Expand-Archive -Path c:nginx-1.9.13.zip -DestinationPath c: ;
Remove-Item c:nginx-1.9.13.zip –Force
WORKDIR /nginx-1.9.13
CMD ["/nginx-1.9.13/nginx.exe"]
47. FROM microsoft/dotnet35
ENV sql_express_download_url "https://download.microsoft.com/download/1/5/6/156992E6-F7C7-4E55-833D-
249BD2348138/ENU/x64/SQLEXPR_x64_ENU.exe"
ENV sa_password _
ENV attach_dbs "[]”
COPY . /
WORKDIR /
RUN powershell -Command (New-Object System.Net.WebClient).DownloadFile('%sql_express_download_url%', 'sqlexpress.exe') &&
/sqlexpress.exe /qs /x:setup && /setup/setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine
/UPDATEENABLED=0 /SQLSVCACCOUNT="NT AUTHORITYSystem" /SQLSYSADMINACCOUNTS="BUILTINADMINISTRATORS"
/TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS && del /F /Q sqlexpress.exe && rd /q /s setup
RUN powershell -Command
set-strictmode -version latest ;
stop-service MSSQL`$SQLEXPRESS ;
set-itemproperty -path 'HKLM:softwaremicrosoftmicrosoft sql servermssql12.SQLEXPRESSmssqlserversupersocketnetlibtcpipall' -
name tcpdynamicports -value '' ;
set-itemproperty -path 'HKLM:softwaremicrosoftmicrosoft sql servermssql12.SQLEXPRESSmssqlserversupersocketnetlibtcpipall' -
name tcpport -value 1433 ;
set-itemproperty -path 'HKLM:softwaremicrosoftmicrosoft sql servermssql12.SQLEXPRESSmssqlserver' -name LoginMode -value
2 ;
CMD powershell ./start -sa_password %sa_password% -attach_dbs "%attach_dbs%" -Verbose
48. FROM microsoft/nanoserver
ENV GOLANG_VERSION 1.6
ENV GOLANG_DOWNLOAD_URL "https://golang.org/dl/go$GOLANG_VERSION.windows-amd64.zip"
RUN powershell.exe -Command ;
$handler = New-Object System.Net.Http.HttpClientHandler ;
$client = New-Object System.Net.Http.HttpClient($handler) ;
$client.Timeout = New-Object System.TimeSpan(0, 30, 0) ;
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new() ;
$responseMsg = $client.GetAsync([System.Uri]::new('%GOLANG_DOWNLOAD_URL%'), $cancelTokenSource.Token) ;
$responseMsg.Wait() ;
$downloadedFileStream = [System.IO.FileStream]::new('c:go.zip', [System.IO.FileMode]::Create,
[System.IO.FileAccess]::Write) ;
$response = $responseMsg.Result ;
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream) ;
$copyStreamOp.Wait() ;
$downloadedFileStream.Close() ;
[System.IO.Compression.ZipFile]::ExtractToDirectory('c:go.zip','c:') ;
Remove-Item c:go.zip -Force
RUN powershell.exe -Command $path = $env:path + ';c:gobin'; Set-ItemProperty -Path
'HKLM:SYSTEMCurrentControlSetControlSession ManagerEnvironment' -Name Path -Value $path
51. Networking
> docker run -it --mac="92:d0:c6:0a:29:33"
windowsservercore cmd
> docker run –it -p 8082:80
windowsservercore cmd
> Multi-host out the box
52. Persisting Data – Data Volumes
> docker run –v <host-dir>:<container-dir> image
-v C:source:C:dest
-v C:container-shareconfig.ini
-v d:
53. Limit CPU Shares
> docker run -it --cpu-shares 2
--name dockerdemo
windowsservercore cmd
54. Powershell API
PS C:> Get-ContainerImage
Name Publisher Version IsOSImage
---- --------- ------- ---------
NanoServer CN=Microsoft 10.0.10584.1000 True
WindowsServerCore CN=Microsoft 10.0.10584.1000 True
55. PS C:> New-Container -ContainerImageName
WindowsServerCore -Name demo -
ContainerComputerName demo
Name State Uptime ParentImageName
---- ----- ------ ---------------
demo Off 00:00:00 WindowsServerCore
57. {
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
{
"mediaType": "application/vnd.docker.image.manifest.v2+json",
"size": 7143,
"digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f",
"platform": {
"architecture": ”amd64",
"os": "linux",
}
},
{
"mediaType": "application/vnd.docker.image.manifest.v2+json",
"size": 7682,
"digest": "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270",
"platform": {
"architecture": "amd64",
"os": ”windows",
"features": [
"sse4"
]
63. var cs = new ContainerSettings
{
SandboxPath = path,
Layers = layers,
KillOnClose = true,
NetworkId = HostComputeService.FindNatNetwork(),
};
using (var container = HostComputeService.CreateContainer(id.ToString(), cs))
{
Console.Out.WriteLine("starting container");
Console.Out.Flush();
container.Start();
var si = new ProcessStartInfo { CommandLine = command };
using (var process = container.CreateProcess(si))
{
Console.Out.Write(process.StandardOutput.ReadToEnd());
process.WaitForExit(5000);
Console.Out.WriteLine("process exited with {0}", process.ExitCode);
}
container.Shutdown(Timeout.Infinite);
}
64. [DllImport("vmcompute.dll", PreserveSig = false, ExactSpelling = true)]
IntPtr computeSystem;
h.CreateComputeSystem(id, JsonHelper.ToJson(hcsSettings), IntPtr.Zero, out computeSystem);
return Container.Initialize(id, computeSystem, settings.KillOnClose, h);
66. Windows Hyper-V Isolation
• Problem: Shared Kernel
• Solution: Super lightweight virtual machines
• Intel Clear Containers
• Ubuntu LXD
• IBM are working on something
67. PS C:> docker run -it -p 80:80
--isolation=hyperv app cmd
1) Windows starts 'Utility VM‘ and freezes state
2) Forks VM state, brings up a fresh second VM
3) Launches container on VM
68. 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?
70. Now Available
• Windows 10 Insider Release
• https://msdn.microsoft.com/en-
us/virtualization/windowscontainers/quick_st
art/quick_start_windows_10
74. Constraint Scheduler
$ docker run
-e constraint:ostypelabel==windowscompat
windowservercore cmd
$ docker run
-e constraint:ostypelabel==linuxcompat
ubuntu bash
78. 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
89. Next Steps
• Katacoda
• Microsoft Ignite Conference in two/three weeks
• Windows Server 2016 on Azure
• Windows 10 Insider Release
Notes de l'éditeur Story of data being lost