mirror of
https://github.com/containers/podman.git
synced 2025-06-18 15:39:08 +08:00
Merge pull request #9025 from mheon/add_support_volumes_field
Ensure the Volumes field in Compat Create is honored
This commit is contained in:
@ -3,6 +3,7 @@ package common
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -383,8 +384,29 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
|
|||||||
}
|
}
|
||||||
|
|
||||||
// volumes
|
// volumes
|
||||||
if volumes := cc.HostConfig.Binds; len(volumes) > 0 {
|
volDestinations := make(map[string]bool)
|
||||||
cliOpts.Volume = volumes
|
for _, vol := range cc.HostConfig.Binds {
|
||||||
|
cliOpts.Volume = append(cliOpts.Volume, vol)
|
||||||
|
// Extract the destination so we don't add duplicate mounts in
|
||||||
|
// the volumes phase.
|
||||||
|
splitVol := strings.SplitN(vol, ":", 3)
|
||||||
|
switch len(splitVol) {
|
||||||
|
case 1:
|
||||||
|
volDestinations[vol] = true
|
||||||
|
default:
|
||||||
|
volDestinations[splitVol[1]] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Anonymous volumes are added differently from other volumes, in their
|
||||||
|
// own special field, for reasons known only to Docker. Still use the
|
||||||
|
// 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.
|
||||||
|
for vol := range cc.Volumes {
|
||||||
|
if _, ok := volDestinations[filepath.Clean(vol)]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cliOpts.Volume = append(cliOpts.Volume, vol)
|
||||||
}
|
}
|
||||||
if len(cc.HostConfig.BlkioWeightDevice) > 0 {
|
if len(cc.HostConfig.BlkioWeightDevice) > 0 {
|
||||||
devices := make([]string, 0, len(cc.HostConfig.BlkioWeightDevice))
|
devices := make([]string, 0, len(cc.HostConfig.BlkioWeightDevice))
|
||||||
|
@ -237,3 +237,12 @@ t GET containers/$cid/json 200 \
|
|||||||
t DELETE containers/$cid 204
|
t DELETE containers/$cid 204
|
||||||
t DELETE images/${MultiTagName}?force=true 200
|
t DELETE images/${MultiTagName}?force=true 200
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
|
||||||
|
# Test Volumes field adds an anonymous volume
|
||||||
|
t POST containers/create '"Image":"'$IMAGE'","Volumes":{"/test":{}}' 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
|
||||||
|
Reference in New Issue
Block a user