Skip to content

Commit 37f10b3

Browse files
authored
Merge pull request #19792 from dvdksn/buildkit-windows-exp
build: experimental test instruction buildkit.exe
2 parents 2abe7d9 + 2b13711 commit 37f10b3

File tree

1 file changed

+144
-3
lines changed

1 file changed

+144
-3
lines changed

content/build/buildkit/_index.md

Lines changed: 144 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,150 @@ If the `/etc/docker/daemon.json` file doesn't exist, create new file called
105105
`daemon.json` and then add the following to the file. And restart the Docker
106106
daemon.
107107

108+
## BuildKit on Windows
109+
108110
> **Warning**
109111
>
110-
> BuildKit only fully supports building Linux containers. Experimental Windows
111-
> container support is tracked in
112-
> [`moby/buildkit#616`](https://github.com/moby/buildkit/issues/616)
112+
> BuildKit only fully supports building Linux containers.
113+
> Windows container support is experimental, and is tracked in
114+
> [`moby/buildkit#616`](https://github.com/moby/buildkit/issues/616).
113115
{ .warning }
116+
117+
BuildKit has experimental support for Windows containers (WCOW) as of version 0.13.
118+
This section walks you through the steps for trying it out.
119+
We appreciate any feedback you submit by [opening an issue here](https://github.com/moby/buildkit/issues/new), especially `buildkitd.exe`.
120+
121+
### Known limitations
122+
123+
- BuildKit on Windows currently only supports the `containerd` worker.
124+
Support for non-OCI workers is tracked in [moby/buildkit#4836](https://github.com/moby/buildkit/issues/4836).
125+
126+
### Prerequisites
127+
128+
- Architecture: `amd64`, `arm64` (binaries available but not officially tested yet).
129+
- Supported OS: Windows Server 2019, Windows Server 2022, Windows 11.
130+
- Base images: `ServerCore:ltsc2019`, `ServerCore:ltsc2022`, `NanoServer:ltsc2022`.
131+
See the [compatibility map here](https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility?tabs=windows-server-2019%2Cwindows-11#windows-server-host-os-compatibility).
132+
- Docker Desktop version 4.29 or later
133+
134+
### Steps
135+
136+
> **Note**
137+
>
138+
> The following commands require administrator (elevated) privileges in a PowerShell terminal.
139+
140+
1. Enable the **Hyper-V** and **Containers** Windows features.
141+
142+
```console
143+
> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V, Containers -All
144+
```
145+
146+
If you see `RestartNeeded` as `True`, restart your machine and re-open a PowerShell terminal as an administrator.
147+
Otherwise, continue with the next step.
148+
149+
2. Switch to Windows containers in Docker Desktop.
150+
151+
Select the Docker icon in the taskbar, and then **Switch to Windows containers...**.
152+
153+
3. Install containerd version 1.7.7 or later following the setup instructions [here](https://github.com/containerd/containerd/blob/main/docs/getting-started.md#installing-containerd-on-windows).
154+
155+
4. Download and extract the latest BuildKit release.
156+
157+
```powershell
158+
$version = "v0.13.1" # specify the release version, v0.13+
159+
$arch = "amd64" # arm64 binary available too
160+
curl.exe -LO https://github.com/moby/buildkit/releases/download/$version/buildkit-$version.windows-$arch.tar.gz
161+
# there could be another `.\bin` directory from containerd instructions
162+
# you can move those
163+
mv bin bin2
164+
tar.exe xvf .\buildkit-$version.windows-$arch.tar.gz
165+
## x bin/
166+
## x bin/buildctl.exe
167+
## x bin/buildkitd.exe
168+
```
169+
170+
5. Install BuildKit binaries on `PATH`.
171+
172+
```powershell
173+
# after the binaries are extracted in the bin directory
174+
# move them to an appropriate path in your $Env:PATH directories or:
175+
Copy-Item -Path ".\bin" -Destination "$Env:ProgramFiles\buildkit" -Recurse -Force
176+
# add `buildkitd.exe` and `buildctl.exe` binaries in the $Env:PATH
177+
$Path = [Environment]::GetEnvironmentVariable("PATH", "Machine") + `
178+
[IO.Path]::PathSeparator + "$Env:ProgramFiles\buildkit"
179+
[Environment]::SetEnvironmentVariable( "Path", $Path, "Machine")
180+
$Env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + `
181+
[System.Environment]::GetEnvironmentVariable("Path","User")
182+
```
183+
6. Start `buildkitd.exe`.
184+
185+
```console
186+
> buildkitd.exe
187+
time="2024-02-26T10:42:16+03:00" level=warning msg="using null network as the default"
188+
time="2024-02-26T10:42:16+03:00" level=info msg="found worker \"zcy8j5dyjn3gztjv6gv9kn037\", labels=map[org.mobyproject.buildkit.worker.containerd.namespace:buildkit org.mobyproject.buildkit.worker.containerd.uuid:c30661c1-5115-45de-9277-a6386185a283 org.mobyproject.buildkit.worker.executor:containerd org.mobyproject.buildkit.worker.hostname:[deducted] org.mobyproject.buildkit.worker.network: org.mobyproject.buildkit.worker.selinux.enabled:false org.mobyproject.buildkit.worker.snapshotter:windows], platforms=[windows/amd64]"
189+
time="2024-02-26T10:42:16+03:00" level=info msg="found 1 workers, default=\"zcy8j5dyjn3gztjv6gv9kn037\""
190+
time="2024-02-26T10:42:16+03:00" level=warning msg="currently, only the default worker can be used."
191+
time="2024-02-26T10:42:16+03:00" level=info msg="running server on //./pipe/buildkitd"
192+
```
193+
194+
7. In another terminal with administrator privileges, create a remote builder that uses the local BuildKit daemon.
195+
196+
> **Note**
197+
>
198+
> This requires Docker Desktop version 4.29 or later.
199+
200+
```console
201+
> docker buildx create --name buildkit-exp --use --driver=remote npipe:////./pipe/buildkitd
202+
buildkit-exp
203+
```
204+
205+
8. Verify the builder connection by running `docker buildx inspect`.
206+
207+
```console
208+
> docker buildx inspect
209+
Name: buildkit-exp
210+
Driver: remote
211+
Last Activity: 2024-04-15 17:51:58 +0000 UTC
212+
Nodes:
213+
Name: buildkit-exp0
214+
Endpoint: npipe:////./pipe/buildkitd
215+
Status: running
216+
BuildKit version: v0.13.1
217+
Platforms: windows/amd64
218+
...
219+
```
220+
221+
9. Create a Dockerfile and build a `hello-world` image.
222+
223+
```console
224+
> mkdir sample_dockerfile
225+
> cd sample_dockerfile
226+
> Set-Content Dockerfile @"
227+
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
228+
USER ContainerAdministrator
229+
COPY hello.txt C:/
230+
RUN echo "Goodbye!" >> hello.txt
231+
CMD ["cmd", "/C", "type C:\\hello.txt"]
232+
"@
233+
Set-Content hello.txt @"
234+
Hello from BuildKit!
235+
This message shows that your installation appears to be working correctly.
236+
"@
237+
```
238+
239+
> **Note**
240+
>
241+
> For a consistent experience, use forward-slashes `/` for paths, e.g. `C:/` instead of `C:\`.
242+
> Support for Windows-style paths is tracked in [moby/buildkit#4696](https://github.com/moby/buildkit/issues/4696).
243+
244+
10. Build and push the image to a registry.
245+
246+
```console
247+
> docker buildx build --push -t <username>/hello-buildkit .
248+
```
249+
250+
11. After pushing to the registry, run the image with `docker run`.
251+
252+
```console
253+
> docker run <username>/hello-world
254+
```

0 commit comments

Comments
 (0)