![](http://2.bp.blogspot.com/-WWQfJc_M3kA/WKGfna3e71I/AAAAAAAAOR8/yxbRvn2ID80majkc5qUjcl1d3Ky4FGRQACLcB/s1600/Windows-Container.png)
Container was first introduced in Sun Solaris operating system but now it is widely available in Linux and Windows as well. The container is an isolated area where an application can run without affecting the rest of the system, and without the system affecting the application. Container shares operating system's kernel so it can be configured as “isolated” part of guest OS.
- Windows Server Containers– A Windows Server container shares a kernel with the container host and all containers running on the host.
- Hyper-V Containers– expand on the isolation provided by Windows Server Containers by running each container in a Hyper-V virtual machine. In this configuration the kernel of the container host is not shared with other Hyper-V Containers.
This article will guide you through the steps to set up Windows Containers on Nano Server using PowerShell command line.
Connecting to Nano Server
Set-Item WSMan:\localhost\Client\TrustedHosts 192.168.1.200 -Force Enter-PSSession -ComputerName 192.168.1.10 -Credential AdministratorUpdating Nano Server
#Scan for updates
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
$result = $ci | Invoke-CimMethod -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0";OnlineScan=$true}
$result.Updates
# Install all updates
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
Invoke-CimMethod -InputObject $ci -MethodName ApplyApplicableUpdates
Restart-Computer
# List Installed Updates
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
$result = $ci | Invoke-CimMethod -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=1";OnlineScan=$true}
$result.Updates
Installing Container
You can install the OneGet PowerShell module and the latest version of Docker by executing the following commands:
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider
Restart-Computer
![](http://3.bp.blogspot.com/-ZJpMhTePmLY/WKGZkhGGQZI/AAAAAAAAORg/DNvzAgQxOyozNmWRrMBnGT710cPN580lACLcB/s1600/Windows-Container.png)
Once rebooted, Start Docker service and install base image
Start-Service docker
docker pull microsoft/nanoserver
Enabling remote access to docker host (Nano Server)
netsh advfirewall firewall add rule name="Docker daemon " dir=in action=allow protocol=TCP localport=2375
Stop-Service docker
dockerd --unregister-service
dockerd -H npipe:// -H 0.0.0.0:2375 --register-service
Start-Service docker
Connecting to Windows container from remote computer
First you need to download docker client using the following command
Invoke-WebRequest "https://download.docker.com/components/engine/windows-server/cs-1.12/docker.zip" -OutFile "$env:TEMP\docker.zip" -UseBasicParsing
Now, extract it using the following command
Expand-Archive -Path "$env:TEMP\docker.zip" -DestinationPath $env:ProgramFiles
You need to set environment variable which does not require shell to be restarted.
$env:path += ";c:\program files\docker"
Now, add docker directory to system path
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine)
Connect to docker container hosted on Nano Server (192.168.0.200), the following command will create container from microsoft/nanoserver image with container1 and hostname container1
docker -H tcp://192.168.0.200:2375 run -it --name container1 --hostname container1 microsoft/nanoserver cmd
Done.