Skip to content

dockerfile: add --unset, FROM --reset and BUILDKIT_DISABLE_ONBUILD - #7344

Merged
tonistiigi merged 5 commits into
moby:masterfrom
tonistiigi:dockerfile-reset
Nov 4, 2026
Merged

tonistiigi merged 5 commits into
moby:masterfrom
tonistiigi:dockerfile-reset

Conversation

@tonistiigi

@tonistiigi tonistiigi commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

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 ONBUILD behavior 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 labs channel, not immediately avaliable unless #syntax=docker/dockerfile:1-labs is used. They are under different names, so they can be promoted separately if needed. No Buildkit update is needed for this feature.

ENV --unset and LABEL --unset take a list of names, so the parser now switches to name-list parsing for those two commands when the flag is set. ENV --unset removes 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 new llb.DelEnv is there for removing it from the state.

FROM --reset takes a list of config fields named after their instructions, or all. 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=onbuild disables onbuild rules from base image, --reset=volume clears all volumes defined by base image.

New global scope build arg BUILDKIT_DISABLE_ONBUILD turns on that same skip for every stage. You can define default behavior in Dockerfile and user can always configure it with --build-arg.

ARG and STOPSIGNAL never 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

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>
@tonistiigi

Copy link
Copy Markdown
Member Author

cc @crazy-max @AkihiroSuda @tianon

}
if c.Unset {
for _, v := range c.Volumes {
v = path.Clean(v)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

| `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. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tonistiigi
tonistiigi merged commit 30785d7 into moby:master Nov 4, 2026
214 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an UNVOLUME or UNSET VOLUME statement to cancaled mount the default parent volume Reset properties inherited from parent image

2 participants