From be7ab169a53da91bbc083bf815557c649cb260da Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 26 Mar 2013 03:05:10 -0700 Subject: [PATCH] #175 Add autodownload on run command Upstream-commit: 91d78a10c33d9e1c33120634fb3dad5e0d247d28 Component: engine --- components/engine/commands.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 1f2c3650d7..7cc46dfcdd 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -826,10 +826,19 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) fmt.Fprintln(stdout, "Error: Command not specified") return fmt.Errorf("Command not specified") } + // Create new container container, err := srv.runtime.Create(config) if err != nil { - return errors.New("Error creating container: " + err.Error()) + // If container not found, try to pull it + // FIXME: not found != error + fmt.Fprintf(stdout, "Image %s not found, trying to pull it from registry.\n", config.Image) + if err = srv.CmdPull(stdin, stdout, config.Image); err != nil { + return err + } + if container, err = srv.runtime.Create(config); err != nil { + return fmt.Errorf("Error creating container: %s", err) + } } if config.OpenStdin { cmd_stdin, err := container.StdinPipe()