Skip to content

Commit

Permalink
fix: make stop stopped container return no error
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Sun <[email protected]>
  • Loading branch information
allencloud committed Apr 25, 2018
1 parent 0713c83 commit 0ab5dc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,9 @@ func (mgr *ContainerManager) Stop(ctx context.Context, name string, timeout int6
c.Lock()
defer c.Unlock()

if !c.IsRunning() {
return fmt.Errorf("container's status is not running: %s", c.meta.State.Status)
if c.IsStopped() {
// stopping a stopped container is valid.
return nil
}

if timeout == 0 {
Expand All @@ -720,7 +721,7 @@ func (mgr *ContainerManager) Stop(ctx context.Context, name string, timeout int6
func (mgr *ContainerManager) stop(ctx context.Context, c *Container, timeout int64) error {
msg, err := mgr.Client.DestroyContainer(ctx, c.ID(), timeout)
if err != nil {
return errors.Wrapf(err, "failed to destroy container: %s", c.ID())
return errors.Wrapf(err, "failed to destroy container %s", c.ID())
}

return mgr.markStoppedAndRelease(c, msg)
Expand Down
3 changes: 3 additions & 0 deletions test/cli_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (suite *PouchStopSuite) TestStopWorks(c *check.C) {

command.PouchRun("start", name).Assert(c, icmd.Success)

// test stop a running container
command.PouchRun("stop", name).Assert(c, icmd.Success)
// test stop a stopped container
command.PouchRun("stop", name).Assert(c, icmd.Success)

res := command.PouchRun("ps", "-a")
Expand Down

0 comments on commit 0ab5dc0

Please sign in to comment.