Repository navigation
dockerfile: add --unset, FROM --reset and BUILDKIT_DISABLE_ONBUILD - #7344
Merged
Merged
Conversation
ARG and STOPSIGNAL never called flags.Parse(), so unknown flags were silently ignored. For example `ARG --unset FOO` declared FOO instead of failing. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Add llb.DelEnv and State.DelEnv for removing an environment variable from the state. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Allow removing environment variables, labels and volumes, including ones inherited from the base image. ENV --unset also removes a build argument with the same name from the stage. Available in the labs channel (dfunset build tag). Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Allow resetting configuration inherited from the base image with FROM --reset=<field>[,<field>...]. Fields are named after the instructions that set them: cmd, entrypoint, env, expose, healthcheck, label, onbuild, shell, stopsignal, user, volume and workdir. "all" resets all of them. Resetting onbuild skips the ONBUILD triggers of the base image. Available in the labs channel (dfreset build tag). Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Setting BUILDKIT_DISABLE_ONBUILD skips the ONBUILD triggers of all base images and stages. It can be passed as a build argument or set as a global ARG in the Dockerfile. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This was referenced Oct 30, 2026
Member
Author
crazy-max
reviewed
Nov 3, 2026
| } | ||
| if c.Unset { | ||
| for _, v := range c.Volumes { | ||
| v = path.Clean(v) |
Member
There was a problem hiding this comment.
Could we normalize these paths according to the target os before comparing them?
path.Clean only handles forward slashes, so on Windows, VOLUME --unset ["C:\\data"] doesn't remove an existing C:\data\ volume. Comparing C:\data with C:/data also fails.
crazy-max
reviewed
Nov 3, 2026
| | `BUILDKIT_BUILD_NAME` | String | Override the build name shown in [`buildx history` command](https://docs.docker.com/reference/cli/docker/buildx/history/) and [Docker Desktop Builds view](https://docs.docker.com/desktop/use-desktop/builds/). | | ||
| | `BUILDKIT_CACHE_MOUNT_NS` | String | Set optional cache ID namespace. | | ||
| | `BUILDKIT_CONTEXT_KEEP_GIT_DIR` | Bool | Trigger Git context to keep the `.git` directory. | | ||
| | `BUILDKIT_DISABLE_ONBUILD` | Bool | Skip the [`ONBUILD`](#onbuild) triggers of all base images and stages. This is not a security boundary: a custom frontend selected with `# syntax=` can ignore it. | |
Member
There was a problem hiding this comment.
Is making the ONBUILD switch available in stable immediately a requirement?
I was thinking we could generalize this to smth like BUILDKIT_DOCKERFILE_RESET=onbuild,expose, using the same fields and semantics as FROM --reset, but applying to every FROM? That would let us reuse the reset mechanism instead of introducing an ONBUILD-specific toggle.
crazy-max
approved these changes
Nov 4, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #4802
closes moby/moby#3465
Three separate changes to solve the cases for resetting properties inherited from base image and explicitly solve the issue for opting out of
ONBUILDbehavior that can cause base image modifications to change the build step definitions. If needed I can submit them separately.All Dockerfile changes are for the
labschannel, not immediately avaliable unless#syntax=docker/dockerfile:1-labsis used. They are under different names, so they can be promoted separately if needed. No Buildkit update is needed for this feature.ENV --unsetandLABEL --unsettake a list of names, so the parser now switches to name-list parsing for those two commands when the flag is set.ENV --unsetremoves the variable from both the image config and the build state, and it also drops a build arg with the same name from the stage. The newllb.DelEnvis there for removing it from the state.FROM --resettakes a list of config fields named after their instructions, orall. The reset is applied right after the stage inherits its base, before the base config is turned into build state, so it works the same for image and stage bases. Eg.FROM --reset=onbuilddisables onbuild rules from base image,--reset=volumeclears all volumes defined by base image.New global scope build arg
BUILDKIT_DISABLE_ONBUILDturns on that same skip for every stage. You can define default behavior in Dockerfile and user can always configure it with--build-arg.ARGandSTOPSIGNALnever parsed their flags, so unknown flags were silently ignored. They now return an error. This is a behavior change for Dockerfiles that have stray flags on those commands.Generated overview slides https://claude.ai/artifact/BFMoGCnWDN5S4g1bGBnmmC#1