1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

'docker start' and 'docker restart': start or restart a container

This commit is contained in:
Solomon Hykes 2013-02-14 13:49:05 -08:00
parent 0da9ccc18e
commit d2885910bd
2 changed files with 50 additions and 0 deletions

View file

@ -89,6 +89,8 @@ func InteractiveMode(scripts ...string) error {
"kill", "kill",
"wait", "wait",
"stop", "stop",
"start",
"restart",
"logs", "logs",
"diff", "diff",
"commit", "commit",

View file

@ -48,6 +48,8 @@ func (srv *Server) Help() string {
{"kill", "Kill a running container"}, {"kill", "Kill a running container"},
{"wait", "Wait for the state of a container to change"}, {"wait", "Wait for the state of a container to change"},
{"stop", "Stop a running container"}, {"stop", "Stop a running container"},
{"start", "Start a stopped container"},
{"restart", "Restart a running container"},
{"logs", "Fetch the logs of a container"}, {"logs", "Fetch the logs of a container"},
{"diff", "Inspect changes on a container's filesystem"}, {"diff", "Inspect changes on a container's filesystem"},
{"commit", "Save the state of a container"}, {"commit", "Save the state of a container"},
@ -94,6 +96,52 @@ func (srv *Server) CmdStop(stdin io.ReadCloser, stdout io.Writer, args ...string
return nil return nil
} }
func (srv *Server) CmdRestart(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
cmd := rcli.Subcmd(stdout, "restart", "[OPTIONS] NAME", "Restart a running container")
if err := cmd.Parse(args); err != nil {
cmd.Usage()
return nil
}
if cmd.NArg() < 1 {
cmd.Usage()
return nil
}
for _, name := range cmd.Args() {
if container := srv.containers.Get(name); container != nil {
if err := container.Restart(); err != nil {
return err
}
fmt.Fprintln(stdout, container.Id)
} else {
return errors.New("No such container: " + name)
}
}
return nil
}
func (srv *Server) CmdStart(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
cmd := rcli.Subcmd(stdout, "start", "[OPTIONS] NAME", "Start a stopped container")
if err := cmd.Parse(args); err != nil {
cmd.Usage()
return nil
}
if cmd.NArg() < 1 {
cmd.Usage()
return nil
}
for _, name := range cmd.Args() {
if container := srv.containers.Get(name); container != nil {
if err := container.Start(); err != nil {
return err
}
fmt.Fprintln(stdout, container.Id)
} else {
return errors.New("No such container: " + name)
}
}
return nil
}
func (srv *Server) CmdUmount(stdin io.ReadCloser, stdout io.Writer, args ...string) error { func (srv *Server) CmdUmount(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
cmd := rcli.Subcmd(stdout, "umount", "[OPTIONS] NAME", "umount a container's filesystem (debug only)") cmd := rcli.Subcmd(stdout, "umount", "[OPTIONS] NAME", "umount a container's filesystem (debug only)")
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {