diff --git a/builder/lxd/step_lxd_launch.go b/builder/lxd/step_lxd_launch.go index 0cc0b80ac..cd51c34f2 100644 --- a/builder/lxd/step_lxd_launch.go +++ b/builder/lxd/step_lxd_launch.go @@ -17,7 +17,7 @@ func (s *stepLxdLaunch) Run(state multistep.StateBag) multistep.StepAction { image := config.Image args := []string{ - "launch", image, name, + "launch", "--ephemeral=false", image, name, } ui.Say("Creating container...") diff --git a/builder/lxd/step_publish.go b/builder/lxd/step_publish.go index cf3c98bb3..ecc547d92 100644 --- a/builder/lxd/step_publish.go +++ b/builder/lxd/step_publish.go @@ -14,15 +14,26 @@ func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) name := config.ContainerName + stop_args := []string{ + // We created the container with "--ephemeral=false" so we know it is safe to stop. + "stop", name, + } + + ui.Say("Stopping container...") + _, err := LXDCommand(stop_args...) + if err != nil { + err := fmt.Errorf("Error stopping container: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } - args := []string{ - // If we use `lxc stop `, an ephemeral container would die forever. - // `lxc publish` has special logic to handle this case. - "publish", "--force", name, "--alias", config.OutputImage, + publish_args := []string{ + "publish", name, "--alias", config.OutputImage, } ui.Say("Publishing container...") - stdoutString, err := LXDCommand(args...) + stdoutString, err := LXDCommand(publish_args...) if err != nil { err := fmt.Errorf("Error publishing container: %s", err) state.Put("error", err)