diff --git a/builder/docker/step_export.go b/builder/docker/step_export.go index 6fbdcb63d..b09ea0bd4 100644 --- a/builder/docker/step_export.go +++ b/builder/docker/step_export.go @@ -3,6 +3,7 @@ package docker import ( "fmt" "os" + "path/filepath" "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" @@ -26,6 +27,13 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + // Make the directory we're exporting to if it doesn't exist + exportDir := filepath.Dir(config.ExportPath) + if err := os.MkdirAll(exportDir, 0755); err != nil { + state.Put("error", err) + return multistep.ActionHalt + } + // Open the file that we're going to write to f, err := os.Create(config.ExportPath) if err != nil {