mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #12753 from LK4D4/remove_all_images
Implement teardown removeAllImages
This commit is contained in:
commit
700056cd4c
20 changed files with 50 additions and 269 deletions
|
@ -30,6 +30,7 @@ type DockerSuite struct {
|
|||
|
||||
func (s *DockerSuite) TearDownTest(c *check.C) {
|
||||
deleteAllContainers()
|
||||
deleteAllImages()
|
||||
s.TimerSuite.TearDownTest(c)
|
||||
}
|
||||
|
||||
|
|
|
@ -632,7 +632,6 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
|
|||
if err := json.Unmarshal(b, &img); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
defer deleteImages(img.Id)
|
||||
|
||||
cmd, err := inspectField(img.Id, "Config.Cmd")
|
||||
if err != nil {
|
||||
|
|
|
@ -30,7 +30,6 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
|||
name := "utest:tag1"
|
||||
name2 := "utest/docker:tag2"
|
||||
name3 := "utest:5000/docker:tag3"
|
||||
defer deleteImages(name, name2, name3)
|
||||
for _, n := range []string{name, name2, name3} {
|
||||
if out, err := exec.Command(dockerBinary, "tag", "busybox", n).CombinedOutput(); err != nil {
|
||||
c.Fatal(err, out)
|
||||
|
@ -74,7 +73,6 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
|||
c.Fatal(err)
|
||||
}
|
||||
id := strings.TrimSpace(out)
|
||||
defer deleteImages("saveandload")
|
||||
|
||||
status, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -33,7 +33,6 @@ func setupImageWithTag(tag string) (string, error) {
|
|||
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
||||
return "", fmt.Errorf("image tagging failed: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoAndTag)
|
||||
|
||||
// delete the container as we don't need it any more
|
||||
if err := deleteContainer(containerName); err != nil {
|
||||
|
@ -77,7 +76,6 @@ func (s *DockerSuite) TestPullByTagDisplaysDigest(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("error pulling by tag: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoName)
|
||||
|
||||
// the pull output includes "Digest: <digest>", so find that
|
||||
matches := digestRegex.FindStringSubmatch(out)
|
||||
|
@ -108,7 +106,6 @@ func (s *DockerSuite) TestPullByDigest(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("error pulling by digest: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(imageReference)
|
||||
|
||||
// the pull output includes "Digest: <digest>", so find that
|
||||
matches := digestRegex.FindStringSubmatch(out)
|
||||
|
@ -248,7 +245,6 @@ func (s *DockerSuite) TestBuildByDigest(c *check.C) {
|
|||
|
||||
// do the build
|
||||
name := "buildbydigest"
|
||||
defer deleteImages(name)
|
||||
_, err = buildImage(name, fmt.Sprintf(
|
||||
`FROM %s
|
||||
CMD ["/bin/echo", "Hello World"]`, imageReference),
|
||||
|
@ -340,7 +336,6 @@ func (s *DockerSuite) TestListImagesWithoutDigests(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestListImagesWithDigests(c *check.C) {
|
||||
defer setupRegistry(c)()
|
||||
defer deleteImages(repoName+":tag1", repoName+":tag2")
|
||||
|
||||
// setup image1
|
||||
digest1, err := setupImageWithTag("tag1")
|
||||
|
@ -348,7 +343,6 @@ func (s *DockerSuite) TestListImagesWithDigests(c *check.C) {
|
|||
c.Fatalf("error setting up image: %v", err)
|
||||
}
|
||||
imageReference1 := fmt.Sprintf("%s@%s", repoName, digest1)
|
||||
defer deleteImages(imageReference1)
|
||||
c.Logf("imageReference1 = %s", imageReference1)
|
||||
|
||||
// pull image1 by digest
|
||||
|
@ -377,7 +371,6 @@ func (s *DockerSuite) TestListImagesWithDigests(c *check.C) {
|
|||
c.Fatalf("error setting up image: %v", err)
|
||||
}
|
||||
imageReference2 := fmt.Sprintf("%s@%s", repoName, digest2)
|
||||
defer deleteImages(imageReference2)
|
||||
c.Logf("imageReference2 = %s", imageReference2)
|
||||
|
||||
// pull image1 by digest
|
||||
|
@ -508,7 +501,6 @@ func (s *DockerSuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) {
|
|||
c.Fatalf("error pulling by digest: %s, %v", out, err)
|
||||
}
|
||||
// just in case...
|
||||
defer deleteImages(imageReference)
|
||||
|
||||
imageID, err := inspectField(imageReference, ".Id")
|
||||
if err != nil {
|
||||
|
|
|
@ -33,10 +33,6 @@ func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
|
|||
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
||||
c.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
deleteImages(cleanedImageID)
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
|
||||
|
@ -65,10 +61,6 @@ func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
|
|||
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
||||
c.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
deleteImages(cleanedImageID)
|
||||
|
||||
}
|
||||
|
||||
//test commit a paused container should not unpause it after commit
|
||||
|
@ -92,8 +84,6 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("failed to commit container to image: %s, %v", out, err)
|
||||
}
|
||||
cleanedImageID := strings.TrimSpace(out)
|
||||
defer deleteImages(cleanedImageID)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.State.Paused}}", cleanedContainerID)
|
||||
out, _, _, err = runCommandWithStdoutStderr(cmd)
|
||||
|
@ -120,7 +110,6 @@ func (s *DockerSuite) TestCommitNewFile(c *check.C) {
|
|||
c.Fatal(err)
|
||||
}
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", imageID, "cat", "/foo")
|
||||
|
||||
|
@ -161,7 +150,6 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
|
|||
c.Fatal(imageID, err)
|
||||
}
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
|
||||
secondOuput, _, err := runCommandWithOutput(cmd)
|
||||
|
@ -185,7 +173,6 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestCommitTTY(c *check.C) {
|
||||
defer deleteImages("ttytest")
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
|
@ -220,7 +207,6 @@ func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
|
|||
}
|
||||
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "bindtest", "true")
|
||||
|
||||
|
@ -248,7 +234,6 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
|
|||
c.Fatal(imageId, err)
|
||||
}
|
||||
imageId = strings.Trim(imageId, "\r\n")
|
||||
defer deleteImages(imageId)
|
||||
|
||||
expected := map[string]string{
|
||||
"Config.ExposedPorts": "map[8080/tcp:{}]",
|
||||
|
@ -274,7 +259,6 @@ func (s *DockerSuite) TestCommitMergeConfigRun(c *check.C) {
|
|||
id := strings.TrimSpace(out)
|
||||
|
||||
dockerCmd(c, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test")
|
||||
defer deleteImages("commit-test")
|
||||
|
||||
out, _ = dockerCmd(c, "run", "--name", name, "commit-test")
|
||||
if strings.TrimSpace(out) != "testing" {
|
||||
|
|
|
@ -259,7 +259,6 @@ func (s *DockerSuite) TestCreateLabels(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) {
|
||||
imageName := "testcreatebuildlabel"
|
||||
defer deleteImages(imageName)
|
||||
_, err := buildImage(imageName,
|
||||
`FROM busybox
|
||||
LABEL k1=v1 k2=v2`,
|
||||
|
|
|
@ -144,7 +144,6 @@ func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
|
||||
name := "testimageevents"
|
||||
defer deleteImages(name)
|
||||
_, err := buildImage(name,
|
||||
`FROM scratch
|
||||
MAINTAINER "docker"`,
|
||||
|
@ -180,8 +179,6 @@ func (s *DockerSuite) TestEventsImagePull(c *check.C) {
|
|||
since := daemonTime(c).Unix()
|
||||
testRequires(c, Network)
|
||||
|
||||
defer deleteImages("hello-world")
|
||||
|
||||
pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
|
||||
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
|
||||
c.Fatalf("pulling the hello-world image from has failed: %s, %v", out, err)
|
||||
|
|
|
@ -12,8 +12,6 @@ import (
|
|||
func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
|
||||
containerID := "testexportcontainerandimportimage"
|
||||
|
||||
defer deleteImages("repo/testexp:v1")
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", containerID, "busybox", "true")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -51,8 +49,6 @@ func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
|
|||
func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
|
||||
containerID := "testexportcontainerwithoutputandimportimage"
|
||||
|
||||
defer deleteImages("repo/testexp:v1")
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", containerID, "busybox", "true")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
// sort is not predictable it doesn't always fail.
|
||||
func (s *DockerSuite) TestBuildHistory(c *check.C) {
|
||||
name := "testbuildhistory"
|
||||
defer deleteImages(name)
|
||||
_, err := buildImage(name, `FROM busybox
|
||||
RUN echo "A"
|
||||
RUN echo "B"
|
||||
|
@ -85,7 +84,6 @@ func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
|
||||
name := "testhistoryimagewithcomment"
|
||||
defer deleteImages(name)
|
||||
|
||||
// make a image through docker commit <container id> [ -m messages ]
|
||||
//runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
||||
|
|
|
@ -26,9 +26,6 @@ func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
||||
defer deleteImages("order:test_a")
|
||||
defer deleteImages("order:test_c")
|
||||
defer deleteImages("order:test_b")
|
||||
id1, err := buildImage("order:test_a",
|
||||
`FROM scratch
|
||||
MAINTAINER dockerio1`, true)
|
||||
|
@ -80,9 +77,6 @@ func (s *DockerSuite) TestImagesFilterLabel(c *check.C) {
|
|||
imageName1 := "images_filter_test1"
|
||||
imageName2 := "images_filter_test2"
|
||||
imageName3 := "images_filter_test3"
|
||||
defer deleteImages(imageName1)
|
||||
defer deleteImages(imageName2)
|
||||
defer deleteImages(imageName3)
|
||||
image1ID, err := buildImage(imageName1,
|
||||
`FROM scratch
|
||||
LABEL match me`, true)
|
||||
|
@ -130,7 +124,6 @@ func (s *DockerSuite) TestImagesFilterLabel(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
|
||||
imageName := "images_filter_test"
|
||||
defer deleteImages(imageName)
|
||||
buildImage(imageName,
|
||||
`FROM scratch
|
||||
RUN touch /test/foo
|
||||
|
@ -189,7 +182,6 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
|
|||
c.Fatalf("error tagging foobox: %s", err)
|
||||
}
|
||||
imageId := stringid.TruncateID(strings.TrimSpace(out))
|
||||
defer deleteImages(imageId)
|
||||
|
||||
// overwrite the tag, making the previous image dangling
|
||||
cmd = exec.Command(dockerBinary, "tag", "-f", "busybox", "foobox")
|
||||
|
@ -197,7 +189,6 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("error tagging foobox: %s", err)
|
||||
}
|
||||
defer deleteImages("foobox")
|
||||
|
||||
cmd = exec.Command(dockerBinary, "images", "-q", "-f", "dangling=true")
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
|
|
|
@ -27,7 +27,6 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
|
|||
c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
||||
}
|
||||
image := strings.TrimSpace(out)
|
||||
defer deleteImages(image)
|
||||
|
||||
runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
|
||||
out, _, err = runCommandWithOutput(runCmd)
|
||||
|
|
|
@ -560,7 +560,6 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
||||
tag := "asybox:shmatest"
|
||||
defer deleteImages(tag)
|
||||
if out, err := exec.Command(dockerBinary, "tag", "busybox", tag).CombinedOutput(); err != nil {
|
||||
c.Fatalf("Failed to tag image: %s, out: %q", err, out)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ func (s *DockerSuite) TestPullImageWithAliases(c *check.C) {
|
|||
defer setupRegistry(c)()
|
||||
|
||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||
defer deleteImages(repoName)
|
||||
|
||||
repos := []string{}
|
||||
for _, tag := range []string{"recent", "fresh"} {
|
||||
|
@ -25,7 +24,6 @@ func (s *DockerSuite) TestPullImageWithAliases(c *check.C) {
|
|||
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil {
|
||||
c.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out)
|
||||
}
|
||||
defer deleteImages(repo)
|
||||
if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil {
|
||||
c.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out))
|
||||
}
|
||||
|
@ -61,7 +59,6 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
|
|||
// unless keychain is manually updated to contain the daemon's sign key.
|
||||
|
||||
verifiedName := "hello-world"
|
||||
defer deleteImages(verifiedName)
|
||||
|
||||
// pull it
|
||||
expected := "The image you are pulling has been verified"
|
||||
|
@ -88,8 +85,6 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
|
|||
func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
|
||||
testRequires(c, Network)
|
||||
|
||||
defer deleteImages("hello-world")
|
||||
|
||||
pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
|
||||
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
|
||||
c.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err)
|
||||
|
|
|
@ -22,7 +22,6 @@ func (s *DockerSuite) TestPushBusyboxImage(c *check.C) {
|
|||
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||
c.Fatalf("image tagging failed: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoName)
|
||||
|
||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
||||
|
@ -77,12 +76,10 @@ func (s *DockerSuite) TestPushMultipleTags(c *check.C) {
|
|||
if out, _, err := runCommandWithOutput(tagCmd1); err != nil {
|
||||
c.Fatalf("image tagging failed: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoTag1)
|
||||
tagCmd2 := exec.Command(dockerBinary, "tag", "busybox", repoTag2)
|
||||
if out, _, err := runCommandWithOutput(tagCmd2); err != nil {
|
||||
c.Fatalf("image tagging failed: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoTag2)
|
||||
|
||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
||||
|
@ -97,7 +94,6 @@ func (s *DockerSuite) TestPushInterrupt(c *check.C) {
|
|||
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repoName)); err != nil {
|
||||
c.Fatalf("image tagging failed: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoName)
|
||||
|
||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||
if err := pushCmd.Start(); err != nil {
|
||||
|
|
|
@ -87,7 +87,6 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
|
|||
|
||||
// build first dockerfile
|
||||
img1, err := buildImage(img, dockerfile1, true)
|
||||
defer deleteImages(img1)
|
||||
if err != nil {
|
||||
c.Fatalf("Could not build image %s: %v", img, err)
|
||||
}
|
||||
|
|
|
@ -447,7 +447,6 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir(c *check.C) {
|
|||
if _, err := buildImage(name, dockerFile, false); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
defer deleteImages(name)
|
||||
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-v", "/test/test", name))
|
||||
if err != nil {
|
||||
|
@ -604,7 +603,6 @@ func (s *DockerSuite) TestRunCreateVolume(c *check.C) {
|
|||
// Note that this bug happens only with symlinks with a target that starts with '/'.
|
||||
func (s *DockerSuite) TestRunCreateVolumeWithSymlink(c *check.C) {
|
||||
image := "docker-test-createvolumewithsymlink"
|
||||
defer deleteImages(image)
|
||||
|
||||
buildCmd := exec.Command(dockerBinary, "build", "-t", image, "-")
|
||||
buildCmd.Stdin = strings.NewReader(`FROM busybox
|
||||
|
@ -644,7 +642,6 @@ func (s *DockerSuite) TestRunCreateVolumeWithSymlink(c *check.C) {
|
|||
// Tests that a volume path that has a symlink exists in a container mounting it with `--volumes-from`.
|
||||
func (s *DockerSuite) TestRunVolumesFromSymlinkPath(c *check.C) {
|
||||
name := "docker-test-volumesfromsymlinkpath"
|
||||
defer deleteImages(name)
|
||||
|
||||
buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-")
|
||||
buildCmd.Stdin = strings.NewReader(`FROM busybox
|
||||
|
@ -1746,7 +1743,6 @@ func (s *DockerSuite) TestRunState(c *check.C) {
|
|||
// Test for #1737
|
||||
func (s *DockerSuite) TestRunCopyVolumeUidGid(c *check.C) {
|
||||
name := "testrunvolumesuidgid"
|
||||
defer deleteImages(name)
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
|
||||
|
@ -1772,7 +1768,6 @@ func (s *DockerSuite) TestRunCopyVolumeUidGid(c *check.C) {
|
|||
// Test for #1582
|
||||
func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) {
|
||||
name := "testruncopyvolumecontent"
|
||||
defer deleteImages(name)
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
RUN mkdir -p /hello/local && echo hello > /hello/local/world`,
|
||||
|
@ -1794,7 +1789,6 @@ func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestRunCleanupCmdOnEntrypoint(c *check.C) {
|
||||
name := "testrunmdcleanuponentrypoint"
|
||||
defer deleteImages(name)
|
||||
if _, err := buildImage(name,
|
||||
`FROM busybox
|
||||
ENTRYPOINT ["echo"]
|
||||
|
@ -2349,7 +2343,6 @@ func (s *DockerSuite) TestRunCreateVolumeEtc(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) {
|
||||
defer deleteImages("dataimage")
|
||||
if _, err := buildImage("dataimage",
|
||||
`FROM busybox
|
||||
RUN mkdir -p /foo
|
||||
|
@ -2430,7 +2423,6 @@ func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) {
|
|||
true); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
defer deleteImages("run_volumes_clean_paths")
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "-v", "/foo", "-v", "/bar/", "--name", "dark_helmet", "run_volumes_clean_paths")
|
||||
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
||||
|
|
|
@ -131,7 +131,6 @@ func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
|||
repoName := "foobar-save-single-tag-test"
|
||||
|
||||
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
|
||||
defer deleteImages(repoName)
|
||||
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||
}
|
||||
|
@ -157,7 +156,6 @@ func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
|||
repoName := "foobar-save-image-id-test"
|
||||
|
||||
tagCmd := exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
|
||||
defer deleteImages(repoName)
|
||||
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||
}
|
||||
|
@ -264,7 +262,6 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
|||
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoName + "-one")
|
||||
|
||||
// Make two images
|
||||
tagCmd = exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
|
||||
|
@ -272,7 +269,6 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||
}
|
||||
defer deleteImages(repoName + "-two")
|
||||
|
||||
out, _, err = runCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)),
|
||||
|
@ -311,9 +307,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
|||
tagBar := repoName + ":bar"
|
||||
|
||||
idFoo := makeImage("busybox:latest", tagFoo)
|
||||
defer deleteImages(idFoo)
|
||||
idBar := makeImage("busybox:latest", tagBar)
|
||||
defer deleteImages(idBar)
|
||||
|
||||
deleteImages(repoName)
|
||||
|
||||
|
@ -358,7 +352,6 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
|||
os.Mkdir(extractionDirectory, 0777)
|
||||
|
||||
defer os.RemoveAll(tmpDir)
|
||||
defer deleteImages(name)
|
||||
_, err = buildImage(name,
|
||||
`FROM busybox
|
||||
RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a
|
||||
|
|
|
@ -18,9 +18,6 @@ func (s *DockerSuite) TestTagUnprefixedRepoByName(c *check.C) {
|
|||
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
|
||||
deleteImages("testfoobarbaz")
|
||||
|
||||
}
|
||||
|
||||
// tagging an image by ID in a new unprefixed repo should work
|
||||
|
@ -36,9 +33,6 @@ func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) {
|
|||
if out, _, err = runCommandWithOutput(tagCmd); err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
|
||||
deleteImages("testfoobarbaz")
|
||||
|
||||
}
|
||||
|
||||
// ensure we don't allow the use of invalid repository names; these tag operations should fail
|
||||
|
@ -104,8 +98,6 @@ func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) {
|
|||
if err == nil || !strings.Contains(out, "Conflict: Tag test is already set to image") {
|
||||
c.Fatal("tag busybox busybox:test should have failed,because busybox:test is existed")
|
||||
}
|
||||
deleteImages("busybox:test")
|
||||
|
||||
}
|
||||
|
||||
// tag an image with an existed tag name with -f option should work
|
||||
|
@ -122,8 +114,6 @@ func (s *DockerSuite) TestTagExistedNameWithForce(c *check.C) {
|
|||
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
deleteImages("busybox:test")
|
||||
|
||||
}
|
||||
|
||||
// ensure tagging using official names works
|
||||
|
|
|
@ -396,6 +396,55 @@ func deleteAllContainers() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var protectedImages = map[string]struct{}{}
|
||||
|
||||
func init() {
|
||||
out, err := exec.Command(dockerBinary, "images").CombinedOutput()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
lines := strings.Split(string(out), "\n")[1:]
|
||||
for _, l := range lines {
|
||||
if l == "" {
|
||||
continue
|
||||
}
|
||||
fields := strings.Fields(l)
|
||||
imgTag := fields[0] + ":" + fields[1]
|
||||
protectedImages[imgTag] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func deleteAllImages() error {
|
||||
out, err := exec.Command(dockerBinary, "images").CombinedOutput()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lines := strings.Split(string(out), "\n")[1:]
|
||||
var imgs []string
|
||||
for _, l := range lines {
|
||||
if l == "" {
|
||||
continue
|
||||
}
|
||||
fields := strings.Fields(l)
|
||||
imgTag := fields[0] + ":" + fields[1]
|
||||
if _, ok := protectedImages[imgTag]; !ok {
|
||||
if fields[0] == "<none>" {
|
||||
imgs = append(imgs, fields[2])
|
||||
continue
|
||||
}
|
||||
imgs = append(imgs, imgTag)
|
||||
}
|
||||
}
|
||||
if len(imgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
args := append([]string{"rmi", "-f"}, imgs...)
|
||||
if err := exec.Command(dockerBinary, args...).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPausedContainers() (string, error) {
|
||||
getPausedContainersCmd := exec.Command(dockerBinary, "ps", "-f", "status=paused", "-q", "-a")
|
||||
out, exitCode, err := runCommandWithOutput(getPausedContainersCmd)
|
||||
|
|
Loading…
Reference in a new issue