From df9344ac4ba8ba81366e557ff3937a3d861dede1 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 4 May 2023 11:57:02 +0200 Subject: [PATCH] compat container create: match duplicate mounts correctly The logic which checks for duplicated volumes here did not work correctly because it used filepath.Clean(). However the writes to the volDestinations map did not thus the string no longer matched when you included a final slash for example. So we can either call Clean() on all or no paths. I decided to call it on no path because this is what we do right now. Just the check did it. Fixed #18454 Signed-off-by: Paul Holzinger --- pkg/api/handlers/compat/containers_create.go | 2 +- test/apiv2/20-containers.at | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index 811305341c..03acff66e4 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -483,7 +483,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C // 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 { + if _, ok := volDestinations[vol]; ok { continue } cliOpts.Volume = append(cliOpts.Volume, vol) diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 7cfe161de4..7840ea5242 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -357,6 +357,15 @@ t GET containers/$cid/json 200 \ t DELETE containers/$cid?v=true 204 +# Test Volumes with bind mount, for some reason docker-py sets this #18454 +t POST containers/create Image=$IMAGE Volumes='{"/test/":{}}' HostConfig='{"Binds":["/tmp:/test/:ro"]}' 201 \ + .Id~[0-9a-f]\\{64\\} +cid=$(jq -r '.Id' <<<"$output") +t GET containers/$cid/json 200 \ + .Mounts[0].Destination="/test/" + +t DELETE containers/$cid?v=true 204 + # test port mapping podman run -d --rm --name bar -p 8080:9090 $IMAGE top