mirror of
https://github.com/docker/cli.git
synced 2026-08-24 10:05:37 -05:00
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>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user