From bcc14559c989dc812afa867e806b318793e31653 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 29 Jan 2026 21:48:38 +0100 Subject: [PATCH] opts: MountOpt: relax client-side validation of mount target The daemon already validates the target, so we don't have to validate if a target is set. Instead, we can ignore empty targets, but produce an error if a target option was set, but set to an empty value. With this patch applied, omitting a target option is ignored by the CLI, but still invalidated by the daemon if the given mount-type requires a mount target; docker run --rm --mount type=bind,src=/var/run/docker.sock alpine docker: Error response from daemon: invalid mount config for type "bind": field Target must not be empty docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=../foo alpine docker: Error response from daemon: invalid mount config for type "bind": invalid mount path: '../foo' mount path must be absolute When passing a target option (`target`, `dst`, or `destination`), the CLI produces an error if the value is empty; docker run --rm --mount type=bind,src=/var/run/docker.sock,dst= alpine invalid argument "type=bind,src=/var/run/docker.sock,dst=" for "--mount" flag: invalid value for 'dst': mount target must be a non-empty value Signed-off-by: Sebastiaan van Stijn --- opts/mount.go | 4 ---- opts/mount_test.go | 15 --------------- 2 files changed, 19 deletions(-) diff --git a/opts/mount.go b/opts/mount.go index 682717f164df..a4b5744fee77 100644 --- a/opts/mount.go +++ b/opts/mount.go @@ -175,10 +175,6 @@ func (m *MountOpt) Set(value string) error { return errors.New("type is required") } - if mount.Target == "" { - return errors.New("target is required") - } - if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume { return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mount.Type) } diff --git a/opts/mount_test.go b/opts/mount_test.go index 96d1a7357942..cacba20b57df 100644 --- a/opts/mount_test.go +++ b/opts/mount_test.go @@ -113,21 +113,6 @@ func TestMountOptErrors(t *testing.T) { doc: "empty value", expErr: "value is empty", }, - { - doc: "missing tmpfs target", - value: "type=tmpfs", - expErr: "target is required", - }, - { - doc: "missing bind target", - value: "type=bind", - expErr: "target is required", - }, - { - doc: "missing volume target", - value: "type=volume,source=/foo", - expErr: "target is required", - }, { doc: "invalid key=value", value: "type=volume,target=/foo,bogus=foo",