Windows: Build images with windows-host-process-containers-base-image fails with Cannot create a file when that file already exists. (0xb7): unknown

Open
#5,196 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
docker, github-actions, go

Research direction

Start by reproducing the GitHub Actions workflow with containerd 1.7.20, BuildKit v0.15.0, and the remote buildx driver. Trace the export failure at hcsshim::ImportLayer during snapshot finalization, using the Dockerfile and reported 0xb7 error as the test case. Done means the host-process base image builds and exports without the duplicate-file error.

Written by the indexing model from the issue text.

Description

area/github-actions area/windows

I tried to build a https://github.com/microsoft/windows-host-process-containers-base-image/ which is considered as special.

windows-host-process-containers-base-image is a very special image, because its hand-crafted image.

I'm using Github Actions to build an images on top of windows-host-process-containers-base-image

Here are the actions I'm using:

      - name: Setup containerd
        run: |
          $version = "1.7.20"
          curl.exe -L https://github.com/containerd/containerd/releases/download/v$version/containerd-$version-windows-amd64.tar.gz -o containerd.tar.gz
          tar.exe xvf containerd.tar.gz
          .\bin\containerd.exe --register-service
          Start-Service containerd
      - name: Setup BuildKit
        run: |
          $version = "v0.15.0"
          curl.exe -L https://github.com/moby/buildkit/releases/download/$version/buildkit-$version.windows-amd64.tar.gz -o buildkit.tar.gz
          tar.exe xvf buildkit.tar.gz
          
          .\bin\buildkitd.exe --register-service
          Start-Service buildkitd
      - name: Setup Docker Buildx
        run: |
          $version = "v0.16.1"
          curl.exe -L https://github.com/docker/buildx/releases/download/$version/buildx-$version.windows-amd64.exe -o $env:ProgramData\Docker\cli-plugins\docker-buildx.exe
      - uses: docker/setup-buildx-action@v3
        with:
          driver: remote
          endpoint: npipe:////./pipe/buildkitd

While build looks fine, exporting the images causes unknown errors:

docker buildx build --push --build-arg=BASE=mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 -f Dockerfile -t ghcr.io/prometheus-community/windows-exporter:master-hostprocess .
#0 building with "builder-e1408480-a0f9-48a2-aa8d-31bc0261d2ff" instance using remote driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 490B done
#1 DONE 0.0s

#2 [internal] load metadata for mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0
#2 DONE 0.1s

#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [internal] load build context
#4 transferring context: 115B done
#4 DONE 0.0s

#5 [1/2] FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0@sha256:b4c9637e032f667c52d1eccfa31ad8c63f1b035e8639f3f48a510536bf34032b
#5 resolve mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0@sha256:b4c9637e032f667c52d1eccfa31ad8c63f1b035e8639f3f48a510536bf34032b
#5 resolve mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0@sha256:b4c9637e032f667c52d1eccfa31ad8c63f1b035e8639f3f48a510536bf34032b 0.1s done
#5 DONE 0.1s

#6 [2/2] COPY output/amd64/windows_exporter.exe /windows_exporter.exe
#6 CACHED

#7 exporting to image
#7 exporting layers
#7 exporting layers 0.2s done
#7 ERROR: failed to commit 5am92igktp6scjpj0kc7ejaj3 to oumlt8yasx34v7sb7a31zzo9f during finalize: failed to reimport snapshot: hcsshim::ImportLayer failed in Win32: Cannot create a file when that file already exists. (0xb7): unknown
------
 > exporting to image:
------
ERROR: failed to solve: failed to commit 5am92igktp6scjpj0kc7ejaj3 to oumlt8yasx34v7sb7a31zzo9f during finalize: failed to reimport snapshot: hcsshim::ImportLayer failed in Win32: Cannot create a file when that file already exists. (0xb7): unknown

Dockerfile, mention that BASE will be overwrite by --build-arg:

ARG BASE="mcr.microsoft.com/windows/nanoserver:ltsc2022"
FROM $BASE

ENV PATH="C:\Windows\system32;C:\Windows;"
COPY output/amd64/windows_exporter.exe /windows_exporter.exe
ENTRYPOINT ["windows_exporter.exe"]

Ref: https://github.com/prometheus-community/windows_exporter/actions/runs/10078511673/job/27863581327#step:17:266

Dominant language
Go
Stars
10.3k
Forks
1.5k
Avg merge
1d 23h
Merged PRs (30d)
48

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from moby/buildkit

All issues in moby/buildkit

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.