summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2018-06-29 12:34:35 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-06-29 19:56:12 +0000
commit4c8c000f3aa0b25577338f805a07c16518890b3d (patch)
tree356649bd991033c4db83f9ebb66c840d021f8a12
parent7fc1a329bd014d61f9895fc212aef452f6fb8f84 (diff)
downloadpodman-4c8c000f3aa0b25577338f805a07c16518890b3d.tar.gz
podman-4c8c000f3aa0b25577338f805a07c16518890b3d.tar.bz2
podman-4c8c000f3aa0b25577338f805a07c16518890b3d.zip
Fix built-in volume issue with podman run/create
The destination path of the built-in volume was not being created but a relabel was being attempted on it, this was causing issues with all images that have built-in volumes. This patch fixes that and ensures the destination volume path is created. Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #1026 Approved by: mheon
-rw-r--r--libpod/container_internal.go37
-rw-r--r--test/e2e/run_test.go19
2 files changed, 43 insertions, 13 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 5c5bf8062..07bb5c6d1 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -1431,28 +1431,39 @@ func (c *Container) addImageVolumes(ctx context.Context, g *generate.Generator)
volumePath := filepath.Join(c.config.StaticDir, "volumes", k)
srcPath := filepath.Join(mountPoint, k)
+ var (
+ uid uint32
+ gid uint32
+ )
+ if c.config.User != "" {
+ if !c.state.Mounted {
+ return errors.Wrapf(ErrCtrStateInvalid, "container %s must be mounted in order to translate User field", c.ID())
+ }
+ uid, gid, err = chrootuser.GetUser(c.state.Mountpoint, c.config.User)
+ if err != nil {
+ return err
+ }
+ }
+
if _, err := os.Stat(srcPath); os.IsNotExist(err) {
logrus.Infof("Volume image mount point %s does not exist in root FS, need to create it", k)
- if err = os.MkdirAll(volumePath, 0755); err != nil {
+ if err = os.MkdirAll(srcPath, 0755); err != nil {
return errors.Wrapf(err, "error creating directory %q for volume %q in container %q", volumePath, k, c.ID)
}
- if c.config.User != "" {
- if !c.state.Mounted {
- return errors.Wrapf(ErrCtrStateInvalid, "container %s must be mounted in order to translate User field", c.ID())
- }
- uid, gid, err := chrootuser.GetUser(c.state.Mountpoint, c.config.User)
- if err != nil {
- return err
- }
-
- if err = os.Chown(volumePath, int(uid), int(gid)); err != nil {
- return errors.Wrapf(err, "error chowning directory %q for volume %q in container %q", volumePath, k, c.ID)
- }
+ if err = os.Chown(srcPath, int(uid), int(gid)); err != nil {
+ return errors.Wrapf(err, "error chowning directory %q for volume %q in container %q", srcPath, k, c.ID)
}
}
if _, err := os.Stat(volumePath); os.IsNotExist(err) {
+ if err = os.MkdirAll(volumePath, 0755); err != nil {
+ return errors.Wrapf(err, "error creating directory %q for volume %q in container %q", volumePath, k, c.ID)
+ }
+
+ if err = os.Chown(volumePath, int(uid), int(gid)); err != nil {
+ return errors.Wrapf(err, "error chowning directory %q for volume %q in container %q", volumePath, k, c.ID)
+ }
if err = label.Relabel(volumePath, c.config.MountLabel, false); err != nil {
return errors.Wrapf(err, "error relabeling directory %q for volume %q in container %q", volumePath, k, c.ID)
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index 34ed55941..76269031d 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -476,4 +476,23 @@ var _ = Describe("Podman run", func() {
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(100))
})
+
+ It("podman run with built-in volume image", func() {
+ session := podmanTest.Podman([]string{"run", "--rm", "docker.io/library/redis:alpine", "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"rmi", "docker.io/library/redis:alpine"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"run", "--rm", "-e", "MYSQL_USER=zmuser", "-e", "MYSQL_PASSWORD=zmpass", "-e", "MYSQL_DATABASE=zm", "-e", "MYSQL_ROOT_PASSWORD=mysqlpassword", "docker.io/centos/mariadb-101-centos7", "ls", "-al", "/var/lib/mysql/data"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring("mysql root"))
+
+ session = podmanTest.Podman([]string{"rmi", "docker.io/centos/mariadb-101-centos7"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ })
})