mirror of https://github.com/docker/compose.git
Merge pull request #9256 from ndeloof/rm_empty
don't fail trying to remove container with no candidate
This commit is contained in:
commit
4d163f35f3
|
@ -165,7 +165,7 @@ SERVICES:
|
||||||
continue SERVICES
|
continue SERVICES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return project, errors.New("no such service: " + qs)
|
return project, errors.Wrapf(api.ErrNotFound, "no such service: %q", qs)
|
||||||
}
|
}
|
||||||
err := project.ForServices(services)
|
err := project.ForServices(services)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -32,6 +32,10 @@ import (
|
||||||
func (s *composeService) Remove(ctx context.Context, projectName string, options api.RemoveOptions) error {
|
func (s *composeService) Remove(ctx context.Context, projectName string, options api.RemoveOptions) error {
|
||||||
containers, _, err := s.actualState(ctx, projectName, options.Services)
|
containers, _, err := s.actualState(ctx, projectName, options.Services)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if api.IsNotFoundError(err) {
|
||||||
|
fmt.Fprintln(s.stderr(), "No stopped containers")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +49,7 @@ func (s *composeService) Remove(ctx context.Context, projectName string, options
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(names) == 0 {
|
if len(names) == 0 {
|
||||||
fmt.Println("No stopped containers")
|
fmt.Fprintln(s.stderr(), "No stopped containers")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf("Going to remove %s", strings.Join(names, ", "))
|
msg := fmt.Sprintf("Going to remove %s", strings.Join(names, ", "))
|
||||||
|
|
|
@ -188,6 +188,11 @@ func TestRm(t *testing.T) {
|
||||||
assert.Assert(t, !strings.Contains(res.Combined(), projectName+"_simple"), res.Combined())
|
assert.Assert(t, !strings.Contains(res.Combined(), projectName+"_simple"), res.Combined())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("rm -sf <none>", func(t *testing.T) {
|
||||||
|
res := c.RunDockerComposeCmd("-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple")
|
||||||
|
res.Assert(t, icmd.Expected{ExitCode: 0})
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("down", func(t *testing.T) {
|
t.Run("down", func(t *testing.T) {
|
||||||
c.RunDockerComposeCmd("-p", projectName, "down")
|
c.RunDockerComposeCmd("-p", projectName, "down")
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue