buildx: Docker buildkit fails to build .net project in contrary to successful builds on depracted builder

Description

I found that when you have more than one dotnet publish in dockerfile, the docker build with buildkit fails with some strange, nondescriptive error: ERROR: failed to solve: failed to prepare 6boxvrjdjur378egamsa297vp as lnddt61dq57lwjio5fkmhme9e: invalid argument. When there is only one dotnet publish line, it works with buildkit.

This failing behavior does not exists when i turn off buildkit via DOCKER_BUILDKIT=0 docker build. It successfully builds image, despite having more than one dotnet publish command.

I attached minimal repro repository, and repro steps. Hope we can clarify of what is going on here.

Reproduce

  1. Download minimal repro repository https://github.com/incloudss/testbuildkit
  2. Go to testbuildkit directory and run docker build .
  3. The build fails.
  4. Run once again build, now with DOCKER_BUILDKIT=0 docker build ..
  5. Build succeeds.

Expected behavior

No response

docker version

Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:35:35 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.5
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.6
  Git commit:       a61e2b4
  Built:            Fri Jul 21 20:35:35 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    24.0.5
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.20.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 24.0.5
 Storage Driver: vfs
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8165feabfdfe38c65b599c4993d227328c231fca
 runc version: v1.1.8-0-g82f18fe
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.4.225-200.el7.x86_64
 Operating System: Debian GNU/Linux 12 (bookworm) (containerized)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 31.36GiB
 Name: connect-build-agent-karas-5d84b54566-hkz8d
 ID: d76c3467-6972-423b-8208-7a5f12201c2b
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 29 (7 by maintainers)

Most upvoted comments

(somewhat catching up on this thread); thanks for correlating this with the casefold option!

So (at least in my case) it looks like vfs was the culprit, which got automatically enabled instead of overlay2 due to the underlying ext4 filesystem having the casefold option, which the overlay kernel module is incompatible with. vfs in turn seems to expose a bug in buildx.

The vfs driver is basically a “last resort” (if all else fails); it’s implemented by creating a copy of all files in the image in a directory, then creating a copy of all file for every layer produced. So with the vfs there’s no additional filesystem-type (like overlayFS) involved, and file-operations happen directly on the host’s filesystem.

Overall, it would not surprise me if things would randomly fail on a case-insensitive filesystem; at least I’m aware of some tools/software using case-sensitive paths for caches, resulting in cache-collisions (cache files overwriting existing cache-files). So, even if things work in docker / buildkit itself, could still result in failures due to software running inside the container assuming a case-sensitive filesystem.

Not sure what difference would be between the classic builder and buildkit for this situation though 🤔

I wonder if (perhaps) BuildKit produces a case-sensitive (temp) paths for intermediate steps and those resulting in a similar collision; it likely hits a different code-path (BuildKit itself acts as a runtime for containers executed during build, and directly controls the OCI runtime, so it may / will hit different code-paths as the classic builder, which runs containers through the docker daemon).

There’s also a possibility that the classic builder was hiding some underlying failures; the vfs driver (as mentioned) is used as a last-resort, there’s historically been some changes to make it slightly more permissive on failures; older versions of docker did so for (extended attributes) unconditionally; https://github.com/moby/moby/blob/v23.0.0/pkg/archive/archive.go#L791-L803

And current versions have this configurable (as silently discarding extended attributes could discard attributes relevant to the container, resulting in different results for some cases) https://github.com/moby/moby/blob/v27.4.1/pkg/archive/archive.go#L788-L803

I wonder if (e.g.) one of those or perhaps some other code-path would be ignoring errors when using vfs, potentially hiding errors related to failures due to the case-insensitive filesystem used.

I wonder if Storage Driver: vfs is related to your issue.

I would definitely NOT recommend using the vfs storage driver for any other purpose than debugging. The vfs storage driver creates a full copy of the image for every layer that’s created, and for every container that’s run (which is both very slow, and may cause a lot of disk space to be used).

There have been some cases where vfs may not be able to write extended attributes (see https://github.com/moby/moby/issues/45535, https://github.com/moby/moby/issues/45417), and older version of docker were silently discarding those errors; docker 25.0 will produce an error in this conditions (added in https://github.com/moby/moby/pull/45464), but other version may either discard that error (or perhaps BuildKit may not).

I have the same error but only in CI where I’m using DinD. It never throws when I build locally.

I don’t have multiple publish commands but I the error occurs if I have multiple run statements that call dotnet.

I’m using the latest version of docker (24.0.6)

Docker throws an error with this file

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /source

# Copy everything
COPY src/Project .

# Restore as distinct layers
RUN dotnet restore

# Build and publish a release
RUN dotnet publish ./Project.csproj -c Release --no-restore -o /app

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build-env /app .
EXPOSE 80
ENTRYPOINT ["./Project"]

But this file works without any issues

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /source

# Copy everything
COPY src/Project .

# Build and publish a release
RUN dotnet publish ./Project.csproj -c Release -o /app

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build-env /app .
EXPOSE 80
ENTRYPOINT ["./Project"]