diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index 0e2f4c912d..3a0fb8959c 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -255,6 +255,9 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C addField(&builder, "tmpfs-mode", strconv.FormatUint(uint64(m.TmpfsOptions.Mode), 8)) } case mount.TypeVolume: + if m.VolumeOptions != nil { + addField(&builder, "subpath", m.VolumeOptions.Subpath) + } // All current VolumeOpts are handled above // See vendor/github.com/containers/common/pkg/parse/parse.go:ValidateVolumeOpts() } diff --git a/test/apiv2/44-mounts.at b/test/apiv2/44-mounts.at index a2efb935cb..2e5a4cd369 100644 --- a/test/apiv2/44-mounts.at +++ b/test/apiv2/44-mounts.at @@ -37,3 +37,24 @@ t POST libpod/containers/create \ 500 \ .cause="invalid mount option" \ .message~"the 'noatime' option is only allowed with tmpfs mounts" + +# Compat API: HostConfig.Mounts.VolumeOptions.Subpath mounts only the selected volume subdirectory +subpath_vol="apiv2-subpath-vol" +podman volume create "$subpath_vol" +podman run --rm -v "$subpath_vol":/mnt "$IMAGE" sh -c "mkdir -p /mnt/test1 /mnt/test2; touch /mnt/test1/hello1; touch /mnt/test2/hello2" + +t POST containers/create?name=compat_mount_subpath_test \ + Image=$IMAGE \ + Cmd='["ls","-1","/test1"]' \ + HostConfig='{"Mounts":[{"Type":"volume","Source":"'$subpath_vol'","Target":"/test1","VolumeOptions":{"Subpath":"test1"}}]}' \ + 201 \ + .Id~[0-9a-f]\\{64\\} +cid=$(jq -r '.Id' <<<"$output") + +t POST containers/${cid}/start 204 +t POST containers/${cid}/wait 200 +t GET containers/${cid}/logs?stdout=true 200 +like "$(tr -d \\0 <$WORKDIR/curl.result.out)" ".*hello1$" "compat mount subpath returns only selected subdir" + +t DELETE containers/${cid}?v=true 204 +podman volume rm "$subpath_vol"