-
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
ONBUILD executed in multi-stage build grandchild #5578
Comments
I'm also seeing a similar issue with https://github.com/Tecnativa/doodba where |
I added a simpler reproduction to https://github.com/MikeMcC399/cy-docker-multistage which does not rely on git clone https://github.com/MikeMcC399/cy-docker-multistage
cd cy-docker-multistage
docker build . -f Dockerfile.parent -t parent --no-cache
docker build . -f Dockerfile.child-grandchild -t child-grandchild --no-cache
# syntax=docker/dockerfile:1
FROM debian:12-slim AS parent
RUN echo "parent"
ONBUILD RUN echo "parent to child" Build Docker image
# syntax=docker/dockerfile:1
FROM parent AS child
RUN echo "child"
FROM child AS grandchild
RUN echo "grandchild" Build Docker image
The following log line from above should not appear. This
|
My current "simple" reproduction is: FROM ubuntu AS onbuild
RUN touch /history.txt
ONBUILD ARG also_used_later=""
ONBUILD RUN echo "$(date) onbuild also_used_later: $also_used_later" >> /history.txt
ONBUILD RUN dd if=/dev/random count=$((1024*2)) > /random.bin
ONBUILD RUN sha256sum /random.bin >> /history.txt
ONBUILD ARG build_date
ONBUILD LABEL my_label=$build_date
# with clean build caches (docker system prune)
docker build -f Dockerfile.onbuild -t onbuild_image .
docker build -f Dockerfile.use_onbuild --build-arg BASE_IMAGE=onbuild_image .
docker build -f Dockerfile.use_onbuild --build-arg BASE_IMAGE=onbuild_image --build-arg "also_used_later=true" . When runnning with
When running with
for us it does not depend on the dockerfile syntax, but we discovered it when updating our build servers one by one from:
to
So i'm not sure if it is the same issue or just a similar one. Edit: also the following actions change the result to be equivalent in buildkit and non buildkit builds:
|
@ap-wtioit This probably broke with #5490 . As a workaround you can pin to 1.10 as previous comment suggests. |
Observed Behavior
If a
docker build
is executed using the Docker image cypress/factory in a two-stageDockerfile
build, with the recommended# syntax=docker/dockerfile:1
from Custom Dockerfile syntax then the
ONBUILD RUN
instructions fromcypress/factory
are executed correctly in the first build stage, and fail in the second build stage. TheONBUILD
instructions can only be executed once, since they clean up after themselves and they delete resources which are no longer supposed to be necessary.cypress/factory is built with factory/factory.Dockerfile and this includes:
This is a regression in
docker/dockerfile:1.11.0
and above:docker/dockerfile
version1
1.10.0
1.11.0
1.11.1
1.12.0
Expected Behavior
The set of
ONBUILD
instructions from an existing Docker file should only be used in the first stage of a multi-stage build, not in the second or any following stages.Steps to reproduce
See https://github.com/MikeMcC399/cy-docker-multistage
On Ubuntu
24.04.1
LTS, Node.jsv22.12.0
LTS, Docker Desktop 4.36.0using
Dockerfile.1
:Logs
Workaround
Pin syntax to
1.10.0
inDockerfile.1.10.0
:# syntax=docker/dockerfile:1.10.0
To test workaround, as above, except:
Reference
Dockerfile ONBUILD
The text was updated successfully, but these errors were encountered: