summaryrefslogtreecommitdiff
path: root/api/server
diff options
context:
space:
mode:
authorNicolas De Loof <nicolas.deloof@gmail.com>2022-04-13 12:08:21 +0200
committerNicolas De Loof <nicolas.deloof@gmail.com>2022-05-19 16:43:06 +0200
commit304fbf080465e7097a6ab16b1f2a540d02bc7d75 (patch)
treed449c47679812f024a7ea6c2562079fe78551252 /api/server
parentc9d04033d443e359e73e5da58a6b46ec1b8f2373 (diff)
downloaddocker-304fbf080465e7097a6ab16b1f2a540d02bc7d75.tar.gz
introduce CreateMountpoint for parity between binds and mounts
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Diffstat (limited to 'api/server')
-rw-r--r--api/server/router/container/container_routes.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go
index db821942db..057a7b0b52 100644
--- a/api/server/router/container/container_routes.go
+++ b/api/server/router/container/container_routes.go
@@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
+ "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/versions"
containerpkg "github.com/docker/docker/container"
"github.com/docker/docker/errdefs"
@@ -513,9 +514,42 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
}
}
+ if hostConfig != nil && versions.LessThan(version, "1.42") {
+ for _, m := range hostConfig.Mounts {
+ // Ignore BindOptions.CreateMountpoint because it was added in API 1.42.
+ if bo := m.BindOptions; bo != nil {
+ bo.CreateMountpoint = false
+ }
+
+ // These combinations are invalid, but weren't validated in API < 1.42.
+ // We reset them here, so that validation doesn't produce an error.
+ if o := m.VolumeOptions; o != nil && m.Type != mount.TypeVolume {
+ m.VolumeOptions = nil
+ }
+ if o := m.TmpfsOptions; o != nil && m.Type != mount.TypeTmpfs {
+ m.TmpfsOptions = nil
+ }
+ if bo := m.BindOptions; bo != nil {
+ // Ignore BindOptions.CreateMountpoint because it was added in API 1.42.
+ bo.CreateMountpoint = false
+ }
+ }
+ }
+
if hostConfig != nil && versions.GreaterThanOrEqualTo(version, "1.42") {
// Ignore KernelMemory removed in API 1.42.
hostConfig.KernelMemory = 0
+ for _, m := range hostConfig.Mounts {
+ if o := m.VolumeOptions; o != nil && m.Type != mount.TypeVolume {
+ return errdefs.InvalidParameter(fmt.Errorf("VolumeOptions must not be specified on mount type %q", m.Type))
+ }
+ if o := m.BindOptions; o != nil && m.Type != mount.TypeBind {
+ return errdefs.InvalidParameter(fmt.Errorf("BindOptions must not be specified on mount type %q", m.Type))
+ }
+ if o := m.TmpfsOptions; o != nil && m.Type != mount.TypeTmpfs {
+ return errdefs.InvalidParameter(fmt.Errorf("TmpfsOptions must not be specified on mount type %q", m.Type))
+ }
+ }
}
if hostConfig != nil && runtime.GOOS == "linux" && versions.LessThan(version, "1.42") {