Skip to content

Commit

Permalink
Merge pull request #526 from mesg-foundation/fix/stop-service
Browse files Browse the repository at this point in the history
Improve hack on StopService function to force removing the container
  • Loading branch information
antho1404 authored Oct 5, 2018
2 parents dce9151 + 5d7279b commit 8e98a70
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions container/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func (c *DockerContainer) StopService(namespace []string) (err error) {
if err := c.client.ServiceRemove(ctx, c.Namespace(namespace)); err != nil && !docker.IsErrNotFound(err) {
return err
}
// TOFIX: Hack to force Docker to remove the containers.
// Sometime, the ServiceRemove function doesn't remove the associated containers.
// This hack for Docker to stop and then remove the container.
// See issue https://github.com/moby/moby/issues/32620
if container.ContainerJSONBase != nil {
timeout := 1 * time.Second
if err := c.client.ContainerStop(ctx, container.ID, &timeout); err != nil && !docker.IsErrNotFound(err) {
return err
}
if err := c.client.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{}); err != nil && !docker.IsErrNotFound(err) {
return err
}
c.client.ContainerStop(ctx, container.ID, &timeout)
c.client.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{})
}
return c.waitForStatus(namespace, STOPPED)
}
Expand Down

0 comments on commit 8e98a70

Please sign in to comment.