2014-04-14 08:43:01 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-02-02 21:39:24 -05:00
|
|
|
"io/ioutil"
|
2014-04-14 08:43:01 -04:00
|
|
|
"os"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2015-10-18 22:42:56 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-04-14 08:43:01 -04:00
|
|
|
)
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon)
|
2015-02-20 01:56:02 -05:00
|
|
|
|
2016-02-03 09:16:00 -05:00
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-02 21:39:24 -05:00
|
|
|
|
|
|
|
tempDir, err := ioutil.TempDir("", "test-rm-container-with-removed-volume-")
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("failed to create temporary directory: %s", tempDir)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tempDir)
|
2014-04-14 08:43:01 -04:00
|
|
|
|
2016-02-02 21:39:24 -05:00
|
|
|
dockerCmd(c, "run", "--name", "losemyvolumes", "-v", tempDir+":"+prefix+slash+"test", "busybox", "true")
|
|
|
|
|
|
|
|
err = os.RemoveAll(tempDir)
|
2015-10-18 22:42:56 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2014-04-14 08:43:01 -04:00
|
|
|
|
2015-07-14 16:15:00 -04:00
|
|
|
dockerCmd(c, "rm", "-v", "losemyvolumes")
|
2014-04-14 08:43:01 -04:00
|
|
|
}
|
2014-04-18 13:40:12 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) {
|
2016-02-03 09:16:00 -05:00
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-02 21:39:24 -05:00
|
|
|
|
|
|
|
dockerCmd(c, "run", "--name", "foo", "-v", prefix+slash+"srv", "busybox", "true")
|
2015-02-20 01:56:02 -05:00
|
|
|
|
2015-07-14 16:15:00 -04:00
|
|
|
dockerCmd(c, "rm", "-v", "foo")
|
2014-04-18 13:40:12 -04:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:39:24 -05:00
|
|
|
func (s *DockerSuite) TestRmContainerRunning(c *check.C) {
|
2015-04-18 12:46:47 -04:00
|
|
|
createRunningContainer(c, "foo")
|
2014-04-18 13:40:12 -04:00
|
|
|
|
2015-10-18 22:42:56 -04:00
|
|
|
_, _, err := dockerCmdWithError("rm", "foo")
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("Expected error, can't rm a running container"))
|
2014-07-06 16:44:56 -04:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:39:24 -05:00
|
|
|
func (s *DockerSuite) TestRmContainerForceRemoveRunning(c *check.C) {
|
2015-04-18 12:46:47 -04:00
|
|
|
createRunningContainer(c, "foo")
|
2014-07-06 16:44:56 -04:00
|
|
|
|
|
|
|
// Stop then remove with -s
|
2015-07-14 16:15:00 -04:00
|
|
|
dockerCmd(c, "rm", "-f", "foo")
|
2014-07-06 16:44:56 -04:00
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
|
2014-08-05 19:11:09 -04:00
|
|
|
dockerfile1 := `FROM busybox:latest
|
2016-02-02 21:39:24 -05:00
|
|
|
ENTRYPOINT ["true"]`
|
2014-08-05 19:11:09 -04:00
|
|
|
img := "test-container-orphaning"
|
|
|
|
dockerfile2 := `FROM busybox:latest
|
2016-02-02 21:39:24 -05:00
|
|
|
ENTRYPOINT ["true"]
|
2014-08-05 19:11:09 -04:00
|
|
|
MAINTAINER Integration Tests`
|
|
|
|
|
|
|
|
// build first dockerfile
|
|
|
|
img1, err := buildImage(img, dockerfile1, true)
|
2015-10-18 22:42:56 -04:00
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img))
|
2014-08-05 19:11:09 -04:00
|
|
|
// run container on first image
|
2015-10-18 22:42:56 -04:00
|
|
|
dockerCmd(c, "run", img)
|
2014-08-05 19:11:09 -04:00
|
|
|
// rebuild dockerfile with a small addition at the end
|
2015-10-18 22:42:56 -04:00
|
|
|
_, err = buildImage(img, dockerfile2, true)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img))
|
2015-11-25 20:57:20 -05:00
|
|
|
// try to remove the image, should not error out.
|
2015-10-18 22:42:56 -04:00
|
|
|
out, _, err := dockerCmdWithError("rmi", img)
|
2015-11-25 20:57:20 -05:00
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out))
|
2015-07-14 16:15:00 -04:00
|
|
|
|
2014-08-05 19:11:09 -04:00
|
|
|
// check if we deleted the first image
|
2015-10-18 22:42:56 -04:00
|
|
|
out, _ = dockerCmd(c, "images", "-q", "--no-trunc")
|
|
|
|
c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out))
|
|
|
|
|
2014-08-05 19:11:09 -04:00
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {
|
Remove redundant error message
Currently some commands including `kill`, `pause`, `restart`, `rm`,
`rmi`, `stop`, `unpause`, `udpate`, `wait` will print a lot of error
message on client side, with a lot of redundant messages, this commit is
trying to remove the unuseful and redundant information for user.
Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
2016-02-03 01:29:15 -05:00
|
|
|
out, _, err := dockerCmdWithError("rm", "unknown")
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("Expected error on rm unknown container, got none"))
|
|
|
|
c.Assert(out, checker.Contains, "No such container")
|
2014-08-05 19:11:09 -04:00
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func createRunningContainer(c *check.C, name string) {
|
2016-02-02 21:39:24 -05:00
|
|
|
runSleepingContainer(c, "-dt", "--name", name)
|
2014-04-18 13:40:12 -04:00
|
|
|
}
|