This will set up buildkitd
natively on Windows Server 2019 (ltsc2019) or Windows Server 2022 (ltsc2022).
This will reboot your server if the feature is not already installed.
Install-WindowsFeature -Name containers -Restart
To install everything simply run:
wget -UseBasicParsing `
-OutFile $HOME\setup_buildkitd_on_windows.ps1 `
https://gist.githubusercontent.com/gabriel-samfira/6e56238ad11c24f490ac109bdd378471/raw/290dcd098814c8f624433e4e21b74f3f6b0156fa/setup_buildkitd_on_windows.ps1
& $HOME\setup_buildkitd_on_windows.ps1
This will install git
, golang
, mingw
, make
. The buildctl.exe
command will be available in C:\Program Files\buildkitd\bin\buildctl.exe
Create a work folder:
mkdir $HOME/playground
cd $HOME/playground
Write a simple Dockerfile
:
Set-Content Dockerfile @"
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
ADD https://github.com/kubernetes-sigs/windows-testing/raw/3fea3d48ea8337b2aaca755c1d719e34b45f46b9/images/busybox/busybox.exe /bin/busybox.exe
USER ContainerAdministrator
RUN net user testuser /ADD /ACTIVE:yes
USER testuser
RUN echo "%USERNAME%"
"@
Now build the dockerfile:
buildctl.exe build --output type=image,name=docker.samfira.com/test,push=false `
--progress plain `
--frontend=dockerfile.v0 `
--local context=. `
--local dockerfile=.
Note: if you're on Windows Server 2019 replace:
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
with
FROM mcr.microsoft.com/windows/nanoserver:ltsc2019
On ltsc2019
you may get an error when building: The requested operation for attach namespace failed.: unknown
. To work around it, remove the existing endpoint:
Get-HnsEndpoint | Remove-HnsEndpoint
And try again.