Common patterns:
- Multiple images were built with same name but only one cleanup.
- Containers were deleted after images.
- Images not removed after retagging.
Signed-off-by: Tõnis Tiigi <tonistiigi@gmail.com> (github: tonistiigi)
| ... | ... |
@@ -39,6 +39,7 @@ func TestBuildShCmdJSONEntrypoint(t *testing.T) {
|
| 39 | 39 |
exec.Command( |
| 40 | 40 |
dockerBinary, |
| 41 | 41 |
"run", |
| 42 |
+ "--rm", |
|
| 42 | 43 |
name)) |
| 43 | 44 |
|
| 44 | 45 |
if err != nil {
|
| ... | ... |
@@ -263,6 +264,8 @@ func TestBuildHandleEscapes(t *testing.T) {
|
| 263 | 263 |
t.Fatal("Could not find volume bar set from env foo in volumes table")
|
| 264 | 264 |
} |
| 265 | 265 |
|
| 266 |
+ deleteImages(name) |
|
| 267 |
+ |
|
| 266 | 268 |
_, err = buildImage(name, |
| 267 | 269 |
` |
| 268 | 270 |
FROM scratch |
| ... | ... |
@@ -287,6 +290,8 @@ func TestBuildHandleEscapes(t *testing.T) {
|
| 287 | 287 |
t.Fatal("Could not find volume ${FOO} set from env foo in volumes table")
|
| 288 | 288 |
} |
| 289 | 289 |
|
| 290 |
+ deleteImages(name) |
|
| 291 |
+ |
|
| 290 | 292 |
// this test in particular provides *7* backslashes and expects 6 to come back. |
| 291 | 293 |
// Like above, the first escape is swallowed and the rest are treated as |
| 292 | 294 |
// literals, this one is just less obvious because of all the character noise. |
| ... | ... |
@@ -355,8 +360,8 @@ func TestBuildOnBuildLowercase(t *testing.T) {
|
| 355 | 355 |
|
| 356 | 356 |
func TestBuildEnvEscapes(t *testing.T) {
|
| 357 | 357 |
name := "testbuildenvescapes" |
| 358 |
- defer deleteAllContainers() |
|
| 359 | 358 |
defer deleteImages(name) |
| 359 |
+ defer deleteAllContainers() |
|
| 360 | 360 |
_, err := buildImage(name, |
| 361 | 361 |
` |
| 362 | 362 |
FROM busybox |
| ... | ... |
@@ -380,8 +385,8 @@ func TestBuildEnvEscapes(t *testing.T) {
|
| 380 | 380 |
|
| 381 | 381 |
func TestBuildEnvOverwrite(t *testing.T) {
|
| 382 | 382 |
name := "testbuildenvoverwrite" |
| 383 |
- defer deleteAllContainers() |
|
| 384 | 383 |
defer deleteImages(name) |
| 384 |
+ defer deleteAllContainers() |
|
| 385 | 385 |
|
| 386 | 386 |
_, err := buildImage(name, |
| 387 | 387 |
` |
| ... | ... |
@@ -410,7 +415,10 @@ func TestBuildEnvOverwrite(t *testing.T) {
|
| 410 | 410 |
|
| 411 | 411 |
func TestBuildOnBuildForbiddenMaintainerInSourceImage(t *testing.T) {
|
| 412 | 412 |
name := "testbuildonbuildforbiddenmaintainerinsourceimage" |
| 413 |
+ defer deleteImages("onbuild")
|
|
| 413 | 414 |
defer deleteImages(name) |
| 415 |
+ defer deleteAllContainers() |
|
| 416 |
+ |
|
| 414 | 417 |
createCmd := exec.Command(dockerBinary, "create", "busybox", "true") |
| 415 | 418 |
out, _, _, err := runCommandWithStdoutStderr(createCmd) |
| 416 | 419 |
if err != nil {
|
| ... | ... |
@@ -441,7 +449,10 @@ func TestBuildOnBuildForbiddenMaintainerInSourceImage(t *testing.T) {
|
| 441 | 441 |
|
| 442 | 442 |
func TestBuildOnBuildForbiddenFromInSourceImage(t *testing.T) {
|
| 443 | 443 |
name := "testbuildonbuildforbiddenfrominsourceimage" |
| 444 |
+ defer deleteImages("onbuild")
|
|
| 444 | 445 |
defer deleteImages(name) |
| 446 |
+ defer deleteAllContainers() |
|
| 447 |
+ |
|
| 445 | 448 |
createCmd := exec.Command(dockerBinary, "create", "busybox", "true") |
| 446 | 449 |
out, _, _, err := runCommandWithStdoutStderr(createCmd) |
| 447 | 450 |
if err != nil {
|
| ... | ... |
@@ -472,7 +483,10 @@ func TestBuildOnBuildForbiddenFromInSourceImage(t *testing.T) {
|
| 472 | 472 |
|
| 473 | 473 |
func TestBuildOnBuildForbiddenChainedInSourceImage(t *testing.T) {
|
| 474 | 474 |
name := "testbuildonbuildforbiddenchainedinsourceimage" |
| 475 |
+ defer deleteImages("onbuild")
|
|
| 475 | 476 |
defer deleteImages(name) |
| 477 |
+ defer deleteAllContainers() |
|
| 478 |
+ |
|
| 476 | 479 |
createCmd := exec.Command(dockerBinary, "create", "busybox", "true") |
| 477 | 480 |
out, _, _, err := runCommandWithStdoutStderr(createCmd) |
| 478 | 481 |
if err != nil {
|
| ... | ... |
@@ -505,9 +519,9 @@ func TestBuildOnBuildCmdEntrypointJSON(t *testing.T) {
|
| 505 | 505 |
name1 := "onbuildcmd" |
| 506 | 506 |
name2 := "onbuildgenerated" |
| 507 | 507 |
|
| 508 |
- defer deleteAllContainers() |
|
| 509 | 508 |
defer deleteImages(name2) |
| 510 | 509 |
defer deleteImages(name1) |
| 510 |
+ defer deleteAllContainers() |
|
| 511 | 511 |
|
| 512 | 512 |
_, err := buildImage(name1, ` |
| 513 | 513 |
FROM busybox |
| ... | ... |
@@ -542,9 +556,9 @@ func TestBuildOnBuildEntrypointJSON(t *testing.T) {
|
| 542 | 542 |
name1 := "onbuildcmd" |
| 543 | 543 |
name2 := "onbuildgenerated" |
| 544 | 544 |
|
| 545 |
- defer deleteAllContainers() |
|
| 546 | 545 |
defer deleteImages(name2) |
| 547 | 546 |
defer deleteImages(name1) |
| 547 |
+ defer deleteAllContainers() |
|
| 548 | 548 |
|
| 549 | 549 |
_, err := buildImage(name1, ` |
| 550 | 550 |
FROM busybox |
| ... | ... |
@@ -590,6 +604,10 @@ func TestBuildCacheADD(t *testing.T) {
|
| 590 | 590 |
true); err != nil {
|
| 591 | 591 |
t.Fatal(err) |
| 592 | 592 |
} |
| 593 |
+ if err != nil {
|
|
| 594 |
+ t.Fatal(err) |
|
| 595 |
+ } |
|
| 596 |
+ deleteImages(name) |
|
| 593 | 597 |
_, out, err := buildImageWithOut(name, |
| 594 | 598 |
fmt.Sprintf(`FROM scratch |
| 595 | 599 |
ADD %s/index.html /`, server.URL), |
| ... | ... |
@@ -1314,9 +1332,12 @@ func TestBuildWithInaccessibleFilesInContext(t *testing.T) {
|
| 1314 | 1314 |
t.Fatal(err) |
| 1315 | 1315 |
} |
| 1316 | 1316 |
defer ctx.Close() |
| 1317 |
- if err := os.Symlink(filepath.Join(ctx.Dir, "g"), "../../../../../../../../../../../../../../../../../../../azA"); err != nil {
|
|
| 1317 |
+ |
|
| 1318 |
+ target := "../../../../../../../../../../../../../../../../../../../azA" |
|
| 1319 |
+ if err := os.Symlink(filepath.Join(ctx.Dir, "g"), target); err != nil {
|
|
| 1318 | 1320 |
t.Fatal(err) |
| 1319 | 1321 |
} |
| 1322 |
+ defer os.Remove(target) |
|
| 1320 | 1323 |
// This is used to ensure we don't follow links when checking if everything in the context is accessible |
| 1321 | 1324 |
// This test doesn't require that we run commands as an unprivileged user |
| 1322 | 1325 |
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
| ... | ... |
@@ -1668,6 +1689,7 @@ func TestBuildContextCleanup(t *testing.T) {
|
| 1668 | 1668 |
func TestBuildContextCleanupFailedBuild(t *testing.T) {
|
| 1669 | 1669 |
name := "testbuildcontextcleanup" |
| 1670 | 1670 |
defer deleteImages(name) |
| 1671 |
+ defer deleteAllContainers() |
|
| 1671 | 1672 |
entries, err := ioutil.ReadDir("/var/lib/docker/tmp")
|
| 1672 | 1673 |
if err != nil {
|
| 1673 | 1674 |
t.Fatalf("failed to list contents of tmp dir: %s", err)
|
| ... | ... |
@@ -1919,7 +1941,8 @@ func TestBuildWithCache(t *testing.T) {
|
| 1919 | 1919 |
|
| 1920 | 1920 |
func TestBuildWithoutCache(t *testing.T) {
|
| 1921 | 1921 |
name := "testbuildwithoutcache" |
| 1922 |
- defer deleteImages(name) |
|
| 1922 |
+ name2 := "testbuildwithoutcache2" |
|
| 1923 |
+ defer deleteImages(name, name2) |
|
| 1923 | 1924 |
id1, err := buildImage(name, |
| 1924 | 1925 |
`FROM scratch |
| 1925 | 1926 |
MAINTAINER dockerio |
| ... | ... |
@@ -1929,7 +1952,8 @@ func TestBuildWithoutCache(t *testing.T) {
|
| 1929 | 1929 |
if err != nil {
|
| 1930 | 1930 |
t.Fatal(err) |
| 1931 | 1931 |
} |
| 1932 |
- id2, err := buildImage(name, |
|
| 1932 |
+ |
|
| 1933 |
+ id2, err := buildImage(name2, |
|
| 1933 | 1934 |
`FROM scratch |
| 1934 | 1935 |
MAINTAINER dockerio |
| 1935 | 1936 |
EXPOSE 5432 |
| ... | ... |
@@ -1946,7 +1970,8 @@ func TestBuildWithoutCache(t *testing.T) {
|
| 1946 | 1946 |
|
| 1947 | 1947 |
func TestBuildADDLocalFileWithCache(t *testing.T) {
|
| 1948 | 1948 |
name := "testbuildaddlocalfilewithcache" |
| 1949 |
- defer deleteImages(name) |
|
| 1949 |
+ name2 := "testbuildaddlocalfilewithcache2" |
|
| 1950 |
+ defer deleteImages(name, name2) |
|
| 1950 | 1951 |
dockerfile := ` |
| 1951 | 1952 |
FROM busybox |
| 1952 | 1953 |
MAINTAINER dockerio |
| ... | ... |
@@ -1963,7 +1988,7 @@ func TestBuildADDLocalFileWithCache(t *testing.T) {
|
| 1963 | 1963 |
if err != nil {
|
| 1964 | 1964 |
t.Fatal(err) |
| 1965 | 1965 |
} |
| 1966 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
| 1966 |
+ id2, err := buildImageFromContext(name2, ctx, true) |
|
| 1967 | 1967 |
if err != nil {
|
| 1968 | 1968 |
t.Fatal(err) |
| 1969 | 1969 |
} |
| ... | ... |
@@ -1975,7 +2000,8 @@ func TestBuildADDLocalFileWithCache(t *testing.T) {
|
| 1975 | 1975 |
|
| 1976 | 1976 |
func TestBuildADDMultipleLocalFileWithCache(t *testing.T) {
|
| 1977 | 1977 |
name := "testbuildaddmultiplelocalfilewithcache" |
| 1978 |
- defer deleteImages(name) |
|
| 1978 |
+ name2 := "testbuildaddmultiplelocalfilewithcache2" |
|
| 1979 |
+ defer deleteImages(name, name2) |
|
| 1979 | 1980 |
dockerfile := ` |
| 1980 | 1981 |
FROM busybox |
| 1981 | 1982 |
MAINTAINER dockerio |
| ... | ... |
@@ -1992,7 +2018,7 @@ func TestBuildADDMultipleLocalFileWithCache(t *testing.T) {
|
| 1992 | 1992 |
if err != nil {
|
| 1993 | 1993 |
t.Fatal(err) |
| 1994 | 1994 |
} |
| 1995 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
| 1995 |
+ id2, err := buildImageFromContext(name2, ctx, true) |
|
| 1996 | 1996 |
if err != nil {
|
| 1997 | 1997 |
t.Fatal(err) |
| 1998 | 1998 |
} |
| ... | ... |
@@ -2004,7 +2030,8 @@ func TestBuildADDMultipleLocalFileWithCache(t *testing.T) {
|
| 2004 | 2004 |
|
| 2005 | 2005 |
func TestBuildADDLocalFileWithoutCache(t *testing.T) {
|
| 2006 | 2006 |
name := "testbuildaddlocalfilewithoutcache" |
| 2007 |
- defer deleteImages(name) |
|
| 2007 |
+ name2 := "testbuildaddlocalfilewithoutcache2" |
|
| 2008 |
+ defer deleteImages(name, name2) |
|
| 2008 | 2009 |
dockerfile := ` |
| 2009 | 2010 |
FROM busybox |
| 2010 | 2011 |
MAINTAINER dockerio |
| ... | ... |
@@ -2021,7 +2048,7 @@ func TestBuildADDLocalFileWithoutCache(t *testing.T) {
|
| 2021 | 2021 |
if err != nil {
|
| 2022 | 2022 |
t.Fatal(err) |
| 2023 | 2023 |
} |
| 2024 |
- id2, err := buildImageFromContext(name, ctx, false) |
|
| 2024 |
+ id2, err := buildImageFromContext(name2, ctx, false) |
|
| 2025 | 2025 |
if err != nil {
|
| 2026 | 2026 |
t.Fatal(err) |
| 2027 | 2027 |
} |
| ... | ... |
@@ -2033,7 +2060,8 @@ func TestBuildADDLocalFileWithoutCache(t *testing.T) {
|
| 2033 | 2033 |
|
| 2034 | 2034 |
func TestBuildCopyDirButNotFile(t *testing.T) {
|
| 2035 | 2035 |
name := "testbuildcopydirbutnotfile" |
| 2036 |
- defer deleteImages(name) |
|
| 2036 |
+ name2 := "testbuildcopydirbutnotfile2" |
|
| 2037 |
+ defer deleteImages(name, name2) |
|
| 2037 | 2038 |
dockerfile := ` |
| 2038 | 2039 |
FROM scratch |
| 2039 | 2040 |
COPY dir /tmp/` |
| ... | ... |
@@ -2052,7 +2080,7 @@ func TestBuildCopyDirButNotFile(t *testing.T) {
|
| 2052 | 2052 |
if err := ctx.Add("dir_file", "hello2"); err != nil {
|
| 2053 | 2053 |
t.Fatal(err) |
| 2054 | 2054 |
} |
| 2055 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
| 2055 |
+ id2, err := buildImageFromContext(name2, ctx, true) |
|
| 2056 | 2056 |
if err != nil {
|
| 2057 | 2057 |
t.Fatal(err) |
| 2058 | 2058 |
} |
| ... | ... |
@@ -2064,7 +2092,11 @@ func TestBuildCopyDirButNotFile(t *testing.T) {
|
| 2064 | 2064 |
|
| 2065 | 2065 |
func TestBuildADDCurrentDirWithCache(t *testing.T) {
|
| 2066 | 2066 |
name := "testbuildaddcurrentdirwithcache" |
| 2067 |
- defer deleteImages(name) |
|
| 2067 |
+ name2 := name + "2" |
|
| 2068 |
+ name3 := name + "3" |
|
| 2069 |
+ name4 := name + "4" |
|
| 2070 |
+ name5 := name + "5" |
|
| 2071 |
+ defer deleteImages(name, name2, name3, name4, name5) |
|
| 2068 | 2072 |
dockerfile := ` |
| 2069 | 2073 |
FROM scratch |
| 2070 | 2074 |
MAINTAINER dockerio |
| ... | ... |
@@ -2084,7 +2116,7 @@ func TestBuildADDCurrentDirWithCache(t *testing.T) {
|
| 2084 | 2084 |
if err := ctx.Add("bar", "hello2"); err != nil {
|
| 2085 | 2085 |
t.Fatal(err) |
| 2086 | 2086 |
} |
| 2087 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
| 2087 |
+ id2, err := buildImageFromContext(name2, ctx, true) |
|
| 2088 | 2088 |
if err != nil {
|
| 2089 | 2089 |
t.Fatal(err) |
| 2090 | 2090 |
} |
| ... | ... |
@@ -2095,7 +2127,7 @@ func TestBuildADDCurrentDirWithCache(t *testing.T) {
|
| 2095 | 2095 |
if err := ctx.Add("foo", "hello1"); err != nil {
|
| 2096 | 2096 |
t.Fatal(err) |
| 2097 | 2097 |
} |
| 2098 |
- id3, err := buildImageFromContext(name, ctx, true) |
|
| 2098 |
+ id3, err := buildImageFromContext(name3, ctx, true) |
|
| 2099 | 2099 |
if err != nil {
|
| 2100 | 2100 |
t.Fatal(err) |
| 2101 | 2101 |
} |
| ... | ... |
@@ -2107,14 +2139,14 @@ func TestBuildADDCurrentDirWithCache(t *testing.T) {
|
| 2107 | 2107 |
if err := ctx.Add("foo", "hello1"); err != nil {
|
| 2108 | 2108 |
t.Fatal(err) |
| 2109 | 2109 |
} |
| 2110 |
- id4, err := buildImageFromContext(name, ctx, true) |
|
| 2110 |
+ id4, err := buildImageFromContext(name4, ctx, true) |
|
| 2111 | 2111 |
if err != nil {
|
| 2112 | 2112 |
t.Fatal(err) |
| 2113 | 2113 |
} |
| 2114 | 2114 |
if id3 == id4 {
|
| 2115 | 2115 |
t.Fatal("The cache should have been invalided but hasn't.")
|
| 2116 | 2116 |
} |
| 2117 |
- id5, err := buildImageFromContext(name, ctx, true) |
|
| 2117 |
+ id5, err := buildImageFromContext(name5, ctx, true) |
|
| 2118 | 2118 |
if err != nil {
|
| 2119 | 2119 |
t.Fatal(err) |
| 2120 | 2120 |
} |
| ... | ... |
@@ -2126,7 +2158,8 @@ func TestBuildADDCurrentDirWithCache(t *testing.T) {
|
| 2126 | 2126 |
|
| 2127 | 2127 |
func TestBuildADDCurrentDirWithoutCache(t *testing.T) {
|
| 2128 | 2128 |
name := "testbuildaddcurrentdirwithoutcache" |
| 2129 |
- defer deleteImages(name) |
|
| 2129 |
+ name2 := "testbuildaddcurrentdirwithoutcache2" |
|
| 2130 |
+ defer deleteImages(name, name2) |
|
| 2130 | 2131 |
dockerfile := ` |
| 2131 | 2132 |
FROM scratch |
| 2132 | 2133 |
MAINTAINER dockerio |
| ... | ... |
@@ -2142,7 +2175,7 @@ func TestBuildADDCurrentDirWithoutCache(t *testing.T) {
|
| 2142 | 2142 |
if err != nil {
|
| 2143 | 2143 |
t.Fatal(err) |
| 2144 | 2144 |
} |
| 2145 |
- id2, err := buildImageFromContext(name, ctx, false) |
|
| 2145 |
+ id2, err := buildImageFromContext(name2, ctx, false) |
|
| 2146 | 2146 |
if err != nil {
|
| 2147 | 2147 |
t.Fatal(err) |
| 2148 | 2148 |
} |
| ... | ... |
@@ -2186,7 +2219,8 @@ func TestBuildADDRemoteFileWithCache(t *testing.T) {
|
| 2186 | 2186 |
|
| 2187 | 2187 |
func TestBuildADDRemoteFileWithoutCache(t *testing.T) {
|
| 2188 | 2188 |
name := "testbuildaddremotefilewithoutcache" |
| 2189 |
- defer deleteImages(name) |
|
| 2189 |
+ name2 := "testbuildaddremotefilewithoutcache2" |
|
| 2190 |
+ defer deleteImages(name, name2) |
|
| 2190 | 2191 |
server, err := fakeStorage(map[string]string{
|
| 2191 | 2192 |
"baz": "hello", |
| 2192 | 2193 |
}) |
| ... | ... |
@@ -2202,7 +2236,7 @@ func TestBuildADDRemoteFileWithoutCache(t *testing.T) {
|
| 2202 | 2202 |
if err != nil {
|
| 2203 | 2203 |
t.Fatal(err) |
| 2204 | 2204 |
} |
| 2205 |
- id2, err := buildImage(name, |
|
| 2205 |
+ id2, err := buildImage(name2, |
|
| 2206 | 2206 |
fmt.Sprintf(`FROM scratch |
| 2207 | 2207 |
MAINTAINER dockerio |
| 2208 | 2208 |
ADD %s/baz /usr/lib/baz/quux`, server.URL), |
| ... | ... |
@@ -2218,7 +2252,11 @@ func TestBuildADDRemoteFileWithoutCache(t *testing.T) {
|
| 2218 | 2218 |
|
| 2219 | 2219 |
func TestBuildADDRemoteFileMTime(t *testing.T) {
|
| 2220 | 2220 |
name := "testbuildaddremotefilemtime" |
| 2221 |
- defer deleteImages(name) |
|
| 2221 |
+ name2 := name + "2" |
|
| 2222 |
+ name3 := name + "3" |
|
| 2223 |
+ name4 := name + "4" |
|
| 2224 |
+ |
|
| 2225 |
+ defer deleteImages(name, name2, name3, name4) |
|
| 2222 | 2226 |
|
| 2223 | 2227 |
server, err := fakeStorage(map[string]string{"baz": "hello"})
|
| 2224 | 2228 |
if err != nil {
|
| ... | ... |
@@ -2239,7 +2277,7 @@ func TestBuildADDRemoteFileMTime(t *testing.T) {
|
| 2239 | 2239 |
t.Fatal(err) |
| 2240 | 2240 |
} |
| 2241 | 2241 |
|
| 2242 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
| 2242 |
+ id2, err := buildImageFromContext(name2, ctx, true) |
|
| 2243 | 2243 |
if err != nil {
|
| 2244 | 2244 |
t.Fatal(err) |
| 2245 | 2245 |
} |
| ... | ... |
@@ -2255,7 +2293,7 @@ func TestBuildADDRemoteFileMTime(t *testing.T) {
|
| 2255 | 2255 |
t.Fatalf("Error setting mtime on %q: %v", bazPath, err)
|
| 2256 | 2256 |
} |
| 2257 | 2257 |
|
| 2258 |
- id3, err := buildImageFromContext(name, ctx, true) |
|
| 2258 |
+ id3, err := buildImageFromContext(name3, ctx, true) |
|
| 2259 | 2259 |
if err != nil {
|
| 2260 | 2260 |
t.Fatal(err) |
| 2261 | 2261 |
} |
| ... | ... |
@@ -2264,7 +2302,7 @@ func TestBuildADDRemoteFileMTime(t *testing.T) {
|
| 2264 | 2264 |
} |
| 2265 | 2265 |
|
| 2266 | 2266 |
// And for good measure do it again and make sure cache is used this time |
| 2267 |
- id4, err := buildImageFromContext(name, ctx, true) |
|
| 2267 |
+ id4, err := buildImageFromContext(name4, ctx, true) |
|
| 2268 | 2268 |
if err != nil {
|
| 2269 | 2269 |
t.Fatal(err) |
| 2270 | 2270 |
} |
| ... | ... |
@@ -2353,7 +2391,7 @@ func TestBuildNoContext(t *testing.T) {
|
| 2353 | 2353 |
t.Fatalf("build failed to complete: %v %v", out, err)
|
| 2354 | 2354 |
} |
| 2355 | 2355 |
|
| 2356 |
- if out, _, err := cmd(t, "run", "nocontext"); out != "ok\n" || err != nil {
|
|
| 2356 |
+ if out, _, err := cmd(t, "run", "--rm", "nocontext"); out != "ok\n" || err != nil {
|
|
| 2357 | 2357 |
t.Fatalf("run produced invalid output: %q, expected %q", out, "ok")
|
| 2358 | 2358 |
} |
| 2359 | 2359 |
|
| ... | ... |
@@ -2364,7 +2402,8 @@ func TestBuildNoContext(t *testing.T) {
|
| 2364 | 2364 |
// TODO: TestCaching |
| 2365 | 2365 |
func TestBuildADDLocalAndRemoteFilesWithoutCache(t *testing.T) {
|
| 2366 | 2366 |
name := "testbuildaddlocalandremotefilewithoutcache" |
| 2367 |
- defer deleteImages(name) |
|
| 2367 |
+ name2 := "testbuildaddlocalandremotefilewithoutcache2" |
|
| 2368 |
+ defer deleteImages(name, name2) |
|
| 2368 | 2369 |
server, err := fakeStorage(map[string]string{
|
| 2369 | 2370 |
"baz": "hello", |
| 2370 | 2371 |
}) |
| ... | ... |
@@ -2387,7 +2426,7 @@ func TestBuildADDLocalAndRemoteFilesWithoutCache(t *testing.T) {
|
| 2387 | 2387 |
if err != nil {
|
| 2388 | 2388 |
t.Fatal(err) |
| 2389 | 2389 |
} |
| 2390 |
- id2, err := buildImageFromContext(name, ctx, false) |
|
| 2390 |
+ id2, err := buildImageFromContext(name2, ctx, false) |
|
| 2391 | 2391 |
if err != nil {
|
| 2392 | 2392 |
t.Fatal(err) |
| 2393 | 2393 |
} |
| ... | ... |
@@ -2552,6 +2591,7 @@ func TestBuildInheritance(t *testing.T) {
|
| 2552 | 2552 |
func TestBuildFails(t *testing.T) {
|
| 2553 | 2553 |
name := "testbuildfails" |
| 2554 | 2554 |
defer deleteImages(name) |
| 2555 |
+ defer deleteAllContainers() |
|
| 2555 | 2556 |
_, err := buildImage(name, |
| 2556 | 2557 |
`FROM busybox |
| 2557 | 2558 |
RUN sh -c "exit 23"`, |
| ... | ... |
@@ -3217,6 +3257,7 @@ func TestBuildIgnoreInvalidInstruction(t *testing.T) {
|
| 3217 | 3217 |
|
| 3218 | 3218 |
func TestBuildEntrypointInheritance(t *testing.T) {
|
| 3219 | 3219 |
defer deleteImages("parent", "child")
|
| 3220 |
+ defer deleteAllContainers() |
|
| 3220 | 3221 |
|
| 3221 | 3222 |
if _, err := buildImage("parent", `
|
| 3222 | 3223 |
FROM busybox |
| ... | ... |
@@ -3255,6 +3296,7 @@ func TestBuildEntrypointInheritanceInspect(t *testing.T) {
|
| 3255 | 3255 |
) |
| 3256 | 3256 |
|
| 3257 | 3257 |
defer deleteImages(name, name2) |
| 3258 |
+ defer deleteAllContainers() |
|
| 3258 | 3259 |
|
| 3259 | 3260 |
if _, err := buildImage(name, "FROM busybox\nENTRYPOINT /foo/bar", true); err != nil {
|
| 3260 | 3261 |
t.Fatal(err) |
| ... | ... |
@@ -3298,7 +3340,7 @@ func TestBuildRunShEntrypoint(t *testing.T) {
|
| 3298 | 3298 |
t.Fatal(err) |
| 3299 | 3299 |
} |
| 3300 | 3300 |
|
| 3301 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", name)) |
|
| 3301 |
+ out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name)) |
|
| 3302 | 3302 |
|
| 3303 | 3303 |
if err != nil {
|
| 3304 | 3304 |
t.Fatal(err, out) |
| ... | ... |
@@ -3345,12 +3387,13 @@ func TestBuildVerifySingleQuoteFails(t *testing.T) {
|
| 3345 | 3345 |
// it should barf on it. |
| 3346 | 3346 |
name := "testbuildsinglequotefails" |
| 3347 | 3347 |
defer deleteImages(name) |
| 3348 |
+ defer deleteAllContainers() |
|
| 3348 | 3349 |
|
| 3349 | 3350 |
_, err := buildImage(name, |
| 3350 | 3351 |
`FROM busybox |
| 3351 | 3352 |
CMD [ '/bin/sh', '-c', 'echo hi' ]`, |
| 3352 | 3353 |
true) |
| 3353 |
- _, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", name)) |
|
| 3354 |
+ _, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name)) |
|
| 3354 | 3355 |
|
| 3355 | 3356 |
if err == nil {
|
| 3356 | 3357 |
t.Fatal("The image was not supposed to be able to run")
|
| ... | ... |
@@ -154,6 +154,9 @@ func TestCommitHardlink(t *testing.T) {
|
| 154 | 154 |
} |
| 155 | 155 |
|
| 156 | 156 |
func TestCommitTTY(t *testing.T) {
|
| 157 |
+ defer deleteImages("ttytest")
|
|
| 158 |
+ defer deleteAllContainers() |
|
| 159 |
+ |
|
| 157 | 160 |
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls") |
| 158 | 161 |
if _, err := runCommand(cmd); err != nil {
|
| 159 | 162 |
t.Fatal(err) |
| ... | ... |
@@ -38,11 +38,15 @@ func TestEventsUntag(t *testing.T) {
|
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
func TestEventsPause(t *testing.T) {
|
| 41 |
+ name := "testeventpause" |
|
| 41 | 42 |
out, _, _ := cmd(t, "images", "-q") |
| 42 | 43 |
image := strings.Split(out, "\n")[0] |
| 43 |
- cmd(t, "run", "-d", "--name", "testeventpause", image, "sleep", "2") |
|
| 44 |
- cmd(t, "pause", "testeventpause") |
|
| 45 |
- cmd(t, "unpause", "testeventpause") |
|
| 44 |
+ cmd(t, "run", "-d", "--name", name, image, "sleep", "2") |
|
| 45 |
+ cmd(t, "pause", name) |
|
| 46 |
+ cmd(t, "unpause", name) |
|
| 47 |
+ |
|
| 48 |
+ defer deleteAllContainers() |
|
| 49 |
+ |
|
| 46 | 50 |
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", time.Now().Unix()))
|
| 47 | 51 |
out, _, _ = runCommandWithOutput(eventsCmd) |
| 48 | 52 |
events := strings.Split(out, "\n") |
| ... | ... |
@@ -60,10 +64,17 @@ func TestEventsPause(t *testing.T) {
|
| 60 | 60 |
t.Fatalf("event should be pause, not %#v", unpauseEvent)
|
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
+ waitCmd := exec.Command(dockerBinary, "wait", name) |
|
| 64 |
+ if waitOut, _, err := runCommandWithOutput(waitCmd); err != nil {
|
|
| 65 |
+ t.Fatalf("error thrown while waiting for container: %s, %v", waitOut, err)
|
|
| 66 |
+ } |
|
| 67 |
+ |
|
| 63 | 68 |
logDone("events - pause/unpause is logged")
|
| 64 | 69 |
} |
| 65 | 70 |
|
| 66 | 71 |
func TestEventsContainerFailStartDie(t *testing.T) {
|
| 72 |
+ defer deleteAllContainers() |
|
| 73 |
+ |
|
| 67 | 74 |
out, _, _ := cmd(t, "images", "-q") |
| 68 | 75 |
image := strings.Split(out, "\n")[0] |
| 69 | 76 |
eventsCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testeventdie", image, "blerg") |
| ... | ... |
@@ -93,6 +104,7 @@ func TestEventsContainerFailStartDie(t *testing.T) {
|
| 93 | 93 |
} |
| 94 | 94 |
|
| 95 | 95 |
func TestEventsLimit(t *testing.T) {
|
| 96 |
+ defer deleteAllContainers() |
|
| 96 | 97 |
for i := 0; i < 30; i++ {
|
| 97 | 98 |
cmd(t, "run", "busybox", "echo", strconv.Itoa(i)) |
| 98 | 99 |
} |
| ... | ... |
@@ -241,6 +253,8 @@ func TestEventsImagePull(t *testing.T) {
|
| 241 | 241 |
func TestEventsImageImport(t *testing.T) {
|
| 242 | 242 |
since := time.Now().Unix() |
| 243 | 243 |
|
| 244 |
+ defer deleteImages("cirros")
|
|
| 245 |
+ |
|
| 244 | 246 |
server, err := fileServer(map[string]string{
|
| 245 | 247 |
"/cirros.tar.gz": "/cirros.tar.gz", |
| 246 | 248 |
}) |
| ... | ... |
@@ -249,7 +263,7 @@ func TestEventsImageImport(t *testing.T) {
|
| 249 | 249 |
} |
| 250 | 250 |
defer server.Close() |
| 251 | 251 |
fileURL := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
|
| 252 |
- importCmd := exec.Command(dockerBinary, "import", fileURL) |
|
| 252 |
+ importCmd := exec.Command(dockerBinary, "import", fileURL, "cirros") |
|
| 253 | 253 |
out, _, err := runCommandWithOutput(importCmd) |
| 254 | 254 |
if err != nil {
|
| 255 | 255 |
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
| ... | ... |
@@ -16,7 +16,7 @@ func TestImportDisplay(t *testing.T) {
|
| 16 | 16 |
} |
| 17 | 17 |
defer server.Close() |
| 18 | 18 |
fileURL := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
|
| 19 |
- importCmd := exec.Command(dockerBinary, "import", fileURL) |
|
| 19 |
+ importCmd := exec.Command(dockerBinary, "import", fileURL, "cirros") |
|
| 20 | 20 |
out, _, err := runCommandWithOutput(importCmd) |
| 21 | 21 |
if err != nil {
|
| 22 | 22 |
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
| ... | ... |
@@ -26,5 +26,7 @@ func TestImportDisplay(t *testing.T) {
|
| 26 | 26 |
t.Fatalf("display is messed up: %d '\\n' instead of 2", n)
|
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 |
+ deleteImages("cirros")
|
|
| 30 |
+ |
|
| 29 | 31 |
logDone("import - cirros was imported and display is fine")
|
| 30 | 32 |
} |
| ... | ... |
@@ -563,7 +563,8 @@ func TestRunCreateVolumeWithSymlink(t *testing.T) {
|
| 563 | 563 |
|
| 564 | 564 |
// Tests that a volume path that has a symlink exists in a container mounting it with `--volumes-from`. |
| 565 | 565 |
func TestRunVolumesFromSymlinkPath(t *testing.T) {
|
| 566 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "docker-test-volumesfromsymlinkpath", "-") |
|
| 566 |
+ name := "docker-test-volumesfromsymlinkpath" |
|
| 567 |
+ buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-") |
|
| 567 | 568 |
buildCmd.Stdin = strings.NewReader(`FROM busybox |
| 568 | 569 |
RUN mkdir /baz && ln -s /baz /foo |
| 569 | 570 |
VOLUME ["/foo/bar"]`) |
| ... | ... |
@@ -573,7 +574,7 @@ func TestRunVolumesFromSymlinkPath(t *testing.T) {
|
| 573 | 573 |
t.Fatalf("could not build 'docker-test-volumesfromsymlinkpath': %v", err)
|
| 574 | 574 |
} |
| 575 | 575 |
|
| 576 |
- cmd := exec.Command(dockerBinary, "run", "--name", "test-volumesfromsymlinkpath", "docker-test-volumesfromsymlinkpath") |
|
| 576 |
+ cmd := exec.Command(dockerBinary, "run", "--name", "test-volumesfromsymlinkpath", name) |
|
| 577 | 577 |
exitCode, err := runCommand(cmd) |
| 578 | 578 |
if err != nil || exitCode != 0 {
|
| 579 | 579 |
t.Fatalf("[run] (volume) err: %v, exitcode: %d", err, exitCode)
|
| ... | ... |
@@ -585,8 +586,8 @@ func TestRunVolumesFromSymlinkPath(t *testing.T) {
|
| 585 | 585 |
t.Fatalf("[run] err: %v, exitcode: %d", err, exitCode)
|
| 586 | 586 |
} |
| 587 | 587 |
|
| 588 |
- deleteImages("docker-test-volumesfromsymlinkpath")
|
|
| 589 | 588 |
deleteAllContainers() |
| 589 |
+ deleteImages(name) |
|
| 590 | 590 |
|
| 591 | 591 |
logDone("run - volumes-from symlink path")
|
| 592 | 592 |
} |
| ... | ... |
@@ -892,6 +893,7 @@ func TestRunUnPrivilegedCanMknod(t *testing.T) {
|
| 892 | 892 |
} |
| 893 | 893 |
|
| 894 | 894 |
func TestRunCapDropInvalid(t *testing.T) {
|
| 895 |
+ defer deleteAllContainers() |
|
| 895 | 896 |
cmd := exec.Command(dockerBinary, "run", "--cap-drop=CHPASS", "busybox", "ls") |
| 896 | 897 |
out, _, err := runCommandWithOutput(cmd) |
| 897 | 898 |
if err == nil {
|
| ... | ... |
@@ -962,6 +964,8 @@ func TestRunCapDropALLAddMknodCannotMknod(t *testing.T) {
|
| 962 | 962 |
} |
| 963 | 963 |
|
| 964 | 964 |
func TestRunCapAddInvalid(t *testing.T) {
|
| 965 |
+ defer deleteAllContainers() |
|
| 966 |
+ |
|
| 965 | 967 |
cmd := exec.Command(dockerBinary, "run", "--cap-add=CHPASS", "busybox", "ls") |
| 966 | 968 |
out, _, err := runCommandWithOutput(cmd) |
| 967 | 969 |
if err == nil {
|
| ... | ... |
@@ -1718,6 +1722,8 @@ func TestRunExitOnStdinClose(t *testing.T) {
|
| 1718 | 1718 |
|
| 1719 | 1719 |
// Test for #2267 |
| 1720 | 1720 |
func TestRunWriteHostsFileAndNotCommit(t *testing.T) {
|
| 1721 |
+ defer deleteAllContainers() |
|
| 1722 |
+ |
|
| 1721 | 1723 |
name := "writehosts" |
| 1722 | 1724 |
cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hosts && cat /etc/hosts") |
| 1723 | 1725 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -1745,6 +1751,8 @@ func TestRunWriteHostsFileAndNotCommit(t *testing.T) {
|
| 1745 | 1745 |
|
| 1746 | 1746 |
// Test for #2267 |
| 1747 | 1747 |
func TestRunWriteHostnameFileAndNotCommit(t *testing.T) {
|
| 1748 |
+ defer deleteAllContainers() |
|
| 1749 |
+ |
|
| 1748 | 1750 |
name := "writehostname" |
| 1749 | 1751 |
cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hostname && cat /etc/hostname") |
| 1750 | 1752 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -1772,6 +1780,8 @@ func TestRunWriteHostnameFileAndNotCommit(t *testing.T) {
|
| 1772 | 1772 |
|
| 1773 | 1773 |
// Test for #2267 |
| 1774 | 1774 |
func TestRunWriteResolvFileAndNotCommit(t *testing.T) {
|
| 1775 |
+ defer deleteAllContainers() |
|
| 1776 |
+ |
|
| 1775 | 1777 |
name := "writeresolv" |
| 1776 | 1778 |
cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/resolv.conf && cat /etc/resolv.conf") |
| 1777 | 1779 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -1798,6 +1808,8 @@ func TestRunWriteResolvFileAndNotCommit(t *testing.T) {
|
| 1798 | 1798 |
} |
| 1799 | 1799 |
|
| 1800 | 1800 |
func TestRunWithBadDevice(t *testing.T) {
|
| 1801 |
+ defer deleteAllContainers() |
|
| 1802 |
+ |
|
| 1801 | 1803 |
name := "baddevice" |
| 1802 | 1804 |
cmd := exec.Command(dockerBinary, "run", "--name", name, "--device", "/etc", "busybox", "true") |
| 1803 | 1805 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -1812,6 +1824,8 @@ func TestRunWithBadDevice(t *testing.T) {
|
| 1812 | 1812 |
} |
| 1813 | 1813 |
|
| 1814 | 1814 |
func TestRunEntrypoint(t *testing.T) {
|
| 1815 |
+ defer deleteAllContainers() |
|
| 1816 |
+ |
|
| 1815 | 1817 |
name := "entrypoint" |
| 1816 | 1818 |
cmd := exec.Command(dockerBinary, "run", "--name", name, "--entrypoint", "/bin/echo", "busybox", "-n", "foobar") |
| 1817 | 1819 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -1826,6 +1840,8 @@ func TestRunEntrypoint(t *testing.T) {
|
| 1826 | 1826 |
} |
| 1827 | 1827 |
|
| 1828 | 1828 |
func TestRunBindMounts(t *testing.T) {
|
| 1829 |
+ defer deleteAllContainers() |
|
| 1830 |
+ |
|
| 1829 | 1831 |
tmpDir, err := ioutil.TempDir("", "docker-test-container")
|
| 1830 | 1832 |
if err != nil {
|
| 1831 | 1833 |
t.Fatal(err) |
| ... | ... |
@@ -2435,8 +2451,6 @@ func TestRunNoOutputFromPullInStdout(t *testing.T) {
|
| 2435 | 2435 |
} |
| 2436 | 2436 |
|
| 2437 | 2437 |
func TestRunVolumesCleanPaths(t *testing.T) {
|
| 2438 |
- defer deleteAllContainers() |
|
| 2439 |
- |
|
| 2440 | 2438 |
if _, err := buildImage("run_volumes_clean_paths",
|
| 2441 | 2439 |
`FROM busybox |
| 2442 | 2440 |
VOLUME /foo/`, |
| ... | ... |
@@ -2444,6 +2458,7 @@ func TestRunVolumesCleanPaths(t *testing.T) {
|
| 2444 | 2444 |
t.Fatal(err) |
| 2445 | 2445 |
} |
| 2446 | 2446 |
defer deleteImages("run_volumes_clean_paths")
|
| 2447 |
+ defer deleteAllContainers() |
|
| 2447 | 2448 |
|
| 2448 | 2449 |
cmd := exec.Command(dockerBinary, "run", "-v", "/foo", "-v", "/bar/", "--name", "dark_helmet", "run_volumes_clean_paths") |
| 2449 | 2450 |
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
| ... | ... |
@@ -239,12 +239,15 @@ func TestSaveMultipleNames(t *testing.T) {
|
| 239 | 239 |
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
| 240 | 240 |
t.Fatalf("failed to tag repo: %s, %v", out, err)
|
| 241 | 241 |
} |
| 242 |
+ defer deleteImages(repoName + "-one") |
|
| 243 |
+ |
|
| 242 | 244 |
// Make two images |
| 243 | 245 |
tagCmdFinal = fmt.Sprintf("%v tag scratch:latest %v-two:latest", dockerBinary, repoName)
|
| 244 | 246 |
tagCmd = exec.Command("bash", "-c", tagCmdFinal)
|
| 245 | 247 |
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
| 246 | 248 |
t.Fatalf("failed to tag repo: %s, %v", out, err)
|
| 247 | 249 |
} |
| 250 |
+ defer deleteImages(repoName + "-two") |
|
| 248 | 251 |
|
| 249 | 252 |
saveCmdFinal := fmt.Sprintf("%v save %v-one %v-two:latest | tar xO repositories | grep -q -E '(-one|-two)'", dockerBinary, repoName, repoName)
|
| 250 | 253 |
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|