mirror of
https://github.com/containers/podman.git
synced 2025-06-26 04:46:57 +08:00
volume: Add support for overlay on named volumes
Following PR allows containers to create and mount overlays on top of named volumes instead of mounting actual volumes via already documented `:O`. Signed-off-by: Aditya Rajan <arajan@redhat.com>
This commit is contained in:
@ -369,13 +369,46 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
volMount := spec.Mount{
|
|
||||||
Type: "bind",
|
overlayFlag := false
|
||||||
Source: mountPoint,
|
for _, o := range namedVol.Options {
|
||||||
Destination: namedVol.Dest,
|
if o == "O" {
|
||||||
Options: namedVol.Options,
|
overlayFlag = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if overlayFlag {
|
||||||
|
contentDir, err := overlay.TempDir(c.config.StaticDir, c.RootUID(), c.RootGID())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
overlayMount, err := overlay.Mount(contentDir, mountPoint, namedVol.Dest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "mounting overlay failed %q", mountPoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, o := range namedVol.Options {
|
||||||
|
switch o {
|
||||||
|
case "U":
|
||||||
|
if err := chown.ChangeHostPathOwnership(mountPoint, true, int(hostUID), int(hostGID)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := chown.ChangeHostPathOwnership(contentDir, true, int(hostUID), int(hostGID)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.AddMount(overlayMount)
|
||||||
|
} else {
|
||||||
|
volMount := spec.Mount{
|
||||||
|
Type: "bind",
|
||||||
|
Source: mountPoint,
|
||||||
|
Destination: namedVol.Dest,
|
||||||
|
Options: namedVol.Options,
|
||||||
|
}
|
||||||
|
g.AddMount(volMount)
|
||||||
}
|
}
|
||||||
g.AddMount(volMount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the spec file mounts contain the options z, Z or U.
|
// Check if the spec file mounts contain the options z, Z or U.
|
||||||
|
@ -242,6 +242,39 @@ var _ = Describe("Podman run with volumes", func() {
|
|||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman support overlay on named volume", func() {
|
||||||
|
SkipIfRemote("Overlay volumes only work locally")
|
||||||
|
if os.Getenv("container") != "" {
|
||||||
|
Skip("Overlay mounts not supported when running in a container")
|
||||||
|
}
|
||||||
|
if rootless.IsRootless() {
|
||||||
|
if _, err := exec.LookPath("fuse-overlayfs"); err != nil {
|
||||||
|
Skip("Fuse-Overlayfs required for rootless overlay mount test")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session := podmanTest.Podman([]string{"volume", "create", "myvolume"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
volName := session.OutputToString()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
// create file on actual volume
|
||||||
|
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> " + "/data/test"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
// create file on overlayed volume
|
||||||
|
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data:O", ALPINE, "sh", "-c", "echo hello >> " + "/data/overlayed"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
// volume should contain only `test` not `overlayed`
|
||||||
|
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "ls /data"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.OutputToString()).To(Not(ContainSubstring("overlayed")))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("test"))
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
It("podman run with noexec can't exec", func() {
|
It("podman run with noexec can't exec", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "--rm", "-v", "/bin:/hostbin:noexec", ALPINE, "/hostbin/ls", "/"})
|
session := podmanTest.Podman([]string{"run", "--rm", "-v", "/bin:/hostbin:noexec", ALPINE, "/hostbin/ls", "/"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user