summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2021-03-03 15:30:52 -0500
committerMatthew Heon <matthew.heon@pm.me>2021-03-03 16:22:31 -0500
commit53d22c779c5d2df5ccda5a8e23db0501a0dadf44 (patch)
treece1e78c2b9e342ecaba790cba6eff7c3f6e1fa1e /cmd/podman/common
parent87e20560ac885c541784af1341098ce8e1e7a940 (diff)
downloadpodman-53d22c779c5d2df5ccda5a8e23db0501a0dadf44.tar.gz
podman-53d22c779c5d2df5ccda5a8e23db0501a0dadf44.tar.bz2
podman-53d22c779c5d2df5ccda5a8e23db0501a0dadf44.zip
Compat API: create volume source dirs on the host
It took a lot to figure out exactly how this should work, but I think I finally have it. My initial versions of this created the directory with the same owner as the user the container was run with, which was rather complicated - but after review against Docker, I have determined that is incorrect, and it's always made as root:root 0755 (Ubuntu's Docker, which I was using to try and test, is a snap - and as such it was sandboxed, and not actually placing directories it made in a place I could find?). This makes things much easier, since I just need to parse out source directories for binds and ensure they exist. Fixes #9510 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/create_opts.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
index f945c9c54..03cd8a721 100644
--- a/cmd/podman/common/create_opts.go
+++ b/cmd/podman/common/create_opts.go
@@ -3,6 +3,7 @@ package common
import (
"fmt"
"net"
+ "os"
"path/filepath"
"strconv"
"strings"
@@ -13,6 +14,7 @@ import (
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/rootless"
"github.com/containers/podman/v3/pkg/specgen"
+ "github.com/pkg/errors"
)
type ContainerCLIOpts struct {
@@ -397,6 +399,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
}
// volumes
+ volSources := make(map[string]bool)
volDestinations := make(map[string]bool)
for _, vol := range cc.HostConfig.Binds {
cliOpts.Volume = append(cliOpts.Volume, vol)
@@ -407,6 +410,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
case 1:
volDestinations[vol] = true
default:
+ volSources[splitVol[0]] = true
volDestinations[splitVol[1]] = true
}
}
@@ -421,6 +425,19 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
}
cliOpts.Volume = append(cliOpts.Volume, vol)
}
+ // Make mount points for compat volumes
+ for vol := range volSources {
+ // This might be a named volume.
+ // Assume it is if it's not an absolute path.
+ if !filepath.IsAbs(vol) {
+ continue
+ }
+ if err := os.MkdirAll(vol, 0755); err != nil {
+ if !os.IsExist(err) {
+ return nil, nil, errors.Wrapf(err, "error making volume mountpoint for volume %s", vol)
+ }
+ }
+ }
if len(cc.HostConfig.BlkioWeightDevice) > 0 {
devices := make([]string, 0, len(cc.HostConfig.BlkioWeightDevice))
for _, d := range cc.HostConfig.BlkioWeightDevice {