mirror of https://github.com/docker/docs.git
Merge pull request #4916 from creack/no_error_start_twice
Don't error when trying to start a running container
This commit is contained in:
commit
249a5ddfeb
|
@ -549,9 +549,11 @@ func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) CmdStart(args ...string) error {
|
func (cli *DockerCli) CmdStart(args ...string) error {
|
||||||
cmd := cli.Subcmd("start", "CONTAINER [CONTAINER...]", "Restart a stopped container")
|
var (
|
||||||
attach := cmd.Bool([]string{"a", "-attach"}, false, "Attach container's stdout/stderr and forward all signals to the process")
|
cmd = cli.Subcmd("start", "CONTAINER [CONTAINER...]", "Restart a stopped container")
|
||||||
openStdin := cmd.Bool([]string{"i", "-interactive"}, false, "Attach container's stdin")
|
attach = cmd.Bool([]string{"a", "-attach"}, false, "Attach container's stdout/stderr and forward all signals to the process")
|
||||||
|
openStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Attach container's stdin")
|
||||||
|
)
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -560,8 +562,10 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var cErr chan error
|
var (
|
||||||
var tty bool
|
cErr chan error
|
||||||
|
tty bool
|
||||||
|
)
|
||||||
if *attach || *openStdin {
|
if *attach || *openStdin {
|
||||||
if cmd.NArg() > 1 {
|
if cmd.NArg() > 1 {
|
||||||
return fmt.Errorf("You cannot start and attach multiple containers at once.")
|
return fmt.Errorf("You cannot start and attach multiple containers at once.")
|
||||||
|
|
|
@ -350,7 +350,7 @@ func TestStart(t *testing.T) {
|
||||||
if !container.State.IsRunning() {
|
if !container.State.IsRunning() {
|
||||||
t.Errorf("Container should be running")
|
t.Errorf("Container should be running")
|
||||||
}
|
}
|
||||||
if err := container.Start(); err == nil {
|
if err := container.Start(); err != nil {
|
||||||
t.Fatalf("A running container should be able to be started")
|
t.Fatalf("A running container should be able to be started")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ func TestCpuShares(t *testing.T) {
|
||||||
if !container.State.IsRunning() {
|
if !container.State.IsRunning() {
|
||||||
t.Errorf("Container should be running")
|
t.Errorf("Container should be running")
|
||||||
}
|
}
|
||||||
if err := container.Start(); err == nil {
|
if err := container.Start(); err != nil {
|
||||||
t.Fatalf("A running container should be able to be started")
|
t.Fatalf("A running container should be able to be started")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -426,7 +426,7 @@ func (container *Container) Start() (err error) {
|
||||||
defer container.Unlock()
|
defer container.Unlock()
|
||||||
|
|
||||||
if container.State.IsRunning() {
|
if container.State.IsRunning() {
|
||||||
return fmt.Errorf("The container %s is already running.", container.ID)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
@ -2064,9 +2064,11 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
|
||||||
if len(job.Args) < 1 {
|
if len(job.Args) < 1 {
|
||||||
return job.Errorf("Usage: %s container_id", job.Name)
|
return job.Errorf("Usage: %s container_id", job.Name)
|
||||||
}
|
}
|
||||||
name := job.Args[0]
|
var (
|
||||||
runtime := srv.runtime
|
name = job.Args[0]
|
||||||
container := runtime.Get(name)
|
runtime = srv.runtime
|
||||||
|
container = runtime.Get(name)
|
||||||
|
)
|
||||||
|
|
||||||
if container == nil {
|
if container == nil {
|
||||||
return job.Errorf("No such container: %s", name)
|
return job.Errorf("No such container: %s", name)
|
||||||
|
|
Loading…
Reference in New Issue