Pull missing images on run. Addresses #31.

chooper@chimay:~/projects/docker/bin$ ./docker images
	NAME                ID                  CREATED             PARENT
	chooper@chimay:~/projects/docker/bin$ ./docker run -a base echo "hello world"
	Downloading from http://s3.amazonaws.com/docker.io/images/base
	Unpacking to base
	######################################################################## 100.0%
	base:e9cb4ad9173245ac
	hello world
	chooper@chimay:~/projects/docker/bin$ ./docker run -a base echo "hello world"
	hello world
	chooper@chimay:~/projects/docker/bin$ ./docker run -a nosuchimage echo "hello world"
	Downloading from http://s3.amazonaws.com/docker.io/images/nosuchimage
	Unpacking to nosuchimage
	######################################################################## 100.0%
	Error: Error downloading image: nosuchimage
	chooper@chimay:~/projects/docker/bin$
This commit is contained in:
Charles Hooper 2013-03-12 02:58:39 +00:00
parent fb350e0c77
commit f6d64738d0

View file

@ -800,6 +800,8 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
fl_tty := cmd.Bool("t", false, "Allocate a pseudo-tty")
fl_comment := cmd.String("c", "", "Comment")
var fl_ports ports
var img *image.Image
cmd.Var(&fl_ports, "p", "Map a network port to the container")
if err := cmd.Parse(args); err != nil {
return nil
@ -820,11 +822,20 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
*fl_attach = true
cmdline = []string{"/bin/bash", "-i"}
}
// Find the image
img := srv.images.Find(name)
img = srv.images.Find(name)
if img == nil {
return errors.New("No such image: " + name)
devnull, err := os.Open("/dev/null")
if err != nil {
return errors.New("Error opening /dev/null")
}
if srv.CmdPull(devnull, stdout, name) != nil {
return errors.New("Error downloading image: " + name)
}
img = srv.images.Find(name)
}
// Create new container
container, err := srv.CreateContainer(img, fl_ports, *fl_user, *fl_tty, *fl_stdin, *fl_comment, cmdline[0], cmdline[1:]...)
if err != nil {