Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: resolve workdir during initialization after all the mounts are completed. #11353

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,11 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error {
return err
}

// Make sure the workdir exists while initializing container
if err := c.resolveWorkDir(); err != nil {
return err
}

// Save the OCI newSpec to disk
if err := c.saveSpec(newSpec); err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@ func (c *Container) prepare() error {
return err
}

// Make sure the workdir exists
if err := c.resolveWorkDir(); err != nil {
return err
}

return nil
}

Expand Down
20 changes: 20 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,26 @@ var _ = Describe("Podman run with volumes", func() {
Expect(matches[0]).To(Not(ContainSubstring("nosuid")))
})

// Container should start when workdir is overlayed volume
It("podman run with volume mounted as overlay and used as workdir", 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")
giuseppe marked this conversation as resolved.
Show resolved Hide resolved
}
}
mountPath := filepath.Join(podmanTest.TempDir, "secrets")
os.Mkdir(mountPath, 0755)

//Container should be able to start with custom overlayed volume
session := podmanTest.Podman([]string{"run", "--rm", "-v", mountPath + ":/data:O", "--workdir=/data", ALPINE, "echo", "hello"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})

It("podman run with noexec can't exec", func() {
session := podmanTest.Podman([]string{"run", "--rm", "-v", "/bin:/hostbin:noexec", ALPINE, "/hostbin/ls", "/"})
session.WaitWithDefaultTimeout()
Expand Down