-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Buildkit does not allow ONBUILD RUN --mount... #959
Comments
@tonistiigi Do we plan to support this? |
@AkihiroSuda I think yes. Haven't checked what is the issue here. Ideally, we could also have something like ONBUILD++ where ONBUILD from any frontend could be used inside any other frontend but that's a bit more tricky and requires changing what is stored in the image config. Simple examples in #817 . |
Stumbled upon this today, my idea of onbuild run mount is like this
to make a simplified dockerfile that can be used with just
in each project, but it seems it doesnt support it ?
Version: |
Wanted to add that we are noticing the same as @fmiqbal with Docker version >=26.0.0. For example with this Dockerfile: FROM ubuntu:22.04 as base
ONBUILD RUN \
--mount=type=cache,target=/var/cache/apt \
apt-get update && apt-get install -y git
FROM base as test
WORKDIR /app
RUN echo "this is the stuff" > notes.txt
ENTRYPOINT [ "cat", "notes.txt" ]
$ docker build -t mytest --target test .
[+] Building 0.0s (2/2) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 280B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:22.04 0.0s
Dockerfile:7
--------------------
5 | apt-get update && apt-get install -y git
6 |
7 | >>> FROM base as test
8 |
9 | WORKDIR /app
--------------------
ERROR: failed to solve: cannot mount from stage "scratch" to "/var/cache/apt", stage needs to be defined before current command |
FYI this is still an issue with |
Maybe related to #4568 |
Problem
The buildkit does not allow mounting an image to an ONBUILD RUN command. When I mount an image in an ONBUILD RUN command, then use that as a base for another image, I get the following error:
=> ERROR [2/1] RUN --mount=type=bind,from=tomcat:latest,src=/usr/local/tomcat/BUILDING.txt,dst=/BUILDING.txt 0.2s ------ > [2/1] RUN --mount=type=bind,from=tomcat:latest,src=/usr/local/tomcat/BUILDING.txt,dst=/BUILDING.txt: #7 0.125 container_linux.go:344: starting container process caused "process_linux.go:424: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/docker/tmp/buildkit-mount356322217/usr/local/tomcat/BU ILDING.txt\\\" to rootfs \\\"/var/lib/docker/buildkit/executor/y76nt87kgf7bikqmd23wzq8ed/rootfs\\\" at \\\"/BUILDING.txt\\\" caused \\\"stat /var/lib/docker/tmp/buildkit-mount356322217/usr/local/tomcat/BUILDING .txt: no such file or directory\\\"\"" --------
Steps To Reproduce
I have a "base" dockerfile that looks like this:
Then I have a service dockerfile that looks like this:
Attempting to build this service image produces the above error.
Use Case
I am trying to create a base image for several services used by my company. That base image is supposed to contain all the building blocks needed to run the service, but should not actually build them (hence the use of the ONBUILD command). So we start with an operating system and layer in standard shared utilities and/or files. Each service uses this base image, then adds in only service-specific files.
The text was updated successfully, but these errors were encountered: