-
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
bug: buildkit does not consider ONBUILD COPY --from #816
Comments
This is a very weird (and inventive) way to use
No, we don't want to add any special behavior for this. Either we consider this as bug and just fix the image resolution or we document that this is invalid usage (and make it error with a proper message). A problem with implementing this is that we can't start to process all stages in parallel like we do now because we only know about the dependant images after we have pulled the config of the base. Still doable, just adds complexity. Once we have determined the correct dependencies of the stages it would build in regular concurrent manner. @AkihiroSuda @tiborvass @ijc @thaJeztah get your votes in |
IIRC ONBUILD was deprecated and unrecommended? |
It's not deprecated, but I think the official images stopped creating So, IIUC, in buildkit the problem is that the stages are executed in parallel, thus (e.g.) FROM foo AS ubuntu
FROM something:onbuild AS final Where ONBUILD COPY --from=ubuntu /foo /foo Could either result in the |
Well, this is not my invention, https://engineering.busbud.com/2017/05/21/going-further-docker-multi-stage-builds/ - this is one of the first google search results. So I don't think I'm alone here.
Maybe this is confusing for official images, but for multistage internal images designed for that purpose - ONBUILD is a revelation... Down the link above is a nice solution to the problem: if we could use something like: ONBUILD FROM runtime:v1 we won't need this strange hack. |
Quote from https://engineering.busbud.com/2017/05/21/going-further-docker-multi-stage-builds/:
As the author of the multi-stage PR I can confirm I was not clever enough to see it as a possible feature. |
Just chiming in here - we do the same as @astorath at our company. It's been a godsend for enabling extremely efficient / modular builds and dockerfiles For context: We discovered this issue after trying to use (new) build secrets (with buildkit) |
Same problem here. I cannot reference another stage, or even another image, with ONBUILD COPY --from :( |
You can if you add a dummy |
I know this trick to force some intermediate stages to build in "weird cases", but I don't see how it is related to the problem here. |
It even does not work with a external image. Minimum example to reproduce : template/Dockerfile
project/Dockerfile
build.sh
@sirlatrom maybe i didn't get your trick ? do you see a solution here ? |
The "trick" is to add a step in the bug image that copies a known-to-exist file from the composer image. That could also be done by creating a prior stage (from the composer image) in the bug image that adds such a dummy file so you can control which it is. |
Ok, let's try it : template/Dockerfile
Same error. |
I meant the new copy instruction should be placed in the last, most downstream image |
Could you provide a working fix based on my minimal example ? |
Note that the use of images instead of stage names in ./template/Dockerfile: FROM php:7.4.2-fpm-buster
ONBUILD COPY --from=template /usr/bin/composer /usr/bin/composer ./project/Dockerfile: FROM composer:1.9.2 AS template
RUN ["touch", "/tmp/dummy"]
FROM bug_template
COPY --from=template /tmp/dummy /tmp/dummy DOCKER_BUILDKIT=1 docker build ./template --tag bug_template
DOCKER_BUILDKIT=1 docker build ./project |
Same error @astorath |
Facing the same issue as what @astorath described - we have an |
Hey folks 👋 Docker Desktop 2.4.0.0 enables BuildKit by default now, which will potentially break any
|
I ran in to this problem and stumbled upon this issue. What is needed to move this fix forward? |
Here is the switch Just set environment arg |
@softworm This does not solve the problem. Turning off BuiltKit means you cannot use the secrets mechanism, which is the only decent approach for passing secrets into a build. |
So this is a bug right?
and then a multi-stage build, however if I change the contents of the Gemfile, it won't pick it up
I can confirm that running a build with buildkit off, it works and will pick up the changes |
It also looks like someone else is having this problem https://stackoverflow.com/questions/66952378/docker-multistage-onbuild-not-executing-first-stage-onbuild-commands |
Just for the sake of adding another usage example of this (now missing) feature: This project started internally 3 years ago. Many of us are still not using buildkit. What is also clearly odd for someone using the docker compose plugin is that these errors start popping between versions 2.3.3 and 2.3.4 of the plugin. |
I've marked this with "help wanted" label but if you are planning to take this on please do verify the design here first(also look at #816 (comment)). |
Thanks @tonistiigi for the input 👍. Just looking back at your latest comment, it feels like a link is missing:
Did you intend to point to some particular documentation on the "here first" or did you just intend to point to the buildkit documentation? I have also read again your proposals to resolve the issue, the second option (support by the dockerfile frontend for the async llb graph generation) seems in fact sexier. |
Hi, so there going to be some fix or you're just breaking backward compatibility by literally saying "you always do it wrong way, our way is better! Just do refactoring of all your dockerfiles and ci/cd"? ) |
This ^ (I would have simply left a "this" emoji reaction but there is none.) |
For anyone that loves to work on this issue, I've included steps to reproduce the issue in moby/moby#42845 and kept those as simple as possible. |
Any update on that? Would love to use it. The 3 alternatives listed above are not the best options. |
Ditto, when is this getting fixed? |
Seeing as how this issue is related to concurrent builds of images I saw that we can create a builder with a config file that sets the
but it seems like it's not working since the build failure is still persisting. Another thing I've noticed is if we take this simple example from here: #816 (comment) and I changed the the order of the imports from:
to
The build now passes. Seems like the builds start from the bottom? Also, this issue is also blocking my org as we rely on |
@ericqt how about |
@chloe-zen I tried that as well and no go :( |
Any update? As we now see:
This will kill all our builds. |
any update? same issue on multi-stage |
I ran into this issue and decided to think about it as a dependency management issue rather than a bug. Consider this code: Base image Dockerfile, tagged as base:latest: FROM alpine:latest
WORKDIR /foo
ONBUILD COPY bar.txt .
ONBUILD RUN cat bar.txt Application Dockerfile: # Stage 1
FROM base:latest AS me
# Stage 2
FROM alpine:latest
COPY --from me /foo/bar.txt /hello/bar.txt
RUN cat /hello/bar.txt This example will likely fail with buildkit since the Base image Dockerfile, built as base:latest: FROM alpine:latest
WORKDIR /foo Application Dockerfile: # Stage 1
FROM base:latest AS me
COPY bar.txt .
RUN cat bar.txt
# Stage 2
FROM alpine:latest
COPY --from me bar.txt /hello/bar.txt
RUN cat /hello/bar.txt The secret is to ensure that any instructions in application stage one that are depended on by stage two are defined in the application Dockerfile rather than the base image Dockerfile. Any This is obviously a very cut down example and is not very useful, but in the real-world project I am currently working on, the method of the solution was identical and means I am able to achieve the same original intent, with minor changes to code. Yes, it means the |
I just encountered this bug when trying to set up a multi-stage build with an early "builder" stage that uses a FROM image with ONBUILD to create an installer, and then a final stage that uses a FROM image with ONBUILD instructions to copy the installer from the builder and do the steps needed to install it. This involves quite a bit of duplicated instructions repeated across Dockerfiles in 50+ repositories, unlike the previous commenter who only has 2 fairly short lines that get duplicated. From the docs (https://docs.docker.com/reference/dockerfile/#onbuild), |
This has been implemented in #5357 . You can test with |
Hi, we make heavy use of ONBUILD option in our environment.
Our typical Dockerfile looks like this:
This works fine in legacy docker build, but turning on BUILDKIT option activates some optimizations, so docker tries to build these containers in parallel. The problem is containers are dependent:
my.company.com/ci/dotnet:v1-build:
my.company.com/ci/dotnet:v1-runtime:
Running
DOCKER_BUILDKIT=1 docker build .
results in:My questions are:
The text was updated successfully, but these errors were encountered: