Skip to content

Commit bcc1455

Browse files
committed
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 <github@gone.nl>
1 parent ffd9b40 commit bcc1455

File tree

2 files changed

+0
-19
lines changed

2 files changed

+0
-19
lines changed

opts/mount.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ func (m *MountOpt) Set(value string) error {
175175
return errors.New("type is required")
176176
}
177177

178-
if mount.Target == "" {
179-
return errors.New("target is required")
180-
}
181-
182178
if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume {
183179
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mount.Type)
184180
}

opts/mount_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,6 @@ func TestMountOptErrors(t *testing.T) {
113113
doc: "empty value",
114114
expErr: "value is empty",
115115
},
116-
{
117-
doc: "missing tmpfs target",
118-
value: "type=tmpfs",
119-
expErr: "target is required",
120-
},
121-
{
122-
doc: "missing bind target",
123-
value: "type=bind",
124-
expErr: "target is required",
125-
},
126-
{
127-
doc: "missing volume target",
128-
value: "type=volume,source=/foo",
129-
expErr: "target is required",
130-
},
131116
{
132117
doc: "invalid key=value",
133118
value: "type=volume,target=/foo,bogus=foo",

0 commit comments

Comments
 (0)