summaryrefslogtreecommitdiff
path: root/pkg/specgen/generate
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-07-31 17:08:06 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-08-03 14:44:52 -0400
commit333d9af77a65d860b5fd788805cd4c0f2cd232df (patch)
treead5ac181ecd3a360c118c2fddeaba83182b86a05 /pkg/specgen/generate
parent7a15be546adffe4f884abfbd4ed02f69ac7659e0 (diff)
downloadpodman-333d9af77a65d860b5fd788805cd4c0f2cd232df.tar.gz
podman-333d9af77a65d860b5fd788805cd4c0f2cd232df.tar.bz2
podman-333d9af77a65d860b5fd788805cd4c0f2cd232df.zip
Ensure WORKDIR from images is created
A recent crun change stopped the creation of the container's working directory if it does not exist. This is arguably correct for user-specified directories, to protect against typos; it is definitely not correct for image WORKDIR, where the image author definitely intended for the directory to be used. This makes Podman create the working directory and chown it to container root, if it does not already exist, and only if it was specified by an image, not the user. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'pkg/specgen/generate')
-rw-r--r--pkg/specgen/generate/container_create.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go
index 9dfb35be3..b61ac2c30 100644
--- a/pkg/specgen/generate/container_create.go
+++ b/pkg/specgen/generate/container_create.go
@@ -238,6 +238,17 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
if s.Entrypoint != nil {
options = append(options, libpod.WithEntrypoint(s.Entrypoint))
}
+ // If the user did not set an workdir but the image did, ensure it is
+ // created.
+ if s.WorkDir == "" && img != nil {
+ newWD, err := img.WorkingDir(ctx)
+ if err != nil {
+ return nil, err
+ }
+ if newWD != "" {
+ options = append(options, libpod.WithCreateWorkingDir())
+ }
+ }
if s.StopSignal != nil {
options = append(options, libpod.WithStopSignal(*s.StopSignal))
}