Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save profnandaa/6c76a0a2ca6f053804642feee9a1526b to your computer and use it in GitHub Desktop.
Save profnandaa/6c76a0a2ca6f053804642feee9a1526b to your computer and use it in GitHub Desktop.
Install Buildkitd on Windows

Installing buildkit on Windows from source

This will set up buildkitd natively on Windows Server 2019 (ltsc2019) or Windows Server 2022 (ltsc2022).

Enable the containers feature

This will reboot your server if the feature is not already installed.

Install-WindowsFeature -Name containers -Restart

Install containerd and buildkitd

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

Testing with a simple Dockerfile

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment