mirror of
https://github.com/containers/podman.git
synced 2025-06-29 15:08:09 +08:00
Respect user-added mounts over default spec mounts
When there was a conflict between a user-added volume and a mount already in the spec, we previously respected the mount already in the spec and discarded the user-added mount. This is counter to expected behavior - if I volume-mount /dev into the container, I epxect it will override the default /dev in the container, and not be ignored. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #1419 Approved by: TomSweeneyRedHat
This commit is contained in:
@ -160,9 +160,6 @@ func (c *CreateConfig) GetVolumeMounts(specMounts []spec.Mount) ([]spec.Mount, e
|
|||||||
if len(spliti) > 2 {
|
if len(spliti) > 2 {
|
||||||
options = strings.Split(spliti[2], ",")
|
options = strings.Split(spliti[2], ",")
|
||||||
}
|
}
|
||||||
if libpod.MountExists(specMounts, spliti[1]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
options = append(options, "rbind")
|
options = append(options, "rbind")
|
||||||
for _, opt := range options {
|
for _, opt := range options {
|
||||||
switch opt {
|
switch opt {
|
||||||
@ -201,6 +198,8 @@ func (c *CreateConfig) GetVolumeMounts(specMounts []spec.Mount) ([]spec.Mount, e
|
|||||||
Source: spliti[0],
|
Source: spliti[0],
|
||||||
Options: options,
|
Options: options,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
logrus.Debugf("User mount %s:%s options %v", spliti[0], spliti[1], options)
|
||||||
}
|
}
|
||||||
|
|
||||||
// volumes from image config
|
// volumes from image config
|
||||||
|
@ -2,6 +2,7 @@ package createconfig
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
@ -310,18 +311,21 @@ func CreateConfigToOCISpec(config *CreateConfig) (*spec.Spec, error) { //nolint
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error getting volume mounts")
|
return nil, errors.Wrapf(err, "error getting volume mounts")
|
||||||
}
|
}
|
||||||
// If we have overlappings mounts, remove them from the spec in favor of
|
if len(mounts) > 0 {
|
||||||
// the user-added volume mounts
|
// If we have overlappings mounts, remove them from the spec in favor of
|
||||||
destinations := make(map[string]bool)
|
// the user-added volume mounts
|
||||||
for _, mount := range mounts {
|
destinations := make(map[string]bool)
|
||||||
destinations[mount.Destination] = true
|
for _, mount := range mounts {
|
||||||
}
|
destinations[path.Clean(mount.Destination)] = true
|
||||||
for _, mount := range configSpec.Mounts {
|
|
||||||
if _, ok := destinations[mount.Destination]; !ok {
|
|
||||||
mounts = append(mounts, mount)
|
|
||||||
}
|
}
|
||||||
|
for _, mount := range configSpec.Mounts {
|
||||||
|
if _, ok := destinations[path.Clean(mount.Destination)]; !ok {
|
||||||
|
logrus.Debugf("Adding mount %s", mount.Destination)
|
||||||
|
mounts = append(mounts, mount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configSpec.Mounts = mounts
|
||||||
}
|
}
|
||||||
configSpec.Mounts = mounts
|
|
||||||
|
|
||||||
if err := g.SetLinuxRootPropagation("shared"); err != nil {
|
if err := g.SetLinuxRootPropagation("shared"); err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to set propagation to rslave")
|
return nil, errors.Wrapf(err, "failed to set propagation to rslave")
|
||||||
|
Reference in New Issue
Block a user