diff --git a/add.go b/add.go index cbeb6757..46fabde9 100644 --- a/add.go +++ b/add.go @@ -50,6 +50,9 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error if destination != "" && filepath.IsAbs(destination) { dest = filepath.Join(dest, destination) } else { + if err := os.MkdirAll(filepath.Join(dest, b.Workdir), 0755); err != nil { + return fmt.Errorf("error ensuring directory %q exists: %v)", b.Workdir, err) + } dest = filepath.Join(dest, b.Workdir, destination) } // Make sure the destination is usable. diff --git a/run.go b/run.go index dfe1e3b3..16d26d59 100644 --- a/run.go +++ b/run.go @@ -108,6 +108,9 @@ func (b *Builder) Run(command []string, options RunOptions) error { if spec.Process.Cwd == "" { spec.Process.Cwd = DefaultWorkingDir } + if err := os.MkdirAll(filepath.Join(mountPoint, b.Workdir), 0755); err != nil { + return fmt.Errorf("error ensuring working directory %q exists: %v)", b.Workdir, err) + } mounts := options.Mounts for _, specMount := range spec.Mounts { override := false