Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-stage buildx build corrupts character special files #1027

Closed
JRaspass opened this issue Mar 26, 2022 · 2 comments
Closed

Multi-stage buildx build corrupts character special files #1027

JRaspass opened this issue Mar 26, 2022 · 2 comments

Comments

@JRaspass
Copy link

JRaspass commented Mar 26, 2022

Single-stage (works)

FROM alpine:3.15

RUN mknod -m 444 /my-urandom c 1 9

CMD ls -l /dev/urandom /my-urandom

docker build

$ docker build -t docker-bug . && docker run --rm docker-bug
...
crw-rw-rw-    1 root     root        1,   9 Mar 26 10:31 /dev/urandom
cr--r--r--    1 root     root        1,   9 Mar 26 10:24 /my-urandom

docker buildx

$ docker buildx build -t docker-bug . && docker run --rm docker-bug
...
crw-rw-rw-    1 root     root        1,   9 Mar 26 10:33 /dev/urandom
cr--r--r--    1 root     root        1,   9 Mar 26 10:24 /my-urandom

Multi-stage (builx doesn't work)

FROM alpine:3.15

RUN mknod -m 444 /my-urandom c 1 9

FROM scratch

COPY --from=0 / /

CMD ls -l /dev/urandom /my-urandom

docker build

$ docker build -t docker-bug . && docker run --rm docker-bug
...
crw-rw-rw-    1 root     root        1,   9 Mar 26 10:34 /dev/urandom
cr--r--r--    1 root     root        1,   9 Mar 26 10:24 /my-urandom

docker buildx (note the lack of c in /my-urandom)

$ docker buildx build -t docker-bug . && docker run --rm docker-bug
...
crw-rw-rw-    1 root     root        1,   9 Mar 26 10:35 /dev/urandom
-r--r--r--    1 root     root             0 Mar 26 10:24 /my-urandom

I noticed this when switching an application to buildx that specifically doesn't mount the hosts /dev and just populates what it needs (like /dev/urandom) and those reads were blocking indefinitely since buildx had made a zero byte regular file instead.

Now it may be that this isn't a bug and that character special files aren't supported but I would argue it's at least a little surprising when both legacy docker build and docker buildx with single-stage build both worked.

$ docker version
Client:
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.18
 Git commit:        a224086349
 Built:             Thu Mar 24 08:56:17 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18
  Git commit:       87a90dc786
  Built:            Thu Mar 24 08:56:03 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.2
  GitCommit:        de8046a5501db9e0e478e1c10cbcfb21af4c6b2d.m
 runc:
  Version:          1.1.0
  GitCommit:        v1.1.0-0-g067aaf85
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
$ docker buildx version
github.com/docker/buildx v0.8.1-docker 5fac64c2c49dae1320f2b51f1a899ca451935554
JRaspass added a commit to code-golf/code-golf that referenced this issue Mar 27, 2022
This moves the creation of /dev to runtime in run-lang.c, this is to
workaround github.com/docker/buildx/issues/1027.

This unblocks us moving to buildx/BuildKit in the near future.

It's not ideal but the cost to doing it at runtime is minimal.

As part of this every lang needed a rebuild some everything is now on
the latest Alpine and V naturally needed a bump to build.
@sprat
Copy link

sprat commented May 14, 2024

I am running buildx v0.12.0 and buildkit v0.12.5 and the problem seems to be solved now!

@JRaspass
Copy link
Author

This seems to be working fine now.

JRaspass added a commit to code-golf/code-golf that referenced this issue Aug 10, 2024
Now that docker/buildx#1027 is fixed we can
populate /dev at build-time rather than runtime.

This also seems to fix the Zig issue of needing a chown.
Yewzir pushed a commit to Yewzir/code-golf that referenced this issue Dec 14, 2024
Now that docker/buildx#1027 is fixed we can
populate /dev at build-time rather than runtime.

This also seems to fix the Zig issue of needing a chown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants