diff options
author | Matthew Heon <mheon@redhat.com> | 2022-03-17 10:40:55 -0400 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2022-03-17 10:45:08 -0400 |
commit | 0793a58343a49b2ed30d3da2d10dd5f14cc13f1a (patch) | |
tree | be0beec90630c74b3e29411451b66ec8c56962c8 /cmd | |
parent | ecd2746ce36db6ebe5d99b26045f197cb136cd61 (diff) | |
download | podman-0793a58343a49b2ed30d3da2d10dd5f14cc13f1a.tar.gz podman-0793a58343a49b2ed30d3da2d10dd5f14cc13f1a.tar.bz2 podman-0793a58343a49b2ed30d3da2d10dd5f14cc13f1a.zip |
Deduplicate between Volumes and Mounts in compat API
Docker Compose v2.0 passes mount specifications in two different
places: Volumes (just the destination) and Mounts (full info
provided - source, destination, etc). This was causing Podman to
refuse to create containers, as the destination was used twice.
Deduplicate between Mounts and Volumes, preferring volumes, to
resolve this.
Fixes #11822
Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/common/create_opts.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index b110b3d85..e5a2a0da3 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -97,12 +97,21 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c } // mounts type=tmpfs/bind,source=...,target=...=,opt=val + volSources := make(map[string]bool) + volDestinations := make(map[string]bool) mounts := make([]string, 0, len(cc.HostConfig.Mounts)) var builder strings.Builder for _, m := range cc.HostConfig.Mounts { addField(&builder, "type", string(m.Type)) addField(&builder, "source", m.Source) addField(&builder, "target", m.Target) + + // Store source/dest so we don't add duplicates if a volume is + // also mentioned in cc.Volumes. + // Which Docker Compose v2.0 does, for unclear reasons... + volSources[m.Source] = true + volDestinations[m.Target] = true + if m.ReadOnly { addField(&builder, "ro", "true") } @@ -328,8 +337,6 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c } // volumes - volSources := make(map[string]bool) - volDestinations := make(map[string]bool) for _, vol := range cc.HostConfig.Binds { cliOpts.Volume = append(cliOpts.Volume, vol) // Extract the destination so we don't add duplicate mounts in @@ -348,6 +355,8 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c // format of `-v` so we can just append them in there. // Unfortunately, these may be duplicates of existing mounts in Binds. // So... We need to catch that. + // This also handles volumes duplicated between cc.HostConfig.Mounts and + // cc.Volumes, as seen in compose v2.0. for vol := range cc.Volumes { if _, ok := volDestinations[filepath.Clean(vol)]; ok { continue |