Windows containers by hand. Part 8: Running HostProcess containers and taking their image apart
All parts of the series “Windows containers by hand”In part 1 we briefly saw the third isolation level, host: the container started, but it ran under the host's name and as SYSTEM. In Kubernetes these containers run kube-proxy and the network plugin's agent: those need access to the node, and Windows has no privileged containers. Why they are needed in a cluster is explained in part 36 of the Kubernetes series. Here we will see what they really are: who creates them, what is left of a container in them and why their base image weighs 20 KB.
The image
Microsoft publishes a separate base image for HostProcess containers. Let's look at it with the same registry requests we used for Nano Server in part 4:
New-Item -ItemType Directory C:\lab\hpc -Force | Out-Null; Set-Location C:\lab\hpc
$reg = 'https://mcr.microsoft.com/v2/oss/kubernetes/windows-host-process-containers-base-image'
$accept = 'application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.docker.distribution.manifest.v2+json'
$index = curl.exe -s -H "Accept: $accept" "$reg/manifests/v1.0.0" | ConvertFrom-Json
$index.manifests.platform | Format-List
$manifest = curl.exe -s -H "Accept: $accept" "$reg/manifests/$($index.manifests[0].digest)" | ConvertFrom-Json
$manifest.layers | Format-List mediaType, size
curl.exe -sL -o base.tar "$reg/blobs/$($manifest.layers[0].digest)"
tar.exe -tvf base.tar
architecture : amd64
os : windows
mediaType : application/vnd.docker.image.rootfs.diff.tar
size : 20480
drwxrwxr-x 0 cloudtest cloudtest 0 Sep 16 2022 Files/
drwxrwxr-x 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/
drwxrwxr-x 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/System32/
drwxrwxr-x 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/System32/config/
-rw-rw-r-- 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/System32/config/SOFTWARE
-rw-rw-r-- 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/System32/config/SYSTEM
-rw-rw-r-- 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/System32/config/SAM
-rw-rw-r-- 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/System32/config/SECURITY
-rw-rw-r-- 0 cloudtest cloudtest 0 Sep 16 2022 Files/Windows/System32/config/DEFAULT
-rw-rw-r-- 0 cloudtest cloudtest 7048 Sep 16 2022 Files/cc0-legalcode.txt
-rw-rw-r-- 0 cloudtest cloudtest 399 Sep 16 2022 Files/License.txt
Compare this with the Nano Server image. There the variant in the index has an os.version, because the image is tied to a Windows build. Here that field is absent: the image fits any build. There is a single layer, an uncompressed 20 KB tar, and there is no Windows in it. Only two licenses and five zero-length registry hives. We will find out why the empty files are needed at the end.
Since there is no os.version, pull-image.ps1 from part 4 will not take this image: it looks in the index for a variant for the host's build. containerd takes it:
$hpc = 'mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0'
nerdctl pull $hpc
nerdctl images
$s = 'C:\ProgramData\containerd\root\io.containerd.snapshotter.v1.windows\snapshots'
$base = (Get-ChildItem $s | Select-Object -First 1).FullName
Get-ChildItem $base | Format-Table Length, Name
Get-ChildItem "$base\Hives" | Format-Table Length, Name
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 b4c9637e032f 46.2MB 21.8kB
Length Name
------ ----
Files
Hives
41943040 blank-base.vhdx
4194304 blank.vhdx
15 layout
Length Name
------ ----
0 DEFAULTUSER_BASE
0 SAM_BASE
0 SECURITY_BASE
0 SOFTWARE_BASE
0 SYSTEM_BASE
On disk the image takes 46 MB, but those are the virtual disk templates that the snapshotter makes for any base layer. The hives in Hives are zero-length too.
The first run
A container from an image that does not even have cmd.exe:
nerdctl run --rm --isolation host $hpc cmd /c "hostname & whoami & ver & cd & set CONTAINER_SANDBOX_MOUNT_POINT"
wincont-lab
nt authority\system
Microsoft Windows [Version 10.0.26100.33650]
C:\hpc
CONTAINER_SANDBOX_MOUNT_POINT=C:\hpc\
cmd.exe here is the host's program, like everything else: the computer name, the Windows version with the host's revision and the SYSTEM account. The current folder is C:\hpc, and the CONTAINER_SANDBOX_MOUNT_POINT variable points to it as well. With any other isolation this image will not start:
nerdctl run --rm $hpc cmd /c ver
nerdctl run --rm --isolation hyperv $hpc cmd /c ver
time="2026-11-09T23:55:34+03:00" level=fatal msg="failed to create shim task: hcs::CreateComputeSystem a2ea3e65be24733b139f9af1417fb65f56fff3e612e69ec620baf45022da53f2: The system cannot find the file specified."
time="2026-11-09T23:55:34+03:00" level=error msg="failed to accept stdout connection on \\\\.\\pipe\\ctr-f9da7bc876f25e41905007fe8ca9c6d232162374250354a7cbec39b2e782d0e2-stdout" error="use of closed network connection"
time="2026-11-09T23:55:34+03:00" level=error msg="failed to accept stderr connection on \\\\.\\pipe\\ctr-f9da7bc876f25e41905007fe8ca9c6d232162374250354a7cbec39b2e782d0e2-stderr" error="use of closed network connection"
time="2026-11-09T23:55:34+03:00" level=fatal msg="failed to create shim task: failed to locate utility VM folder from layer folders: utility VM folder could not be found in layers"
An ordinary container needs the image's system files, and a container with Hyper-V isolation also needs the UtilityVM folder. This image has neither.
What it is from the Windows point of view
Let's start a long-running container and look at it with the tools we used to take ordinary containers apart in part 3. We will need the NtObjectManager module:
Import-Module NtObjectManager
nerdctl run -d --name hp --isolation host $hpc ping -t localhost
hcsdiag list
Get-Process ping | Format-Table Name, Id, SessionId, Path
Get-ChildItem NtObject:\Silos | Format-Table Name, TypeName
Name Id SessionId Path
---- -- --------- ----
PING 1016 0 C:\WINDOWS\system32\PING.EXE
hcsdiag list printed nothing: HCS does not know about this container. The \Silos directory, which holds the object namespaces of server silos, is empty too. The ping process, on the other hand, is an ordinary host process from C:\WINDOWS\system32, in session 0. There is no smss, csrss, lsass or CExecSvc of its own here. Let's see what it is wrapped in:
$p = Get-NtProcess -ProcessId (Get-Process ping).Id
$j = Get-NtProcessJob -Process $p
$j | Format-List Name, Silo, LimitFlags
$j.SiloBasicInformation | Format-List SiloId, NumberOfProcesses, IsInServerSilo
($j.GetProcessIdList() | ForEach-Object { (Get-Process -Id $_).Name }) -join ', '
$j.Close(); $p.Close()
$id = (nerdctl inspect hp | ConvertFrom-Json).Id
(ctr containers info $id | ConvertFrom-Json).Spec.annotations | Format-List 'microsoft.com/*'
Name : JobContainer_c66375505cfc9b11193e28e1346173253387b42dcffbf7eddde92ee2ac65476a
Silo : True
LimitFlags : KillOnJobClose
SiloId : 564
NumberOfProcesses : 2
IsInServerSilo : False
cmd, PING
microsoft.com/hostprocess-container : true
microsoft.com/hostprocess-inherit-user : true
That is the whole container: a job object named JobContainer_ plus the ID, with two processes in it. The KillOnJobClose flag means that when the job is closed, Windows terminates everything running in it, which is why nerdctl rm kills these processes.
The job has been turned into a silo (Silo : True), but it is not the server silo from part 3 (IsInServerSilo : False): it has no object namespace, registry or kernel of its own. The containerd shim does all this itself. When it sees the microsoft.com/hostprocess-container annotation, it does not go to HCS but creates the job on its own; the code is in internal/jobcontainers of the hcsshim project. The second annotation, hostprocess-inherit-user, tells it to start the process as the same user the shim runs as, that is, SYSTEM.
There really is no isolation here: the container changes the host's files and sees its services.
nerdctl exec hp cmd /c "echo from-hostprocess> C:\Windows\Temp\hp.txt & sc query containerd | findstr STATE"
Get-Content C:\Windows\Temp\hp.txt
Remove-Item C:\Windows\Temp\hp.txt
STATE : 4 RUNNING
from-hostprocess
The C:\hpc folder
All that is left of the container's file system is the image files. They are visible inside at C:\hpc, while on the host itself this folder is empty:
nerdctl exec hp cmd /c "dir /b /a C:\hpc & type C:\hpc\License.txt"
"on the host: $((Get-ChildItem C:\hpc -Force | Measure-Object).Count) items"
nerdctl rm -f hp
cc0-legalcode.txt
License.txt
WcSandboxState
Windows
Windows-host-process-containers-base-image by Microsoft Corporation.
To the extent possible under law, the persons who associated CC0 with
Windows-host-process-containers-base-image has waived all copyright
and related or neighboring rights to this work.
You should have received a copy of the CC0 legalcode along with this
work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
on the host: 0 items
This is what the job needs a silo for. The bindflt filter from part 3 attaches the container's volume to C:\hpc only inside this silo, so every container has its own C:\hpc at the same path. The seam shows when the path is needed on a command line:
nerdctl run --rm --isolation host $hpc cmd /c "echo %CONTAINER_SANDBOX_MOUNT_POINT%& set CONTAINER_SANDBOX_MOUNT_POINT"
C:\hpc
CONTAINER_SANDBOX_MOUNT_POINT=C:\hpc\
The values differ. The environment variable ends with a backslash, while %CONTAINER_SANDBOX_MOUNT_POINT% on the command line is substituted by hcsshim itself, before the process starts, and without that backslash. So in a container's command a file path is written as %CONTAINER_SANDBOX_MOUNT_POINT%\app\tool.exe, and inside a batch file as %CONTAINER_SANDBOX_MOUNT_POINT%app\tool.exe.
Mounted folders live inside the silo too: you can reach them both at the given path and through C:\hpc.
New-Item -ItemType Directory C:\share -Force | Out-Null
'hello from host' | Set-Content C:\share\hello.txt
nerdctl run --rm --isolation host -v C:\share:C:\data $hpc cmd /c "type C:\data\hello.txt & type C:\hpc\data\hello.txt"
Test-Path C:\data
hello from host
hello from host
False
There is no C:\data on the host: the path exists only for the processes of this container.
The network
nerdctl run -d --name hp --isolation host -p 8090:8090 $hpc ping -t localhost
nerdctl exec hp cmd /c "ipconfig | findstr IPv4"
Get-HnsEndpoint | Select-Object IPAddress, @{n='Policy';e={"$($_.Policies.Type) $($_.Policies.Protocol) $($_.Policies.ExternalPort)->$($_.Policies.InternalPort)"}} | Format-List
nerdctl rm -f hp
IPv4 Address. . . . . . . . . . . : 192.168.10.30
IPv4 Address. . . . . . . . . . . : 172.30.0.1
IPAddress : 172.30.1.1
Policy : NAT TCP 8090->8090
The process sees the host's addresses, so it runs in the host's network. Yet nerdctl does not know that no network is needed here: the CNI plugin gave the container the address 172.30.1.1 and created an endpoint with a port publishing policy that nobody uses. A program inside listens on a port directly on the host's addresses, and -p is unnecessary for it.
The user
--user accepts accounts that can be obtained without a password, the built-in service accounts:
foreach ($u in 'NT AUTHORITY\Local service', 'NT AUTHORITY\Network Service', 'ContainerUser') {
nerdctl run --rm --isolation host --user $u $hpc cmd /c whoami
}
nt authority\local service
nt authority\network service
time="2026-11-09T23:55:46+03:00" level=fatal msg="failed to create user process token: failed to logon user: The user name or password is incorrect."
ContainerUser exists only in Windows images, and here the logon happens on the host, which has no such account.
Limits
Limits work through the same job:
nerdctl run -d --name hp --isolation host --memory 512m --cpus 1 $hpc ping -t localhost
$p = Get-NtProcess -ProcessId (Get-Process ping).Id
$j = Get-NtProcessJob -Process $p
$j | Format-List LimitFlags, JobMemory
$j.Close(); $p.Close()
$id = (nerdctl inspect hp | ConvertFrom-Json).Id
(ctr containers info $id | ConvertFrom-Json).Spec.windows.resources | ConvertTo-Json -Depth 4
nerdctl rm -f hp
LimitFlags : JobMemory, KillOnJobClose
JobMemory : 536870912
{
"memory": {
"limit": 536870912
},
"cpu": {
"count": 1
}
}
Memory is limited by the job, to 512 MiB. The CPU value is written to the spec the same way as for an ordinary container.
Any image, any build
The base image is not special: --isolation host will also start an ordinary image, even one of an old build that the host does not accept with process isolation.
nerdctl pull --platform windows/amd64 mcr.microsoft.com/windows/nanoserver:1809
nerdctl run --rm --platform windows/amd64 --isolation host mcr.microsoft.com/windows/nanoserver:1809 cmd /c "ver & dir /b C:\hpc"
Microsoft Windows [Version 10.0.26100.33650]
License.txt
Users
Windows
This is a Windows Server 2019 image, yet ver shows build 26100: cmd.exe again comes from the host. The image's files sit in C:\hpc and bother nobody, but here the 601 MB on disk are wasted. That is why a 20 KB image is needed.
Your own image
A HostProcess image usually holds a program and starts it. The official way is a Dockerfile FROM this image and docker buildx build --platform windows/amd64 with BuildKit on Linux. On Windows itself such a build, according to reports in the project, fails with error 0x3f1. A fix, real minimal hives instead of empty files, is already in the image's build script, but the v1.0.0 tag in the registry still holds the old image. We will do without Docker: in part 7 we already wrote a manifest and an index by hand. This time we will build the layer with plain tar: a HostProcess container does not care about the image's files.
Set-Location C:\lab\hpc
New-Item -ItemType Directory layer\Files\app, layer\Hives, oci\blobs\sha256 -Force | Out-Null
@'
@echo off
echo Hello from a HostProcess image
echo user: %USERNAME%, computer: %COMPUTERNAME%
echo files: %CONTAINER_SANDBOX_MOUNT_POINT%
dir /b %CONTAINER_SANDBOX_MOUNT_POINT%app
'@ | Set-Content layer\Files\app\hello.cmd -Encoding ascii
tar.exe -cf layer.tar -C layer Files Hives
$utf8 = New-Object Text.UTF8Encoding $false
function Add-Blob([string] $file) {
$h = (Get-FileHash $file).Hash.ToLower()
Copy-Item $file "oci\blobs\sha256\$h" -Force
[ordered]@{ digest = "sha256:$h"; size = (Get-Item $file).Length }
}
function Add-Json($obj, [string] $file) {
[IO.File]::WriteAllText("$PWD\$file", ($obj | ConvertTo-Json -Depth 6 -Compress), $utf8)
Add-Blob $file
}
$baseLayer = Add-Blob base.tar
$myLayer = Add-Blob layer.tar
$config = Add-Json ([ordered]@{
architecture = 'amd64'
os = 'windows'
config = [ordered]@{ Cmd = @('cmd', '/c', '%CONTAINER_SANDBOX_MOUNT_POINT%\app\hello.cmd') }
rootfs = [ordered]@{ type = 'layers'; diff_ids = @($baseLayer.digest, $myLayer.digest) }
}) config.json
$layerType = 'application/vnd.oci.image.layer.v1.tar'
$manifest2 = Add-Json ([ordered]@{
schemaVersion = 2
mediaType = 'application/vnd.oci.image.manifest.v1+json'
config = $config + @{ mediaType = 'application/vnd.oci.image.config.v1+json' }
layers = @(($baseLayer + @{ mediaType = $layerType }), ($myLayer + @{ mediaType = $layerType }))
}) manifest.json
[IO.File]::WriteAllText("$PWD\oci\oci-layout", '{"imageLayoutVersion":"1.0.0"}', $utf8)
[IO.File]::WriteAllText("$PWD\oci\index.json", ([ordered]@{
schemaVersion = 2
manifests = @($manifest2 + @{
mediaType = 'application/vnd.oci.image.manifest.v1+json'
platform = [ordered]@{ architecture = 'amd64'; os = 'windows' }
annotations = @{ 'org.opencontainers.image.ref.name' = 'docker.io/library/hello-hpc:1.0' }
})
} | ConvertTo-Json -Depth 6 -Compress), $utf8)
tar.exe -cf hello-hpc.tar -C oci .
nerdctl load -i hello-hpc.tar
nerdctl run --rm --isolation host hello-hpc:1.0
Hello from a HostProcess image
user: WINCONT-LAB$, computer: WINCONT-LAB
files: C:\hpc\
hello.cmd
The same steps are collected in the build-hostprocess-image.ps1 script in the 08-hostprocess folder of the repository.
This is the OCI image layout format: the oci folder is packed into a tar and loaded straight into containerd, without a registry. The image takes 25 KB. Like the base image, its index has no os.version. The process's user name is WINCONT-LAB$, which is how SYSTEM looks on a domain member: the computer account.
Now about the empty files. Without the empty Hives folder the layer does not import, even though this image needs no registry:
time="2026-11-09T23:56:31+03:00" level=fatal msg="failed to extract layer (application/vnd.oci.image.layer.v1.tar sha256:3caf684f06ed78aa3342322ca1840991a5429eba7ab429b27fb24a8258e3d4a8) to windows as \"extract-829880500-Zzf0 sha256:817e30d5936d9270c36db18fc2665e46d84e683c76b0bec29fd7970d16280a9a\": hcsshim::ImportLayer failed in Win32: The configuration registry database is corrupt. (0x3f1)"
BuildKit on Linux builds exactly the same layer: Files with our files and an empty Hives folder.
And a single layer without the five hives in Files\Windows\System32\config fails while the base layer is being prepared:
time="2026-11-09T23:53:34+03:00" level=fatal msg="failed to extract layer (application/vnd.oci.image.layer.v1.tar sha256:c3efb08daa9bdf5a1fda27ac00712c431a20ac80dfa1f9894b9c0bde144d2f8c) to windows as \"extract-676697100-xaIL sha256:c3efb08daa9bdf5a1fda27ac00712c431a20ac80dfa1f9894b9c0bde144d2f8c\": hcsshim::ProcessBaseLayer \\\\?\\C:\\ProgramData\\containerd\\root\\io.containerd.snapshotter.v1.windows\\snapshots\\214: The system cannot find the path specified."
That is what the five zero-length files are for. Importing a layer in Windows expects to see a base image with a registry, and the empty files carry it through this check. Nobody reads their contents: the container does not boot a system.
Cleaning up
We removed the containers along the way. The images and folders remain. nerdctl load leaves a second entry for the image of the form import@sha256:…, so we remove the images through ctr:
Set-Location C:\
ctr image ls -q | ForEach-Object { ctr image rm $_ }
Remove-Item C:\share, C:\lab, C:\hpc -Recurse -Force
The shim creates the empty C:\hpc on the host the first time such a container starts.
Part summary
| Process isolation | Hyper-V isolation | HostProcess | |
|---|---|---|---|
| Created by | HCS | HCS, then a service in the utility VM | the containerd shim, without HCS |
| Kernel | the host's | its own, from the image | the host's |
| Silo | server | inside the VM | application, with no object namespace of its own |
| System files | from the image layers | from the image layers | the host's |
| Image files | the container's C:\ |
the container's C:\ |
C:\hpc |
| Network | its own HNS endpoint | its own HNS endpoint | the host's |
| Default user | from the image | from the image | SYSTEM |
| Image build | must match | can be older | does not matter |
- A HostProcess container is ordinary host processes in a job object. HCS does not know about it, and
hcsdiag listis empty. - The job becomes an application silo only to show the image files and mounted folders inside at their own paths.
- The base image needs no operating system: it has five empty hive files, which layer import requires.
- This is not a container for applications: it is a process running as SYSTEM with access to the whole host. Such containers are for node agents, and you should run in them only what you would trust as a service on the host.
What the series covered
We started with containerd and nerdctl on a clean Windows Server and went down one layer at a time:
- containerd without Kubernetes: manual installation, the
natCNI plugin, ports, host folders and files, limits, isolation levels. - Names and addresses: a shared
hostsfile, our own IPAM plugin in C# with reservations by name, and CoreDNS. - What is inside a container: layers on disk,
sandbox.vhdx, thewcifsandbindfltfilters, a server silo in the kernel object namespace. - An image without containerd: the registry protocol, digest and
diff_id,wclayer, what containerd passes to the shim. - A container without a runtime: HCS and HNS directly from our own program, a small runtime in two scripts.
- Hyper-V isolation: the utility VM, its kernel from the image and running a 2019 image on Server 2025.
- An image without Docker: a layer from a folder, OCI image layout, an index with
os.versionand a push to a registry. - HostProcess: a container without HCS, a job object,
C:\hpcand an image of empty files.
Under all the tools there are two Windows services and a few formats. HCS creates a container from a JSON document, HNS gives it a network, and an image is layers with Files and Hives, tied together by a manifest and an index. Everything else, containerd, nerdctl, Docker, kubelet, is a convenient layer on top of them. HostProcess shows the other side: when isolation is not needed, a container comes down to a job object and a folder of files.
Sources
- Create a Windows HostProcess Pod — the Kubernetes documentation: HostProcess pods, users and volume mounts.
- windows-host-process-containers-base-image — the repository of the base image.
- hcsshim: jobcontainers — the shim code that creates a container from a job object.
- Job Objects — Microsoft Learn: job objects.
- OCI Image Layout — the format of a folder holding an image.
Only registered users can leave a comment.
Sign in or register to leave a comment.