Browse code

Use dockerCmd when possible (#14603)

- integration-cli/docker_cli_attach_test.go
- integration-cli/docker_cli_attach_unix_test.go
- integration-cli/docker_cli_build_test.go
- integration-cli/docker_cli_build_unix_test.go
- integration-cli/docker_cli_by_digest_test.go
- integration-cli/docker_cli_commit_test.go
- integration-cli/docker_cli_config_test.go
- integration-cli/docker_cli_cp_test.go
- integration-cli/docker_cli_create_test.go
- integration-cli/docker_cli_pause_test.go
- integration-cli/docker_cli_port_test.go
- integration-cli/docker_cli_port_unix_test.go
- integration-cli/docker_cli_proxy_test.go
- integration-cli/docker_cli_ps_test.go
- integration-cli/docker_cli_pull_test.go
- integration-cli/docker_cli_push_test.go

- docker_api_attach_test.go
- docker_api_containers_test.go
- docker_api_events_test.go
- docker_api_exec_resize_test.go
- docker_api_exec_test.go
- docker_api_images_test.go
- docker_api_info_test.go

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2015/07/14 15:35:36
Showing 23 changed files
... ...
@@ -5,7 +5,6 @@ import (
5 5
 	"io"
6 6
 	"net/http"
7 7
 	"net/http/httputil"
8
-	"os/exec"
9 8
 	"strings"
10 9
 	"time"
11 10
 
... ...
@@ -14,11 +13,7 @@ import (
14 14
 )
15 15
 
16 16
 func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) {
17
-	runCmd := exec.Command(dockerBinary, "run", "-dit", "busybox", "cat")
18
-	out, _, err := runCommandWithOutput(runCmd)
19
-	if err != nil {
20
-		c.Fatalf(out, err)
21
-	}
17
+	out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat")
22 18
 
23 19
 	rwc, err := sockConn(time.Duration(10 * time.Second))
24 20
 	if err != nil {
... ...
@@ -102,9 +97,7 @@ func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *check.C) {
102 102
 }
103 103
 
104 104
 func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
105
-	runCmd := exec.Command(dockerBinary, "run", "-dit", "busybox", "cat")
106
-	out, _, err := runCommandWithOutput(runCmd)
107
-	c.Assert(err, check.IsNil)
105
+	out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat")
108 106
 
109 107
 	r, w := io.Pipe()
110 108
 	defer r.Close()
... ...
@@ -167,9 +160,7 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
167 167
 }
168 168
 
169 169
 func (s *DockerSuite) TestPostContainersAttachStderr(c *check.C) {
170
-	runCmd := exec.Command(dockerBinary, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2")
171
-	out, _, err := runCommandWithOutput(runCmd)
172
-	c.Assert(err, check.IsNil)
170
+	out, _ := dockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2")
173 171
 
174 172
 	r, w := io.Pipe()
175 173
 	defer r.Close()
... ...
@@ -8,7 +8,6 @@ import (
8 8
 	"net/http"
9 9
 	"net/http/httputil"
10 10
 	"os"
11
-	"os/exec"
12 11
 	"strconv"
13 12
 	"strings"
14 13
 	"time"
... ...
@@ -26,11 +25,7 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
26 26
 	}
27 27
 
28 28
 	name := "getall"
29
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
30
-	out, _, err := runCommandWithOutput(runCmd)
31
-	if err != nil {
32
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
33
-	}
29
+	dockerCmd(c, "run", "--name", name, "busybox", "true")
34 30
 
35 31
 	status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
36 32
 	c.Assert(err, check.IsNil)
... ...
@@ -54,9 +49,7 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
54 54
 
55 55
 // regression test for empty json field being omitted #13691
56 56
 func (s *DockerSuite) TestContainerApiGetJSONNoFieldsOmitted(c *check.C) {
57
-	runCmd := exec.Command(dockerBinary, "run", "busybox", "true")
58
-	_, err := runCommand(runCmd)
59
-	c.Assert(err, check.IsNil)
57
+	dockerCmd(c, "run", "busybox", "true")
60 58
 
61 59
 	status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
62 60
 	c.Assert(err, check.IsNil)
... ...
@@ -94,9 +87,7 @@ type containerPs struct {
94 94
 func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) {
95 95
 	name := "pstest"
96 96
 	port := 80
97
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "--expose", strconv.Itoa(port), "busybox", "top")
98
-	_, err := runCommand(runCmd)
99
-	c.Assert(err, check.IsNil)
97
+	dockerCmd(c, "run", "-d", "--name", name, "--expose", strconv.Itoa(port), "busybox", "top")
100 98
 
101 99
 	status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
102 100
 	c.Assert(err, check.IsNil)
... ...
@@ -126,11 +117,7 @@ func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) {
126 126
 
127 127
 func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
128 128
 	name := "exportcontainer"
129
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
130
-	out, _, err := runCommandWithOutput(runCmd)
131
-	if err != nil {
132
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
133
-	}
129
+	dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test")
134 130
 
135 131
 	status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
136 132
 	c.Assert(err, check.IsNil)
... ...
@@ -158,11 +145,7 @@ func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
158 158
 
159 159
 func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
160 160
 	name := "changescontainer"
161
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "rm", "/etc/passwd")
162
-	out, _, err := runCommandWithOutput(runCmd)
163
-	if err != nil {
164
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
165
-	}
161
+	dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
166 162
 
167 163
 	status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
168 164
 	c.Assert(err, check.IsNil)
... ...
@@ -248,9 +231,7 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
248 248
 	volName := "voltst"
249 249
 	volPath := "/tmp"
250 250
 
251
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", volName, "-v", volPath, "busybox")); err != nil {
252
-		c.Fatal(out, err)
253
-	}
251
+	dockerCmd(c, "run", "-d", "--name", volName, "-v", volPath, "busybox")
254 252
 
255 253
 	name := "TestContainerApiStartDupVolumeBinds"
256 254
 	config := map[string]interface{}{
... ...
@@ -285,13 +266,10 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
285 285
 
286 286
 func (s *DockerSuite) TestGetContainerStats(c *check.C) {
287 287
 	var (
288
-		name   = "statscontainer"
289
-		runCmd = exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
288
+		name = "statscontainer"
290 289
 	)
291
-	out, _, err := runCommandWithOutput(runCmd)
292
-	if err != nil {
293
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
294
-	}
290
+	dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
291
+
295 292
 	type b struct {
296 293
 		status int
297 294
 		body   []byte
... ...
@@ -305,9 +283,7 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
305 305
 
306 306
 	// allow some time to stream the stats from the container
307 307
 	time.Sleep(4 * time.Second)
308
-	if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil {
309
-		c.Fatal(err)
310
-	}
308
+	dockerCmd(c, "rm", "-f", name)
311 309
 
312 310
 	// collect the results from the stats stream or timeout and fail
313 311
 	// if the stream was not disconnected.
... ...
@@ -353,7 +329,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
353 353
 	c.Assert(err, check.IsNil)
354 354
 
355 355
 	// Now remove without `-f` and make sure we are still pulling stats
356
-	_, err = runCommand(exec.Command(dockerBinary, "rm", id))
356
+	_, _, err = dockerCmdWithError(c, "rm", id)
357 357
 	c.Assert(err, check.Not(check.IsNil), check.Commentf("rm should have failed but didn't"))
358 358
 	_, err = buf.ReadTimeout(b, 2*time.Second)
359 359
 	c.Assert(err, check.IsNil)
... ...
@@ -368,9 +344,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
368 368
 // stream false always return one stat)
369 369
 func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
370 370
 	name := "statscontainer"
371
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
372
-	_, err := runCommand(runCmd)
373
-	c.Assert(err, check.IsNil)
371
+	dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
374 372
 
375 373
 	type b struct {
376 374
 		status int
... ...
@@ -385,9 +359,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
385 385
 
386 386
 	// allow some time to stream the stats from the container
387 387
 	time.Sleep(4 * time.Second)
388
-	if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil {
389
-		c.Fatal(err)
390
-	}
388
+	dockerCmd(c, "rm", "-f", name)
391 389
 
392 390
 	// collect the results from the stats stream or timeout and fail
393 391
 	// if the stream was not disconnected.
... ...
@@ -408,9 +380,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
408 408
 
409 409
 func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
410 410
 	name := "statscontainer"
411
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
412
-	_, err := runCommand(runCmd)
413
-	c.Assert(err, check.IsNil)
411
+	dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
414 412
 
415 413
 	type b struct {
416 414
 		status int
... ...
@@ -425,9 +395,7 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
425 425
 
426 426
 	// allow some time to stream the stats from the container
427 427
 	time.Sleep(4 * time.Second)
428
-	if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil {
429
-		c.Fatal(err)
430
-	}
428
+	dockerCmd(c, "rm", "-f", name)
431 429
 
432 430
 	// collect the results from the stats stream or timeout and fail
433 431
 	// if the stream was not disconnected.
... ...
@@ -449,13 +417,9 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
449 449
 func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
450 450
 	// TODO: this test does nothing because we are c.Assert'ing in goroutine
451 451
 	var (
452
-		name   = "statscontainer"
453
-		runCmd = exec.Command(dockerBinary, "create", "--name", name, "busybox", "top")
452
+		name = "statscontainer"
454 453
 	)
455
-	out, _, err := runCommandWithOutput(runCmd)
456
-	if err != nil {
457
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
458
-	}
454
+	dockerCmd(c, "create", "--name", name, "busybox", "top")
459 455
 
460 456
 	go func() {
461 457
 		// We'll never get return for GET stats from sockRequest as of now,
... ...
@@ -739,20 +703,14 @@ func (s *DockerSuite) TestBuildApiDockerfileSymlink(c *check.C) {
739 739
 
740 740
 // #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume
741 741
 func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
742
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=one", "busybox"))
743
-	if err != nil {
744
-		c.Fatal(err, out)
745
-	}
742
+	dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
746 743
 
747 744
 	fooDir, err := inspectFieldMap("one", "Volumes", "/foo")
748 745
 	if err != nil {
749 746
 		c.Fatal(err)
750 747
 	}
751 748
 
752
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=two", "busybox"))
753
-	if err != nil {
754
-		c.Fatal(err, out)
755
-	}
749
+	dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox")
756 750
 
757 751
 	bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
758 752
 	status, _, err := sockRequest("POST", "/containers/two/start", bindSpec)
... ...
@@ -771,12 +729,7 @@ func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
771 771
 
772 772
 func (s *DockerSuite) TestContainerApiPause(c *check.C) {
773 773
 	defer unpauseAllContainers()
774
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "30")
775
-	out, _, err := runCommandWithOutput(runCmd)
776
-
777
-	if err != nil {
778
-		c.Fatalf("failed to create a container: %s, %v", out, err)
779
-	}
774
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30")
780 775
 	ContainerID := strings.TrimSpace(out)
781 776
 
782 777
 	status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
... ...
@@ -809,10 +762,7 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
809 809
 }
810 810
 
811 811
 func (s *DockerSuite) TestContainerApiTop(c *check.C) {
812
-	out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", "top").CombinedOutput()
813
-	if err != nil {
814
-		c.Fatal(err, out)
815
-	}
812
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top")
816 813
 	id := strings.TrimSpace(string(out))
817 814
 	if err := waitRun(id); err != nil {
818 815
 		c.Fatal(err)
... ...
@@ -851,10 +801,7 @@ func (s *DockerSuite) TestContainerApiTop(c *check.C) {
851 851
 
852 852
 func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
853 853
 	cName := "testapicommit"
854
-	out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput()
855
-	if err != nil {
856
-		c.Fatal(err, out)
857
-	}
854
+	dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
858 855
 
859 856
 	name := "TestContainerApiCommit"
860 857
 	status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil)
... ...
@@ -877,18 +824,12 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
877 877
 		c.Fatalf("got wrong Cmd from commit: %q", cmd)
878 878
 	}
879 879
 	// sanity check, make sure the image is what we think it is
880
-	out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput()
881
-	if err != nil {
882
-		c.Fatalf("error checking committed image: %v - %q", err, string(out))
883
-	}
880
+	dockerCmd(c, "run", img.Id, "ls", "/test")
884 881
 }
885 882
 
886 883
 func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
887 884
 	cName := "testapicommitwithconfig"
888
-	out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput()
889
-	if err != nil {
890
-		c.Fatal(err, out)
891
-	}
885
+	dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
892 886
 
893 887
 	config := map[string]interface{}{
894 888
 		"Labels": map[string]string{"key1": "value1", "key2": "value2"},
... ...
@@ -928,10 +869,7 @@ func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
928 928
 	}
929 929
 
930 930
 	// sanity check, make sure the image is what we think it is
931
-	out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput()
932
-	if err != nil {
933
-		c.Fatalf("error checking committed image: %v - %q", err, string(out))
934
-	}
931
+	dockerCmd(c, "run", img.Id, "ls", "/test")
935 932
 }
936 933
 
937 934
 func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
... ...
@@ -952,11 +890,8 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
952 952
 		c.Fatal(err)
953 953
 	}
954 954
 
955
-	out, err := exec.Command(dockerBinary, "start", "-a", container.Id).CombinedOutput()
956
-	if err != nil {
957
-		c.Fatal(string(out), err)
958
-	}
959
-	if strings.TrimSpace(string(out)) != "/test" {
955
+	out, _ := dockerCmd(c, "start", "-a", container.Id)
956
+	if strings.TrimSpace(out) != "/test" {
960 957
 		c.Fatalf("expected output `/test`, got %q", out)
961 958
 	}
962 959
 }
... ...
@@ -1241,10 +1176,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
1241 1241
 }
1242 1242
 
1243 1243
 func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
1244
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "busybox"))
1245
-	if err != nil {
1246
-		c.Fatal(err, out)
1247
-	}
1244
+	out, _ := dockerCmd(c, "create", "busybox")
1248 1245
 
1249 1246
 	containerID := strings.TrimSpace(out)
1250 1247
 
... ...
@@ -1265,9 +1197,7 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
1265 1265
 }
1266 1266
 
1267 1267
 func (s *DockerSuite) TestContainerApiRename(c *check.C) {
1268
-	runCmd := exec.Command(dockerBinary, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh")
1269
-	out, _, err := runCommandWithOutput(runCmd)
1270
-	c.Assert(err, check.IsNil)
1268
+	out, _ := dockerCmd(c, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh")
1271 1269
 
1272 1270
 	containerID := strings.TrimSpace(out)
1273 1271
 	newName := "TestContainerApiRenameNew"
... ...
@@ -1284,11 +1214,7 @@ func (s *DockerSuite) TestContainerApiRename(c *check.C) {
1284 1284
 
1285 1285
 func (s *DockerSuite) TestContainerApiKill(c *check.C) {
1286 1286
 	name := "test-api-kill"
1287
-	runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
1288
-	out, _, err := runCommandWithOutput(runCmd)
1289
-	if err != nil {
1290
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
1291
-	}
1287
+	dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
1292 1288
 
1293 1289
 	status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil)
1294 1290
 	c.Assert(err, check.IsNil)
... ...
@@ -1305,11 +1231,7 @@ func (s *DockerSuite) TestContainerApiKill(c *check.C) {
1305 1305
 
1306 1306
 func (s *DockerSuite) TestContainerApiRestart(c *check.C) {
1307 1307
 	name := "test-api-restart"
1308
-	runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
1309
-	out, _, err := runCommandWithOutput(runCmd)
1310
-	if err != nil {
1311
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
1312
-	}
1308
+	dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
1313 1309
 
1314 1310
 	status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil)
1315 1311
 	c.Assert(err, check.IsNil)
... ...
@@ -1322,11 +1244,7 @@ func (s *DockerSuite) TestContainerApiRestart(c *check.C) {
1322 1322
 
1323 1323
 func (s *DockerSuite) TestContainerApiRestartNotimeoutParam(c *check.C) {
1324 1324
 	name := "test-api-restart-no-timeout-param"
1325
-	runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
1326
-	out, _, err := runCommandWithOutput(runCmd)
1327
-	if err != nil {
1328
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
1329
-	}
1325
+	out, _ := dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
1330 1326
 	id := strings.TrimSpace(out)
1331 1327
 	c.Assert(waitRun(id), check.IsNil)
1332 1328
 
... ...
@@ -1364,11 +1282,7 @@ func (s *DockerSuite) TestContainerApiStart(c *check.C) {
1364 1364
 
1365 1365
 func (s *DockerSuite) TestContainerApiStop(c *check.C) {
1366 1366
 	name := "test-api-stop"
1367
-	runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
1368
-	out, _, err := runCommandWithOutput(runCmd)
1369
-	if err != nil {
1370
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
1371
-	}
1367
+	dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
1372 1368
 
1373 1369
 	status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=1", nil)
1374 1370
 	c.Assert(err, check.IsNil)
... ...
@@ -1386,11 +1300,7 @@ func (s *DockerSuite) TestContainerApiStop(c *check.C) {
1386 1386
 
1387 1387
 func (s *DockerSuite) TestContainerApiWait(c *check.C) {
1388 1388
 	name := "test-api-wait"
1389
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sleep", "5")
1390
-	out, _, err := runCommandWithOutput(runCmd)
1391
-	if err != nil {
1392
-		c.Fatalf("Error on container creation: %v, output: %q", err, out)
1393
-	}
1389
+	dockerCmd(c, "run", "--name", name, "busybox", "sleep", "5")
1394 1390
 
1395 1391
 	status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil)
1396 1392
 	c.Assert(err, check.IsNil)
... ...
@@ -1412,9 +1322,7 @@ func (s *DockerSuite) TestContainerApiWait(c *check.C) {
1412 1412
 
1413 1413
 func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
1414 1414
 	name := "test-container-api-copy"
1415
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt")
1416
-	_, err := runCommand(runCmd)
1417
-	c.Assert(err, check.IsNil)
1415
+	dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
1418 1416
 
1419 1417
 	postData := types.CopyConfig{
1420 1418
 		Resource: "/test.txt",
... ...
@@ -1443,9 +1351,7 @@ func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
1443 1443
 
1444 1444
 func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
1445 1445
 	name := "test-container-api-copy-resource-empty"
1446
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt")
1447
-	_, err := runCommand(runCmd)
1448
-	c.Assert(err, check.IsNil)
1446
+	dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
1449 1447
 
1450 1448
 	postData := types.CopyConfig{
1451 1449
 		Resource: "",
... ...
@@ -1459,9 +1365,7 @@ func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
1459 1459
 
1460 1460
 func (s *DockerSuite) TestContainerApiCopyResourcePathNotFound(c *check.C) {
1461 1461
 	name := "test-container-api-copy-resource-not-found"
1462
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox")
1463
-	_, err := runCommand(runCmd)
1464
-	c.Assert(err, check.IsNil)
1462
+	dockerCmd(c, "run", "--name", name, "busybox")
1465 1463
 
1466 1464
 	postData := types.CopyConfig{
1467 1465
 		Resource: "/notexist",
... ...
@@ -1484,16 +1388,12 @@ func (s *DockerSuite) TestContainerApiCopyContainerNotFound(c *check.C) {
1484 1484
 }
1485 1485
 
1486 1486
 func (s *DockerSuite) TestContainerApiDelete(c *check.C) {
1487
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1488
-	out, _, err := runCommandWithOutput(runCmd)
1489
-	c.Assert(err, check.IsNil)
1487
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
1490 1488
 
1491 1489
 	id := strings.TrimSpace(out)
1492 1490
 	c.Assert(waitRun(id), check.IsNil)
1493 1491
 
1494
-	stopCmd := exec.Command(dockerBinary, "stop", id)
1495
-	_, err = runCommand(stopCmd)
1496
-	c.Assert(err, check.IsNil)
1492
+	dockerCmd(c, "stop", id)
1497 1493
 
1498 1494
 	status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
1499 1495
 	c.Assert(err, check.IsNil)
... ...
@@ -1508,9 +1408,7 @@ func (s *DockerSuite) TestContainerApiDeleteNotExist(c *check.C) {
1508 1508
 }
1509 1509
 
1510 1510
 func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
1511
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1512
-	out, _, err := runCommandWithOutput(runCmd)
1513
-	c.Assert(err, check.IsNil)
1511
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
1514 1512
 
1515 1513
 	id := strings.TrimSpace(out)
1516 1514
 	c.Assert(waitRun(id), check.IsNil)
... ...
@@ -1521,16 +1419,12 @@ func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
1521 1521
 }
1522 1522
 
1523 1523
 func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
1524
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "tlink1", "busybox", "top")
1525
-	out, _, err := runCommandWithOutput(runCmd)
1526
-	c.Assert(err, check.IsNil)
1524
+	out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top")
1527 1525
 
1528 1526
 	id := strings.TrimSpace(out)
1529 1527
 	c.Assert(waitRun(id), check.IsNil)
1530 1528
 
1531
-	runCmd = exec.Command(dockerBinary, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
1532
-	out, _, err = runCommandWithOutput(runCmd)
1533
-	c.Assert(err, check.IsNil)
1529
+	out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
1534 1530
 
1535 1531
 	id2 := strings.TrimSpace(out)
1536 1532
 	c.Assert(waitRun(id2), check.IsNil)
... ...
@@ -1555,9 +1449,7 @@ func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
1555 1555
 }
1556 1556
 
1557 1557
 func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
1558
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1559
-	out, _, err := runCommandWithOutput(runCmd)
1560
-	c.Assert(err, check.IsNil)
1558
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
1561 1559
 
1562 1560
 	id := strings.TrimSpace(out)
1563 1561
 	c.Assert(waitRun(id), check.IsNil)
... ...
@@ -1570,9 +1462,7 @@ func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
1570 1570
 func (s *DockerSuite) TestContainerApiDeleteRemoveVolume(c *check.C) {
1571 1571
 	testRequires(c, SameHostDaemon)
1572 1572
 
1573
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/testvolume", "busybox", "top")
1574
-	out, _, err := runCommandWithOutput(runCmd)
1575
-	c.Assert(err, check.IsNil)
1573
+	out, _ := dockerCmd(c, "run", "-d", "-v", "/testvolume", "busybox", "top")
1576 1574
 
1577 1575
 	id := strings.TrimSpace(out)
1578 1576
 	c.Assert(waitRun(id), check.IsNil)
... ...
@@ -1644,9 +1534,7 @@ func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
1644 1644
 }
1645 1645
 
1646 1646
 func (s *DockerSuite) TestPostContainerStop(c *check.C) {
1647
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1648
-	out, _, err := runCommandWithOutput(runCmd)
1649
-	c.Assert(err, check.IsNil)
1647
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
1650 1648
 
1651 1649
 	containerID := strings.TrimSpace(out)
1652 1650
 	c.Assert(waitRun(containerID), check.IsNil)
... ...
@@ -2,18 +2,13 @@ package main
2 2
 
3 3
 import (
4 4
 	"net/http"
5
-	"os/exec"
6 5
 	"strings"
7 6
 
8 7
 	"github.com/go-check/check"
9 8
 )
10 9
 
11 10
 func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) {
12
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
13
-	out, _, err := runCommandWithOutput(runCmd)
14
-	if err != nil {
15
-		c.Fatalf(out, err)
16
-	}
11
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
17 12
 	cleanedContainerID := strings.TrimSpace(out)
18 13
 
19 14
 	endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
... ...
@@ -7,7 +7,6 @@ import (
7 7
 	"encoding/json"
8 8
 	"fmt"
9 9
 	"net/http"
10
-	"os/exec"
11 10
 
12 11
 	"github.com/go-check/check"
13 12
 )
... ...
@@ -15,10 +14,7 @@ import (
15 15
 // Regression test for #9414
16 16
 func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
17 17
 	name := "exec_test"
18
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
19
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
20
-		c.Fatal(out, err)
21
-	}
18
+	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
22 19
 
23 20
 	status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
24 21
 	c.Assert(status, check.Equals, http.StatusInternalServerError)
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"encoding/json"
5 5
 	"net/http"
6 6
 	"net/url"
7
-	"os/exec"
8 7
 	"strings"
9 8
 
10 9
 	"github.com/docker/docker/api/types"
... ...
@@ -16,9 +15,7 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
16 16
 	name2 := "utest/docker:tag2"
17 17
 	name3 := "utest:5000/docker:tag3"
18 18
 	for _, n := range []string{name, name2, name3} {
19
-		if out, err := exec.Command(dockerBinary, "tag", "busybox", n).CombinedOutput(); err != nil {
20
-			c.Fatal(err, out)
21
-		}
19
+		dockerCmd(c, "tag", "busybox", n)
22 20
 	}
23 21
 	type image types.Image
24 22
 	getImages := func(filter string) []image {
... ...
@@ -65,9 +62,7 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
65 65
 
66 66
 	defer body.Close()
67 67
 
68
-	if out, err := exec.Command(dockerBinary, "rmi", id).CombinedOutput(); err != nil {
69
-		c.Fatal(err, out)
70
-	}
68
+	dockerCmd(c, "rmi", id)
71 69
 
72 70
 	res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
73 71
 	c.Assert(err, check.IsNil)
... ...
@@ -75,10 +70,7 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
75 75
 
76 76
 	defer loadBody.Close()
77 77
 
78
-	inspectOut, err := exec.Command(dockerBinary, "inspect", "--format='{{ .Id }}'", id).CombinedOutput()
79
-	if err != nil {
80
-		c.Fatal(err, inspectOut)
81
-	}
78
+	inspectOut, _ := dockerCmd(c, "inspect", "--format='{{ .Id }}'", id)
82 79
 	if strings.TrimSpace(string(inspectOut)) != id {
83 80
 		c.Fatal("load did not work properly")
84 81
 	}
... ...
@@ -93,9 +85,7 @@ func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
93 93
 	}
94 94
 	id := strings.TrimSpace(out)
95 95
 
96
-	if out, err := exec.Command(dockerBinary, "tag", name, "test:tag1").CombinedOutput(); err != nil {
97
-		c.Fatal(err, out)
98
-	}
96
+	dockerCmd(c, "tag", name, "test:tag1")
99 97
 
100 98
 	status, _, err := sockRequest("DELETE", "/images/"+id, nil)
101 99
 	c.Assert(status, check.Equals, http.StatusConflict)
... ...
@@ -3,18 +3,13 @@ package main
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"net/http"
6
-	"os/exec"
7 6
 	"strings"
8 7
 
9 8
 	"github.com/go-check/check"
10 9
 )
11 10
 
12 11
 func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
13
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
14
-	out, _, err := runCommandWithOutput(runCmd)
15
-	if err != nil {
16
-		c.Fatalf("failed to create a container: %s, %v", out, err)
17
-	}
12
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
18 13
 
19 14
 	cleanedContainerID := strings.TrimSpace(out)
20 15
 
... ...
@@ -5,7 +5,6 @@ import (
5 5
 	"bytes"
6 6
 	"fmt"
7 7
 	"net/http"
8
-	"os/exec"
9 8
 	"strings"
10 9
 	"time"
11 10
 
... ...
@@ -46,10 +45,7 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
46 46
 
47 47
 func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
48 48
 	name := "logs_test"
49
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
50
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
51
-		c.Fatal(out, err)
52
-	}
49
+	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
53 50
 
54 51
 	status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
55 52
 	c.Assert(status, check.Equals, http.StatusBadRequest)
... ...
@@ -65,10 +61,7 @@ func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
65 65
 func (s *DockerSuite) TestLogsApiFollowEmptyOutput(c *check.C) {
66 66
 	name := "logs_test"
67 67
 	t0 := time.Now()
68
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
69
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
70
-		c.Fatal(out, err)
71
-	}
68
+	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
72 69
 
73 70
 	_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
74 71
 	t1 := time.Now()
... ...
@@ -2,18 +2,13 @@ package main
2 2
 
3 3
 import (
4 4
 	"net/http"
5
-	"os/exec"
6 5
 	"strings"
7 6
 
8 7
 	"github.com/go-check/check"
9 8
 )
10 9
 
11 10
 func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
12
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
13
-	out, _, err := runCommandWithOutput(runCmd)
14
-	if err != nil {
15
-		c.Fatalf(out, err)
16
-	}
11
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
17 12
 	cleanedContainerID := strings.TrimSpace(out)
18 13
 
19 14
 	endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
... ...
@@ -23,11 +18,7 @@ func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
23 23
 }
24 24
 
25 25
 func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
26
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
27
-	out, _, err := runCommandWithOutput(runCmd)
28
-	if err != nil {
29
-		c.Fatalf(out, err)
30
-	}
26
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
31 27
 	cleanedContainerID := strings.TrimSpace(out)
32 28
 
33 29
 	endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
... ...
@@ -37,19 +28,11 @@ func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
37 37
 }
38 38
 
39 39
 func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
40
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
41
-	out, _, err := runCommandWithOutput(runCmd)
42
-	if err != nil {
43
-		c.Fatalf(out, err)
44
-	}
40
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
45 41
 	cleanedContainerID := strings.TrimSpace(out)
46 42
 
47 43
 	// make sure the exited container is not running
48
-	runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
49
-	out, _, err = runCommandWithOutput(runCmd)
50
-	if err != nil {
51
-		c.Fatalf(out, err)
52
-	}
44
+	dockerCmd(c, "wait", cleanedContainerID)
53 45
 
54 46
 	endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
55 47
 	status, body, err := sockRequest("POST", endpoint, nil)
... ...
@@ -76,10 +76,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
76 76
 		c.Fatalf("Attaches did not initialize properly")
77 77
 	}
78 78
 
79
-	cmd := exec.Command(dockerBinary, "kill", "attacher")
80
-	if _, err := runCommand(cmd); err != nil {
81
-		c.Fatal(err)
82
-	}
79
+	dockerCmd(c, "kill", "attacher")
83 80
 
84 81
 	select {
85 82
 	case <-endDone:
... ...
@@ -90,11 +87,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
90 90
 }
91 91
 
92 92
 func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) {
93
-	cmd := exec.Command(dockerBinary, "run", "-d", "-ti", "busybox")
94
-	out, _, err := runCommandWithOutput(cmd)
95
-	if err != nil {
96
-		c.Fatalf("failed to start container: %v (%v)", out, err)
97
-	}
93
+	out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
98 94
 
99 95
 	id := strings.TrimSpace(out)
100 96
 	if err := waitRun(id); err != nil {
... ...
@@ -16,11 +16,7 @@ import (
16 16
 // #9860
17 17
 func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) {
18 18
 
19
-	cmd := exec.Command(dockerBinary, "run", "-dti", "busybox", "sleep", "2")
20
-	out, _, err := runCommandWithOutput(cmd)
21
-	if err != nil {
22
-		c.Fatalf("failed to start container: %v (%v)", out, err)
23
-	}
19
+	out, _ := dockerCmd(c, "run", "-dti", "busybox", "sleep", "2")
24 20
 
25 21
 	id := strings.TrimSpace(out)
26 22
 	if err := waitRun(id); err != nil {
... ...
@@ -47,10 +43,8 @@ func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) {
47 47
 		}
48 48
 	}()
49 49
 
50
-	waitCmd := exec.Command(dockerBinary, "wait", id)
51
-	if out, _, err = runCommandWithOutput(waitCmd); err != nil {
52
-		c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
53
-	}
50
+	dockerCmd(c, "wait", id)
51
+
54 52
 	select {
55 53
 	case err := <-errChan:
56 54
 		c.Assert(err, check.IsNil)
... ...
@@ -76,16 +76,7 @@ func (s *DockerSuite) TestBuildShCmdJSONEntrypoint(c *check.C) {
76 76
 		c.Fatal(err)
77 77
 	}
78 78
 
79
-	out, _, err := runCommandWithOutput(
80
-		exec.Command(
81
-			dockerBinary,
82
-			"run",
83
-			"--rm",
84
-			name))
85
-
86
-	if err != nil {
87
-		c.Fatal(err)
88
-	}
79
+	out, _ := dockerCmd(c, "run", "--rm", name)
89 80
 
90 81
 	if strings.TrimSpace(out) != "/bin/sh -c echo test" {
91 82
 		c.Fatal("CMD did not contain /bin/sh -c")
... ...
@@ -420,12 +411,12 @@ func (s *DockerSuite) TestBuildEnvEscapes(c *check.C) {
420 420
     `,
421 421
 		true)
422 422
 
423
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name))
424
-
425 423
 	if err != nil {
426 424
 		c.Fatal(err)
427 425
 	}
428 426
 
427
+	out, _ := dockerCmd(c, "run", "-t", name)
428
+
429 429
 	if strings.TrimSpace(out) != "$" {
430 430
 		c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out))
431 431
 	}
... ...
@@ -447,11 +438,7 @@ func (s *DockerSuite) TestBuildEnvOverwrite(c *check.C) {
447 447
 		c.Fatal(err)
448 448
 	}
449 449
 
450
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-e", "TEST=bar", "-t", name))
451
-
452
-	if err != nil {
453
-		c.Fatal(err)
454
-	}
450
+	out, _ := dockerCmd(c, "run", "-e", "TEST=bar", "-t", name)
455 451
 
456 452
 	if strings.TrimSpace(out) != "bar" {
457 453
 		c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out))
... ...
@@ -462,21 +449,13 @@ func (s *DockerSuite) TestBuildEnvOverwrite(c *check.C) {
462 462
 func (s *DockerSuite) TestBuildOnBuildForbiddenMaintainerInSourceImage(c *check.C) {
463 463
 	name := "testbuildonbuildforbiddenmaintainerinsourceimage"
464 464
 
465
-	createCmd := exec.Command(dockerBinary, "create", "busybox", "true")
466
-	out, _, _, err := runCommandWithStdoutStderr(createCmd)
467
-	if err != nil {
468
-		c.Fatal(out, err)
469
-	}
465
+	out, _ := dockerCmd(c, "create", "busybox", "true")
470 466
 
471 467
 	cleanedContainerID := strings.TrimSpace(out)
472 468
 
473
-	commitCmd := exec.Command(dockerBinary, "commit", "--run", "{\"OnBuild\":[\"MAINTAINER docker.io\"]}", cleanedContainerID, "onbuild")
474
-
475
-	if _, err := runCommand(commitCmd); err != nil {
476
-		c.Fatal(err)
477
-	}
469
+	dockerCmd(c, "commit", "--run", "{\"OnBuild\":[\"MAINTAINER docker.io\"]}", cleanedContainerID, "onbuild")
478 470
 
479
-	_, err = buildImage(name,
471
+	_, err := buildImage(name,
480 472
 		`FROM onbuild`,
481 473
 		true)
482 474
 	if err != nil {
... ...
@@ -492,21 +471,13 @@ func (s *DockerSuite) TestBuildOnBuildForbiddenMaintainerInSourceImage(c *check.
492 492
 func (s *DockerSuite) TestBuildOnBuildForbiddenFromInSourceImage(c *check.C) {
493 493
 	name := "testbuildonbuildforbiddenfrominsourceimage"
494 494
 
495
-	createCmd := exec.Command(dockerBinary, "create", "busybox", "true")
496
-	out, _, _, err := runCommandWithStdoutStderr(createCmd)
497
-	if err != nil {
498
-		c.Fatal(out, err)
499
-	}
495
+	out, _ := dockerCmd(c, "create", "busybox", "true")
500 496
 
501 497
 	cleanedContainerID := strings.TrimSpace(out)
502 498
 
503
-	commitCmd := exec.Command(dockerBinary, "commit", "--run", "{\"OnBuild\":[\"FROM busybox\"]}", cleanedContainerID, "onbuild")
499
+	dockerCmd(c, "commit", "--run", "{\"OnBuild\":[\"FROM busybox\"]}", cleanedContainerID, "onbuild")
504 500
 
505
-	if _, err := runCommand(commitCmd); err != nil {
506
-		c.Fatal(err)
507
-	}
508
-
509
-	_, err = buildImage(name,
501
+	_, err := buildImage(name,
510 502
 		`FROM onbuild`,
511 503
 		true)
512 504
 	if err != nil {
... ...
@@ -522,21 +493,13 @@ func (s *DockerSuite) TestBuildOnBuildForbiddenFromInSourceImage(c *check.C) {
522 522
 func (s *DockerSuite) TestBuildOnBuildForbiddenChainedInSourceImage(c *check.C) {
523 523
 	name := "testbuildonbuildforbiddenchainedinsourceimage"
524 524
 
525
-	createCmd := exec.Command(dockerBinary, "create", "busybox", "true")
526
-	out, _, _, err := runCommandWithStdoutStderr(createCmd)
527
-	if err != nil {
528
-		c.Fatal(out, err)
529
-	}
525
+	out, _ := dockerCmd(c, "create", "busybox", "true")
530 526
 
531 527
 	cleanedContainerID := strings.TrimSpace(out)
532 528
 
533
-	commitCmd := exec.Command(dockerBinary, "commit", "--run", "{\"OnBuild\":[\"ONBUILD RUN ls\"]}", cleanedContainerID, "onbuild")
534
-
535
-	if _, err := runCommand(commitCmd); err != nil {
536
-		c.Fatal(err)
537
-	}
529
+	dockerCmd(c, "commit", "--run", "{\"OnBuild\":[\"ONBUILD RUN ls\"]}", cleanedContainerID, "onbuild")
538 530
 
539
-	_, err = buildImage(name,
531
+	_, err := buildImage(name,
540 532
 		`FROM onbuild`,
541 533
 		true)
542 534
 	if err != nil {
... ...
@@ -570,10 +533,7 @@ ONBUILD RUN ["true"]`,
570 570
 		c.Fatal(err)
571 571
 	}
572 572
 
573
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2))
574
-	if err != nil {
575
-		c.Fatal(err)
576
-	}
573
+	out, _ := dockerCmd(c, "run", "-t", name2)
577 574
 
578 575
 	if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) {
579 576
 		c.Fatal("did not get echo output from onbuild", out)
... ...
@@ -600,10 +560,7 @@ ONBUILD ENTRYPOINT ["echo"]`,
600 600
 		c.Fatal(err)
601 601
 	}
602 602
 
603
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2))
604
-	if err != nil {
605
-		c.Fatal(err)
606
-	}
603
+	out, _ := dockerCmd(c, "run", "-t", name2)
607 604
 
608 605
 	if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) {
609 606
 		c.Fatal("got malformed output from onbuild", out)
... ...
@@ -1827,11 +1784,7 @@ func (s *DockerSuite) TestBuildForceRm(c *check.C) {
1827 1827
 	}
1828 1828
 	defer ctx.Close()
1829 1829
 
1830
-	buildCmd := exec.Command(dockerBinary, "build", "-t", name, "--force-rm", ".")
1831
-	buildCmd.Dir = ctx.Dir
1832
-	if out, _, err := runCommandWithOutput(buildCmd); err == nil {
1833
-		c.Fatalf("failed to build the image: %s, %v", out, err)
1834
-	}
1830
+	dockerCmdInDir(c, ctx.Dir, "build", "-t", name, "--force-rm", ".")
1835 1831
 
1836 1832
 	containerCountAfter, err := getContainerCount()
1837 1833
 	if err != nil {
... ...
@@ -3100,11 +3053,7 @@ func (s *DockerSuite) TestBuildWithVolumeOwnership(c *check.C) {
3100 3100
 		c.Fatal(err)
3101 3101
 	}
3102 3102
 
3103
-	cmd := exec.Command(dockerBinary, "run", "--rm", "testbuildimg", "ls", "-la", "/test")
3104
-	out, _, err := runCommandWithOutput(cmd)
3105
-	if err != nil {
3106
-		c.Fatal(out, err)
3107
-	}
3103
+	out, _ := dockerCmd(c, "run", "--rm", "testbuildimg", "ls", "-la", "/test")
3108 3104
 
3109 3105
 	if expected := "drw-------"; !strings.Contains(out, expected) {
3110 3106
 		c.Fatalf("expected %s received %s", expected, out)
... ...
@@ -3349,6 +3298,9 @@ func (s *DockerSuite) TestBuildEscapeWhitespace(c *check.C) {
3349 3349
 IO <io@\
3350 3350
 docker.com>"
3351 3351
   `, true)
3352
+	if err != nil {
3353
+		c.Fatal(err)
3354
+	}
3352 3355
 
3353 3356
 	res, err := inspectField(name, "Author")
3354 3357
 
... ...
@@ -3371,11 +3323,12 @@ func (s *DockerSuite) TestBuildVerifyIntString(c *check.C) {
3371 3371
   MAINTAINER 123
3372 3372
   `, true)
3373 3373
 
3374
-	out, rc, err := runCommandWithOutput(exec.Command(dockerBinary, "inspect", name))
3375
-	if rc != 0 || err != nil {
3376
-		c.Fatalf("Unexpected error from inspect: rc: %v  err: %v", rc, err)
3374
+	if err != nil {
3375
+		c.Fatal(err)
3377 3376
 	}
3378 3377
 
3378
+	out, _ := dockerCmd(c, "inspect", name)
3379
+
3379 3380
 	if !strings.Contains(out, "\"123\"") {
3380 3381
 		c.Fatalf("Output does not contain the int as a string:\n%s", out)
3381 3382
 	}
... ...
@@ -4030,6 +3983,7 @@ func (s *DockerSuite) TestBuildAddTarXz(c *check.C) {
4030 4030
 		if err := tw.Close(); err != nil {
4031 4031
 			c.Fatalf("failed to close tar archive: %v", err)
4032 4032
 		}
4033
+
4033 4034
 		xzCompressCmd := exec.Command("xz", "-k", "test.tar")
4034 4035
 		xzCompressCmd.Dir = tmpDir
4035 4036
 		out, _, err := runCommandWithOutput(xzCompressCmd)
... ...
@@ -4389,9 +4343,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritance(c *check.C) {
4389 4389
 		c.Fatal(err)
4390 4390
 	}
4391 4391
 
4392
-	status, _ := runCommand(exec.Command(dockerBinary, "run", "parent"))
4393
-
4394
-	if status != 130 {
4392
+	if _, status, _ := dockerCmdWithError(c, "run", "parent"); status != 130 {
4395 4393
 		c.Fatalf("expected exit code 130 but received %d", status)
4396 4394
 	}
4397 4395
 
... ...
@@ -4402,9 +4354,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritance(c *check.C) {
4402 4402
 		c.Fatal(err)
4403 4403
 	}
4404 4404
 
4405
-	status, _ = runCommand(exec.Command(dockerBinary, "run", "child"))
4406
-
4407
-	if status != 5 {
4405
+	if _, status, _ := dockerCmdWithError(c, "run", "child"); status != 5 {
4408 4406
 		c.Fatalf("expected exit code 5 but received %d", status)
4409 4407
 	}
4410 4408
 
... ...
@@ -4434,10 +4384,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritanceInspect(c *check.C) {
4434 4434
 		c.Fatalf("Expected value %s not in Config.Entrypoint: %s", expected, res)
4435 4435
 	}
4436 4436
 
4437
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2))
4438
-	if err != nil {
4439
-		c.Fatal(err, out)
4440
-	}
4437
+	out, _ := dockerCmd(c, "run", "-t", name2)
4441 4438
 
4442 4439
 	expected = "quux"
4443 4440
 
... ...
@@ -4457,12 +4404,7 @@ func (s *DockerSuite) TestBuildRunShEntrypoint(c *check.C) {
4457 4457
 		c.Fatal(err)
4458 4458
 	}
4459 4459
 
4460
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name))
4461
-
4462
-	if err != nil {
4463
-		c.Fatal(err, out)
4464
-	}
4465
-
4460
+	dockerCmd(c, "run", "--rm", name)
4466 4461
 }
4467 4462
 
4468 4463
 func (s *DockerSuite) TestBuildExoticShellInterpolation(c *check.C) {
... ...
@@ -4501,13 +4443,14 @@ func (s *DockerSuite) TestBuildVerifySingleQuoteFails(c *check.C) {
4501 4501
 	// it should barf on it.
4502 4502
 	name := "testbuildsinglequotefails"
4503 4503
 
4504
-	_, err := buildImage(name,
4504
+	if _, err := buildImage(name,
4505 4505
 		`FROM busybox
4506 4506
 		CMD [ '/bin/sh', '-c', 'echo hi' ]`,
4507
-		true)
4508
-	_, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name))
4507
+		true); err != nil {
4508
+		c.Fatal(err)
4509
+	}
4509 4510
 
4510
-	if err == nil {
4511
+	if _, _, err := dockerCmdWithError(c, "run", "--rm", name); err == nil {
4511 4512
 		c.Fatal("The image was not supposed to be able to run")
4512 4513
 	}
4513 4514
 
... ...
@@ -4771,10 +4714,7 @@ CMD cat /foo/file`,
4771 4771
 		c.Fatal(err)
4772 4772
 	}
4773 4773
 
4774
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name))
4775
-	if err != nil {
4776
-		c.Fatal(err)
4777
-	}
4774
+	out, _ := dockerCmd(c, "run", "--rm", name)
4778 4775
 	if out != expected {
4779 4776
 		c.Fatalf("expected file contents for /foo/file to be %q but received %q", expected, out)
4780 4777
 	}
... ...
@@ -5056,7 +4996,7 @@ func (s *DockerSuite) TestBuildDockerfileOutsideContext(c *check.C) {
5056 5056
 		filepath.Join(ctx, "dockerfile1"),
5057 5057
 		filepath.Join(ctx, "dockerfile2"),
5058 5058
 	} {
5059
-		out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "build", "-t", name, "--no-cache", "-f", dockerfilePath, "."))
5059
+		out, _, err := dockerCmdWithError(c, "build", "-t", name, "--no-cache", "-f", dockerfilePath, ".")
5060 5060
 		if err == nil {
5061 5061
 			c.Fatalf("Expected error with %s. Out: %s", dockerfilePath, out)
5062 5062
 		}
... ...
@@ -5070,7 +5010,7 @@ func (s *DockerSuite) TestBuildDockerfileOutsideContext(c *check.C) {
5070 5070
 
5071 5071
 	// Path to Dockerfile should be resolved relative to working directory, not relative to context.
5072 5072
 	// There is a Dockerfile in the context, but since there is no Dockerfile in the current directory, the following should fail
5073
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "build", "-t", name, "--no-cache", "-f", "Dockerfile", ctx))
5073
+	out, _, err := dockerCmdWithError(c, "build", "-t", name, "--no-cache", "-f", "Dockerfile", ctx)
5074 5074
 	if err == nil {
5075 5075
 		c.Fatalf("Expected error. Out: %s", out)
5076 5076
 	}
... ...
@@ -5257,9 +5197,7 @@ func (s *DockerSuite) TestBuildNotVerbose(c *check.C) {
5257 5257
 	defer ctx.Close()
5258 5258
 
5259 5259
 	// First do it w/verbose - baseline
5260
-	buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", "verbose", ".")
5261
-	buildCmd.Dir = ctx.Dir
5262
-	out, _, err := runCommandWithOutput(buildCmd)
5260
+	out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-t", "verbose", ".")
5263 5261
 	if err != nil {
5264 5262
 		c.Fatalf("failed to build the image w/o -q: %s, %v", out, err)
5265 5263
 	}
... ...
@@ -5268,9 +5206,7 @@ func (s *DockerSuite) TestBuildNotVerbose(c *check.C) {
5268 5268
 	}
5269 5269
 
5270 5270
 	// Now do it w/o verbose
5271
-	buildCmd = exec.Command(dockerBinary, "build", "--no-cache", "-q", "-t", "verbose", ".")
5272
-	buildCmd.Dir = ctx.Dir
5273
-	out, _, err = runCommandWithOutput(buildCmd)
5271
+	out, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-q", "-t", "verbose", ".")
5274 5272
 	if err != nil {
5275 5273
 		c.Fatalf("failed to build the image w/ -q: %s, %v", out, err)
5276 5274
 	}
... ...
@@ -5290,9 +5226,7 @@ RUN [ "/hello" ]`, map[string]string{})
5290 5290
 	}
5291 5291
 	defer ctx.Close()
5292 5292
 
5293
-	buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", name, ".")
5294
-	buildCmd.Dir = ctx.Dir
5295
-	out, _, err := runCommandWithOutput(buildCmd)
5293
+	out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-t", name, ".")
5296 5294
 	if err != nil {
5297 5295
 		c.Fatalf("failed to build the image: %s, %v", out, err)
5298 5296
 	}
... ...
@@ -4,7 +4,6 @@ package main
4 4
 
5 5
 import (
6 6
 	"encoding/json"
7
-	"os/exec"
8 7
 	"strings"
9 8
 
10 9
 	"github.com/go-check/check"
... ...
@@ -22,14 +21,9 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
22 22
 		c.Fatal(err)
23 23
 	}
24 24
 
25
-	cmd := exec.Command(dockerBinary, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "-t", name, ".")
26
-	cmd.Dir = ctx.Dir
25
+	dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "-t", name, ".")
27 26
 
28
-	out, _, err := runCommandWithOutput(cmd)
29
-	if err != nil {
30
-		c.Fatal(err, out)
31
-	}
32
-	out, _ = dockerCmd(c, "ps", "-lq")
27
+	out, _ := dockerCmd(c, "ps", "-lq")
33 28
 
34 29
 	cID := strings.TrimSpace(out)
35 30
 
... ...
@@ -57,7 +51,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
57 57
 	}
58 58
 
59 59
 	// Make sure constraints aren't saved to image
60
-	_, _ = dockerCmd(c, "run", "--name=test", name)
60
+	dockerCmd(c, "run", "--name=test", name)
61 61
 
62 62
 	cfg, err = inspectFieldJSON("test", "HostConfig")
63 63
 	if err != nil {
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"regexp"
7 6
 	"strings"
8 7
 
... ...
@@ -15,22 +14,18 @@ var (
15 15
 	digestRegex = regexp.MustCompile("Digest: ([^\n]+)")
16 16
 )
17 17
 
18
-func setupImage() (string, error) {
19
-	return setupImageWithTag("latest")
18
+func setupImage(c *check.C) (string, error) {
19
+	return setupImageWithTag(c, "latest")
20 20
 }
21 21
 
22
-func setupImageWithTag(tag string) (string, error) {
22
+func setupImageWithTag(c *check.C, tag string) (string, error) {
23 23
 	containerName := "busyboxbydigest"
24 24
 
25
-	cmd := exec.Command(dockerBinary, "run", "-d", "-e", "digest=1", "--name", containerName, "busybox")
26
-	if _, err := runCommand(cmd); err != nil {
27
-		return "", err
28
-	}
25
+	dockerCmd(c, "run", "-d", "-e", "digest=1", "--name", containerName, "busybox")
29 26
 
30 27
 	// tag the image to upload it to the private registry
31 28
 	repoAndTag := utils.ImageReference(repoName, tag)
32
-	cmd = exec.Command(dockerBinary, "commit", containerName, repoAndTag)
33
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
29
+	if out, _, err := dockerCmdWithError(c, "commit", containerName, repoAndTag); err != nil {
34 30
 		return "", fmt.Errorf("image tagging failed: %s, %v", out, err)
35 31
 	}
36 32
 
... ...
@@ -40,16 +35,14 @@ func setupImageWithTag(tag string) (string, error) {
40 40
 	}
41 41
 
42 42
 	// push the image
43
-	cmd = exec.Command(dockerBinary, "push", repoAndTag)
44
-	out, _, err := runCommandWithOutput(cmd)
43
+	out, _, err := dockerCmdWithError(c, "push", repoAndTag)
45 44
 	if err != nil {
46 45
 		return "", fmt.Errorf("pushing the image to the private registry has failed: %s, %v", out, err)
47 46
 	}
48 47
 
49 48
 	// delete our local repo that we previously tagged
50
-	cmd = exec.Command(dockerBinary, "rmi", repoAndTag)
51
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
52
-		return "", fmt.Errorf("error deleting images prior to real test: %s, %v", out, err)
49
+	if rmiout, _, err := dockerCmdWithError(c, "rmi", repoAndTag); err != nil {
50
+		return "", fmt.Errorf("error deleting images prior to real test: %s, %v", rmiout, err)
53 51
 	}
54 52
 
55 53
 	// the push output includes "Digest: <digest>", so find that
... ...
@@ -63,17 +56,13 @@ func setupImageWithTag(tag string) (string, error) {
63 63
 }
64 64
 
65 65
 func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
66
-	pushDigest, err := setupImage()
66
+	pushDigest, err := setupImage(c)
67 67
 	if err != nil {
68 68
 		c.Fatalf("error setting up image: %v", err)
69 69
 	}
70 70
 
71 71
 	// pull from the registry using the tag
72
-	cmd := exec.Command(dockerBinary, "pull", repoName)
73
-	out, _, err := runCommandWithOutput(cmd)
74
-	if err != nil {
75
-		c.Fatalf("error pulling by tag: %s, %v", out, err)
76
-	}
72
+	out, _ := dockerCmd(c, "pull", repoName)
77 73
 
78 74
 	// the pull output includes "Digest: <digest>", so find that
79 75
 	matches := digestRegex.FindStringSubmatch(out)
... ...
@@ -89,18 +78,14 @@ func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
89 89
 }
90 90
 
91 91
 func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
92
-	pushDigest, err := setupImage()
92
+	pushDigest, err := setupImage(c)
93 93
 	if err != nil {
94 94
 		c.Fatalf("error setting up image: %v", err)
95 95
 	}
96 96
 
97 97
 	// pull from the registry using the <name>@<digest> reference
98 98
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
99
-	cmd := exec.Command(dockerBinary, "pull", imageReference)
100
-	out, _, err := runCommandWithOutput(cmd)
101
-	if err != nil {
102
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
103
-	}
99
+	out, _ := dockerCmd(c, "pull", imageReference)
104 100
 
105 101
 	// the pull output includes "Digest: <digest>", so find that
106 102
 	matches := digestRegex.FindStringSubmatch(out)
... ...
@@ -118,15 +103,14 @@ func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
118 118
 func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) {
119 119
 	// pull from the registry using the <name>@<digest> reference
120 120
 	imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName)
121
-	cmd := exec.Command(dockerBinary, "pull", imageReference)
122
-	out, _, err := runCommandWithOutput(cmd)
121
+	out, _, err := dockerCmdWithError(c, "pull", imageReference)
123 122
 	if err == nil || !strings.Contains(out, "pulling with digest reference failed from v2 registry") {
124 123
 		c.Fatalf("expected non-zero exit status and correct error message when pulling non-existing image: %s", out)
125 124
 	}
126 125
 }
127 126
 
128 127
 func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
129
-	pushDigest, err := setupImage()
128
+	pushDigest, err := setupImage(c)
130 129
 	if err != nil {
131 130
 		c.Fatalf("error setting up image: %v", err)
132 131
 	}
... ...
@@ -134,11 +118,7 @@ func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
134 134
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
135 135
 
136 136
 	containerName := "createByDigest"
137
-	cmd := exec.Command(dockerBinary, "create", "--name", containerName, imageReference)
138
-	out, _, err := runCommandWithOutput(cmd)
139
-	if err != nil {
140
-		c.Fatalf("error creating by digest: %s, %v", out, err)
141
-	}
137
+	out, _ := dockerCmd(c, "create", "--name", containerName, imageReference)
142 138
 
143 139
 	res, err := inspectField(containerName, "Config.Image")
144 140
 	if err != nil {
... ...
@@ -150,7 +130,7 @@ func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
150 150
 }
151 151
 
152 152
 func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
153
-	pushDigest, err := setupImage()
153
+	pushDigest, err := setupImage(c)
154 154
 	if err != nil {
155 155
 		c.Fatalf("error setting up image: %v", err)
156 156
 	}
... ...
@@ -158,11 +138,7 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
158 158
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
159 159
 
160 160
 	containerName := "runByDigest"
161
-	cmd := exec.Command(dockerBinary, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest")
162
-	out, _, err := runCommandWithOutput(cmd)
163
-	if err != nil {
164
-		c.Fatalf("error run by digest: %s, %v", out, err)
165
-	}
161
+	out, _ := dockerCmd(c, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest")
166 162
 
167 163
 	foundRegex := regexp.MustCompile("found=([^\n]+)")
168 164
 	matches := foundRegex.FindStringSubmatch(out)
... ...
@@ -183,7 +159,7 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
183 183
 }
184 184
 
185 185
 func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
186
-	digest, err := setupImage()
186
+	digest, err := setupImage(c)
187 187
 	if err != nil {
188 188
 		c.Fatalf("error setting up image: %v", err)
189 189
 	}
... ...
@@ -191,11 +167,7 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
191 191
 	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
192 192
 
193 193
 	// pull from the registry using the <name>@<digest> reference
194
-	cmd := exec.Command(dockerBinary, "pull", imageReference)
195
-	out, _, err := runCommandWithOutput(cmd)
196
-	if err != nil {
197
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
198
-	}
194
+	dockerCmd(c, "pull", imageReference)
199 195
 
200 196
 	// make sure inspect runs ok
201 197
 	if _, err := inspectField(imageReference, "Id"); err != nil {
... ...
@@ -216,7 +188,7 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
216 216
 }
217 217
 
218 218
 func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
219
-	digest, err := setupImage()
219
+	digest, err := setupImage(c)
220 220
 	if err != nil {
221 221
 		c.Fatalf("error setting up image: %v", err)
222 222
 	}
... ...
@@ -224,11 +196,7 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
224 224
 	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
225 225
 
226 226
 	// pull from the registry using the <name>@<digest> reference
227
-	cmd := exec.Command(dockerBinary, "pull", imageReference)
228
-	out, _, err := runCommandWithOutput(cmd)
229
-	if err != nil {
230
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
231
-	}
227
+	dockerCmd(c, "pull", imageReference)
232 228
 
233 229
 	// get the image id
234 230
 	imageID, err := inspectField(imageReference, "Id")
... ...
@@ -258,7 +226,7 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
258 258
 }
259 259
 
260 260
 func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
261
-	digest, err := setupImage()
261
+	digest, err := setupImage(c)
262 262
 	if err != nil {
263 263
 		c.Fatalf("error setting up image: %v", err)
264 264
 	}
... ...
@@ -266,18 +234,11 @@ func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
266 266
 	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
267 267
 
268 268
 	// pull from the registry using the <name>@<digest> reference
269
-	cmd := exec.Command(dockerBinary, "pull", imageReference)
270
-	out, _, err := runCommandWithOutput(cmd)
271
-	if err != nil {
272
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
273
-	}
269
+	dockerCmd(c, "pull", imageReference)
274 270
 
275 271
 	// tag it
276 272
 	tag := "tagbydigest"
277
-	cmd = exec.Command(dockerBinary, "tag", imageReference, tag)
278
-	if _, err := runCommand(cmd); err != nil {
279
-		c.Fatalf("unexpected error tagging: %v", err)
280
-	}
273
+	dockerCmd(c, "tag", imageReference, tag)
281 274
 
282 275
 	expectedID, err := inspectField(imageReference, "Id")
283 276
 	if err != nil {
... ...
@@ -295,7 +256,7 @@ func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
295 295
 }
296 296
 
297 297
 func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
298
-	digest, err := setupImage()
298
+	digest, err := setupImage(c)
299 299
 	if err != nil {
300 300
 		c.Fatalf("error setting up image: %v", err)
301 301
 	}
... ...
@@ -303,17 +264,9 @@ func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
303 303
 	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
304 304
 
305 305
 	// pull from the registry using the <name>@<digest> reference
306
-	cmd := exec.Command(dockerBinary, "pull", imageReference)
307
-	out, _, err := runCommandWithOutput(cmd)
308
-	if err != nil {
309
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
310
-	}
306
+	dockerCmd(c, "pull", imageReference)
311 307
 
312
-	cmd = exec.Command(dockerBinary, "images")
313
-	out, _, err = runCommandWithOutput(cmd)
314
-	if err != nil {
315
-		c.Fatalf("error listing images: %s, %v", out, err)
316
-	}
308
+	out, _ := dockerCmd(c, "images")
317 309
 
318 310
 	if strings.Contains(out, "DIGEST") {
319 311
 		c.Fatalf("list output should not have contained DIGEST header: %s", out)
... ...
@@ -324,7 +277,7 @@ func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
324 324
 func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
325 325
 
326 326
 	// setup image1
327
-	digest1, err := setupImageWithTag("tag1")
327
+	digest1, err := setupImageWithTag(c, "tag1")
328 328
 	if err != nil {
329 329
 		c.Fatalf("error setting up image: %v", err)
330 330
 	}
... ...
@@ -332,18 +285,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
332 332
 	c.Logf("imageReference1 = %s", imageReference1)
333 333
 
334 334
 	// pull image1 by digest
335
-	cmd := exec.Command(dockerBinary, "pull", imageReference1)
336
-	out, _, err := runCommandWithOutput(cmd)
337
-	if err != nil {
338
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
339
-	}
335
+	dockerCmd(c, "pull", imageReference1)
340 336
 
341 337
 	// list images
342
-	cmd = exec.Command(dockerBinary, "images", "--digests")
343
-	out, _, err = runCommandWithOutput(cmd)
344
-	if err != nil {
345
-		c.Fatalf("error listing images: %s, %v", out, err)
346
-	}
338
+	out, _ := dockerCmd(c, "images", "--digests")
347 339
 
348 340
 	// make sure repo shown, tag=<none>, digest = $digest1
349 341
 	re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1 + `\s`)
... ...
@@ -352,7 +297,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
352 352
 	}
353 353
 
354 354
 	// setup image2
355
-	digest2, err := setupImageWithTag("tag2")
355
+	digest2, err := setupImageWithTag(c, "tag2")
356 356
 	if err != nil {
357 357
 		c.Fatalf("error setting up image: %v", err)
358 358
 	}
... ...
@@ -360,25 +305,13 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
360 360
 	c.Logf("imageReference2 = %s", imageReference2)
361 361
 
362 362
 	// pull image1 by digest
363
-	cmd = exec.Command(dockerBinary, "pull", imageReference1)
364
-	out, _, err = runCommandWithOutput(cmd)
365
-	if err != nil {
366
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
367
-	}
363
+	dockerCmd(c, "pull", imageReference1)
368 364
 
369 365
 	// pull image2 by digest
370
-	cmd = exec.Command(dockerBinary, "pull", imageReference2)
371
-	out, _, err = runCommandWithOutput(cmd)
372
-	if err != nil {
373
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
374
-	}
366
+	dockerCmd(c, "pull", imageReference2)
375 367
 
376 368
 	// list images
377
-	cmd = exec.Command(dockerBinary, "images", "--digests")
378
-	out, _, err = runCommandWithOutput(cmd)
379
-	if err != nil {
380
-		c.Fatalf("error listing images: %s, %v", out, err)
381
-	}
369
+	out, _ = dockerCmd(c, "images", "--digests")
382 370
 
383 371
 	// make sure repo shown, tag=<none>, digest = $digest1
384 372
 	if !re1.MatchString(out) {
... ...
@@ -392,18 +325,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
392 392
 	}
393 393
 
394 394
 	// pull tag1
395
-	cmd = exec.Command(dockerBinary, "pull", repoName+":tag1")
396
-	out, _, err = runCommandWithOutput(cmd)
397
-	if err != nil {
398
-		c.Fatalf("error pulling tag1: %s, %v", out, err)
399
-	}
395
+	dockerCmd(c, "pull", repoName+":tag1")
400 396
 
401 397
 	// list images
402
-	cmd = exec.Command(dockerBinary, "images", "--digests")
403
-	out, _, err = runCommandWithOutput(cmd)
404
-	if err != nil {
405
-		c.Fatalf("error listing images: %s, %v", out, err)
406
-	}
398
+	out, _ = dockerCmd(c, "images", "--digests")
407 399
 
408 400
 	// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
409 401
 	reWithTag1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*<none>\s`)
... ...
@@ -420,18 +345,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
420 420
 	}
421 421
 
422 422
 	// pull tag 2
423
-	cmd = exec.Command(dockerBinary, "pull", repoName+":tag2")
424
-	out, _, err = runCommandWithOutput(cmd)
425
-	if err != nil {
426
-		c.Fatalf("error pulling tag2: %s, %v", out, err)
427
-	}
423
+	dockerCmd(c, "pull", repoName+":tag2")
428 424
 
429 425
 	// list images
430
-	cmd = exec.Command(dockerBinary, "images", "--digests")
431
-	out, _, err = runCommandWithOutput(cmd)
432
-	if err != nil {
433
-		c.Fatalf("error listing images: %s, %v", out, err)
434
-	}
426
+	out, _ = dockerCmd(c, "images", "--digests")
435 427
 
436 428
 	// make sure image 1 has repo, tag, digest
437 429
 	if !reWithTag1.MatchString(out) {
... ...
@@ -449,11 +366,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
449 449
 	}
450 450
 
451 451
 	// list images
452
-	cmd = exec.Command(dockerBinary, "images", "--digests")
453
-	out, _, err = runCommandWithOutput(cmd)
454
-	if err != nil {
455
-		c.Fatalf("error listing images: %s, %v", out, err)
456
-	}
452
+	out, _ = dockerCmd(c, "images", "--digests")
457 453
 
458 454
 	// make sure image 1 has repo, tag, digest
459 455
 	if !reWithTag1.MatchString(out) {
... ...
@@ -471,18 +384,14 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
471 471
 }
472 472
 
473 473
 func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) {
474
-	pushDigest, err := setupImage()
474
+	pushDigest, err := setupImage(c)
475 475
 	if err != nil {
476 476
 		c.Fatalf("error setting up image: %v", err)
477 477
 	}
478 478
 
479 479
 	// pull from the registry using the <name>@<digest> reference
480 480
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
481
-	cmd := exec.Command(dockerBinary, "pull", imageReference)
482
-	out, _, err := runCommandWithOutput(cmd)
483
-	if err != nil {
484
-		c.Fatalf("error pulling by digest: %s, %v", out, err)
485
-	}
481
+	dockerCmd(c, "pull", imageReference)
486 482
 	// just in case...
487 483
 
488 484
 	imageID, err := inspectField(imageReference, "Id")
... ...
@@ -490,8 +399,5 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C)
490 490
 		c.Fatalf("error inspecting image id: %v", err)
491 491
 	}
492 492
 
493
-	cmd = exec.Command(dockerBinary, "rmi", imageID)
494
-	if _, err := runCommand(cmd); err != nil {
495
-		c.Fatalf("error deleting image by id: %v", err)
496
-	}
493
+	dockerCmd(c, "rmi", imageID)
497 494
 }
... ...
@@ -1,91 +1,51 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"os/exec"
5 4
 	"strings"
6 5
 
7 6
 	"github.com/go-check/check"
8 7
 )
9 8
 
10 9
 func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
11
-	runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
12
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
13
-	if err != nil {
14
-		c.Fatalf("failed to run container: %s, %v", out, err)
15
-	}
10
+	out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
16 11
 
17 12
 	cleanedContainerID := strings.TrimSpace(out)
18 13
 
19
-	waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
20
-	if _, _, err = runCommandWithOutput(waitCmd); err != nil {
21
-		c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
22
-	}
14
+	dockerCmd(c, "wait", cleanedContainerID)
23 15
 
24
-	commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID)
25
-	out, _, err = runCommandWithOutput(commitCmd)
26
-	if err != nil {
27
-		c.Fatalf("failed to commit container to image: %s, %v", out, err)
28
-	}
16
+	out, _ = dockerCmd(c, "commit", cleanedContainerID)
29 17
 
30 18
 	cleanedImageID := strings.TrimSpace(out)
31 19
 
32
-	inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
33
-	if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
34
-		c.Fatalf("failed to inspect image: %s, %v", out, err)
35
-	}
20
+	dockerCmd(c, "inspect", cleanedImageID)
36 21
 }
37 22
 
38 23
 func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
39
-	runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
40
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
41
-	if err != nil {
42
-		c.Fatalf("failed to run container: %s, %v", out, err)
43
-	}
24
+	out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
44 25
 
45 26
 	cleanedContainerID := strings.TrimSpace(out)
46 27
 
47
-	waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
48
-	if _, _, err = runCommandWithOutput(waitCmd); err != nil {
49
-		c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
50
-	}
28
+	dockerCmd(c, "wait", cleanedContainerID)
51 29
 
52
-	commitCmd := exec.Command(dockerBinary, "commit", "-p=false", cleanedContainerID)
53
-	out, _, err = runCommandWithOutput(commitCmd)
54
-	if err != nil {
55
-		c.Fatalf("failed to commit container to image: %s, %v", out, err)
56
-	}
30
+	out, _ = dockerCmd(c, "commit", "-p=false", cleanedContainerID)
57 31
 
58 32
 	cleanedImageID := strings.TrimSpace(out)
59 33
 
60
-	inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
61
-	if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
62
-		c.Fatalf("failed to inspect image: %s, %v", out, err)
63
-	}
34
+	dockerCmd(c, "inspect", cleanedImageID)
64 35
 }
65 36
 
66 37
 //test commit a paused container should not unpause it after commit
67 38
 func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
68 39
 	defer unpauseAllContainers()
69
-	cmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox")
70
-	out, _, _, err := runCommandWithStdoutStderr(cmd)
71
-	if err != nil {
72
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
73
-	}
40
+	out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
74 41
 
75 42
 	cleanedContainerID := strings.TrimSpace(out)
76
-	cmd = exec.Command(dockerBinary, "pause", cleanedContainerID)
77
-	out, _, _, err = runCommandWithStdoutStderr(cmd)
78
-	if err != nil {
79
-		c.Fatalf("failed to pause container: %v, output: %q", err, out)
80
-	}
81 43
 
82
-	commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID)
83
-	out, _, err = runCommandWithOutput(commitCmd)
84
-	if err != nil {
85
-		c.Fatalf("failed to commit container to image: %s, %v", out, err)
86
-	}
44
+	dockerCmd(c, "pause", cleanedContainerID)
45
+
46
+	out, _ = dockerCmd(c, "commit", cleanedContainerID)
87 47
 
88
-	out, err = inspectField(cleanedContainerID, "State.Paused")
48
+	out, err := inspectField(cleanedContainerID, "State.Paused")
89 49
 	c.Assert(err, check.IsNil)
90 50
 	if !strings.Contains(out, "true") {
91 51
 		c.Fatalf("commit should not unpause a paused container")
... ...
@@ -94,24 +54,13 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
94 94
 
95 95
 func (s *DockerSuite) TestCommitNewFile(c *check.C) {
96 96
 
97
-	cmd := exec.Command(dockerBinary, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
98
-	if _, err := runCommand(cmd); err != nil {
99
-		c.Fatal(err)
100
-	}
97
+	dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
101 98
 
102
-	cmd = exec.Command(dockerBinary, "commit", "commiter")
103
-	imageID, _, err := runCommandWithOutput(cmd)
104
-	if err != nil {
105
-		c.Fatal(err)
106
-	}
99
+	imageID, _ := dockerCmd(c, "commit", "commiter")
107 100
 	imageID = strings.Trim(imageID, "\r\n")
108 101
 
109
-	cmd = exec.Command(dockerBinary, "run", imageID, "cat", "/foo")
102
+	out, _ := dockerCmd(c, "run", imageID, "cat", "/foo")
110 103
 
111
-	out, _, err := runCommandWithOutput(cmd)
112
-	if err != nil {
113
-		c.Fatal(err, out)
114
-	}
115 104
 	if actual := strings.Trim(out, "\r\n"); actual != "koye" {
116 105
 		c.Fatalf("expected output koye received %q", actual)
117 106
 	}
... ...
@@ -120,13 +69,9 @@ func (s *DockerSuite) TestCommitNewFile(c *check.C) {
120 120
 
121 121
 func (s *DockerSuite) TestCommitHardlink(c *check.C) {
122 122
 
123
-	cmd := exec.Command(dockerBinary, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
124
-	firstOuput, _, err := runCommandWithOutput(cmd)
125
-	if err != nil {
126
-		c.Fatal(err)
127
-	}
123
+	firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
128 124
 
129
-	chunks := strings.Split(strings.TrimSpace(firstOuput), " ")
125
+	chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
130 126
 	inode := chunks[0]
131 127
 	found := false
132 128
 	for _, chunk := range chunks[1:] {
... ...
@@ -139,20 +84,12 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
139 139
 		c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
140 140
 	}
141 141
 
142
-	cmd = exec.Command(dockerBinary, "commit", "hardlinks", "hardlinks")
143
-	imageID, _, err := runCommandWithOutput(cmd)
144
-	if err != nil {
145
-		c.Fatal(imageID, err)
146
-	}
142
+	imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
147 143
 	imageID = strings.Trim(imageID, "\r\n")
148 144
 
149
-	cmd = exec.Command(dockerBinary, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
150
-	secondOuput, _, err := runCommandWithOutput(cmd)
151
-	if err != nil {
152
-		c.Fatal(err)
153
-	}
145
+	secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
154 146
 
155
-	chunks = strings.Split(strings.TrimSpace(secondOuput), " ")
147
+	chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
156 148
 	inode = chunks[0]
157 149
 	found = false
158 150
 	for _, chunk := range chunks[1:] {
... ...
@@ -169,56 +106,31 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
169 169
 
170 170
 func (s *DockerSuite) TestCommitTTY(c *check.C) {
171 171
 
172
-	cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
173
-	if _, err := runCommand(cmd); err != nil {
174
-		c.Fatal(err)
175
-	}
172
+	dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
176 173
 
177
-	cmd = exec.Command(dockerBinary, "commit", "tty", "ttytest")
178
-	imageID, _, err := runCommandWithOutput(cmd)
179
-	if err != nil {
180
-		c.Fatal(err)
181
-	}
174
+	imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
182 175
 	imageID = strings.Trim(imageID, "\r\n")
183 176
 
184
-	cmd = exec.Command(dockerBinary, "run", "ttytest", "/bin/ls")
185
-	if _, err := runCommand(cmd); err != nil {
186
-		c.Fatal(err)
187
-	}
177
+	dockerCmd(c, "run", "ttytest", "/bin/ls")
188 178
 
189 179
 }
190 180
 
191 181
 func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
192 182
 
193
-	cmd := exec.Command(dockerBinary, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
194
-	if _, err := runCommand(cmd); err != nil {
195
-		c.Fatal(err)
196
-	}
197
-
198
-	cmd = exec.Command(dockerBinary, "commit", "bind-commit", "bindtest")
199
-	imageID, _, err := runCommandWithOutput(cmd)
200
-	if err != nil {
201
-		c.Fatal(imageID, err)
202
-	}
183
+	dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
203 184
 
185
+	imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
204 186
 	imageID = strings.Trim(imageID, "\r\n")
205 187
 
206
-	cmd = exec.Command(dockerBinary, "run", "bindtest", "true")
207
-
208
-	if _, err := runCommand(cmd); err != nil {
209
-		c.Fatal(err)
210
-	}
188
+	dockerCmd(c, "run", "bindtest", "true")
211 189
 
212 190
 }
213 191
 
214 192
 func (s *DockerSuite) TestCommitChange(c *check.C) {
215 193
 
216
-	cmd := exec.Command(dockerBinary, "run", "--name", "test", "busybox", "true")
217
-	if _, err := runCommand(cmd); err != nil {
218
-		c.Fatal(err)
219
-	}
194
+	dockerCmd(c, "run", "--name", "test", "busybox", "true")
220 195
 
221
-	cmd = exec.Command(dockerBinary, "commit",
196
+	imageID, _ := dockerCmd(c, "commit",
222 197
 		"--change", "EXPOSE 8080",
223 198
 		"--change", "ENV DEBUG true",
224 199
 		"--change", "ENV test 1",
... ...
@@ -231,11 +143,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
231 231
 		"--change", "VOLUME /var/lib/docker",
232 232
 		"--change", "ONBUILD /usr/local/bin/python-build --dir /app/src",
233 233
 		"test", "test-commit")
234
-	imageId, _, err := runCommandWithOutput(cmd)
235
-	if err != nil {
236
-		c.Fatal(imageId, err)
237
-	}
238
-	imageId = strings.Trim(imageId, "\r\n")
234
+	imageID = strings.Trim(imageID, "\r\n")
239 235
 
240 236
 	expected := map[string]string{
241 237
 		"Config.ExposedPorts": "map[8080/tcp:{}]",
... ...
@@ -250,7 +158,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
250 250
 	}
251 251
 
252 252
 	for conf, value := range expected {
253
-		res, err := inspectField(imageId, conf)
253
+		res, err := inspectField(imageID, conf)
254 254
 		c.Assert(err, check.IsNil)
255 255
 		if res != value {
256 256
 			c.Errorf("%s('%s'), expected %s", conf, res, value)
... ...
@@ -69,17 +69,16 @@ func (s *DockerSuite) TestConfigDir(c *check.C) {
69 69
 	cDir, _ := ioutil.TempDir("", "fake-home")
70 70
 
71 71
 	// First make sure pointing to empty dir doesn't generate an error
72
-	cmd := exec.Command(dockerBinary, "--config", cDir, "ps")
73
-	out, rc, err := runCommandWithOutput(cmd)
72
+	out, rc := dockerCmd(c, "--config", cDir, "ps")
74 73
 
75
-	if rc != 0 || err != nil {
76
-		c.Fatalf("ps1 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err)
74
+	if rc != 0 {
75
+		c.Fatalf("ps1 didn't work:\nrc:%d\nout%s", rc, out)
77 76
 	}
78 77
 
79 78
 	// Test with env var too
80
-	cmd = exec.Command(dockerBinary, "ps")
79
+	cmd := exec.Command(dockerBinary, "ps")
81 80
 	cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir)
82
-	out, rc, err = runCommandWithOutput(cmd)
81
+	out, rc, err := runCommandWithOutput(cmd)
83 82
 
84 83
 	if rc != 0 || err != nil {
85 84
 		c.Fatalf("ps2 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err)
... ...
@@ -61,7 +61,7 @@ func (s *DockerSuite) TestCpGarbagePath(c *check.C) {
61 61
 
62 62
 	path := path.Join("../../../../../../../../../../../../", cpFullPath)
63 63
 
64
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
64
+	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
65 65
 
66 66
 	file, _ := os.Open(tmpname)
67 67
 	defer file.Close()
... ...
@@ -126,7 +126,7 @@ func (s *DockerSuite) TestCpRelativePath(c *check.C) {
126 126
 		c.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
127 127
 	}
128 128
 
129
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
129
+	dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
130 130
 
131 131
 	file, _ := os.Open(tmpname)
132 132
 	defer file.Close()
... ...
@@ -184,7 +184,7 @@ func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
184 184
 
185 185
 	path := cpFullPath
186 186
 
187
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
187
+	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
188 188
 
189 189
 	file, _ := os.Open(tmpname)
190 190
 	defer file.Close()
... ...
@@ -243,7 +243,7 @@ func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
243 243
 
244 244
 	path := path.Join("/", "container_path")
245 245
 
246
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
246
+	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
247 247
 
248 248
 	file, _ := os.Open(tmpname)
249 249
 	defer file.Close()
... ...
@@ -302,7 +302,7 @@ func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
302 302
 
303 303
 	path := path.Join("/", "container_path", cpTestName)
304 304
 
305
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
305
+	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
306 306
 
307 307
 	file, _ := os.Open(tmpname)
308 308
 	defer file.Close()
... ...
@@ -380,7 +380,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
380 380
 	}
381 381
 
382 382
 	// Copy actual /etc/resolv.conf
383
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
383
+	dockerCmd(c, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
384 384
 
385 385
 	expected, err := ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/resolv.conf")
386 386
 	actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
... ...
@@ -390,7 +390,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
390 390
 	}
391 391
 
392 392
 	// Copy actual /etc/hosts
393
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hosts", outDir)
393
+	dockerCmd(c, "cp", cleanedContainerID+":/etc/hosts", outDir)
394 394
 
395 395
 	expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hosts")
396 396
 	actual, err = ioutil.ReadFile(outDir + "/hosts")
... ...
@@ -400,7 +400,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
400 400
 	}
401 401
 
402 402
 	// Copy actual /etc/resolv.conf
403
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hostname", outDir)
403
+	dockerCmd(c, "cp", cleanedContainerID+":/etc/hostname", outDir)
404 404
 
405 405
 	expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hostname")
406 406
 	actual, err = ioutil.ReadFile(outDir + "/hostname")
... ...
@@ -442,7 +442,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
442 442
 	}
443 443
 
444 444
 	// Copy actual volume path
445
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
445
+	dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
446 446
 
447 447
 	stat, err := os.Stat(outDir + "/foo")
448 448
 	if err != nil {
... ...
@@ -460,7 +460,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
460 460
 	}
461 461
 
462 462
 	// Copy file nested in volume
463
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo/bar", outDir)
463
+	dockerCmd(c, "cp", cleanedContainerID+":/foo/bar", outDir)
464 464
 
465 465
 	stat, err = os.Stat(outDir + "/bar")
466 466
 	if err != nil {
... ...
@@ -471,7 +471,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
471 471
 	}
472 472
 
473 473
 	// Copy Bind-mounted dir
474
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
474
+	dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
475 475
 	stat, err = os.Stat(outDir + "/baz")
476 476
 	if err != nil {
477 477
 		c.Fatal(err)
... ...
@@ -481,7 +481,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
481 481
 	}
482 482
 
483 483
 	// Copy file nested in bind-mounted dir
484
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz/test", outDir)
484
+	dockerCmd(c, "cp", cleanedContainerID+":/baz/test", outDir)
485 485
 	fb, err := ioutil.ReadFile(outDir + "/baz/test")
486 486
 	if err != nil {
487 487
 		c.Fatal(err)
... ...
@@ -495,7 +495,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
495 495
 	}
496 496
 
497 497
 	// Copy bind-mounted file
498
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
498
+	dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
499 499
 	fb, err = ioutil.ReadFile(outDir + "/test")
500 500
 	if err != nil {
501 501
 		c.Fatal(err)
... ...
@@ -536,7 +536,7 @@ func (s *DockerSuite) TestCpToDot(c *check.C) {
536 536
 	if err := os.Chdir(tmpdir); err != nil {
537 537
 		c.Fatal(err)
538 538
 	}
539
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
539
+	dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
540 540
 	content, err := ioutil.ReadFile("./test")
541 541
 	if string(content) != "lololol\n" {
542 542
 		c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
... ...
@@ -589,7 +589,7 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
589 589
 		c.Fatal(err)
590 590
 	}
591 591
 	defer os.RemoveAll(tmpdir)
592
-	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/te:s:t", tmpdir)
592
+	dockerCmd(c, "cp", cleanedContainerID+":/te:s:t", tmpdir)
593 593
 	content, err := ioutil.ReadFile(tmpdir + "/te:s:t")
594 594
 	if string(content) != "lololol\n" {
595 595
 		c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
... ...
@@ -598,17 +598,12 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
598 598
 
599 599
 func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
600 600
 	expectedMsg := "hello"
601
-	out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", expectedMsg).CombinedOutput()
602
-	if err != nil {
603
-		c.Fatal(string(out), err)
604
-	}
601
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg)
605 602
 	id := strings.TrimSpace(string(out))
606 603
 
607
-	if out, err = exec.Command(dockerBinary, "wait", id).CombinedOutput(); err != nil {
608
-		c.Fatalf("unable to wait for container: %s", err)
609
-	}
604
+	out, _ = dockerCmd(c, "wait", id)
610 605
 
611
-	status := strings.TrimSpace(string(out))
606
+	status := strings.TrimSpace(out)
612 607
 	if status != "0" {
613 608
 		c.Fatalf("container exited with status %s", status)
614 609
 	}
... ...
@@ -619,33 +614,23 @@ func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
619 619
 	}
620 620
 	defer os.RemoveAll(tmpDir)
621 621
 
622
-	if _, err = exec.Command(dockerBinary, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir).CombinedOutput(); err != nil {
623
-		c.Fatalf("unable to copy from busybox container: %s", err)
624
-	}
622
+	dockerCmd(c, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir)
625 623
 
626
-	if out, err = exec.Command(dockerBinary, "start", "-a", id).CombinedOutput(); err != nil {
627
-		c.Fatalf("unable to start busybox container after copy: %s - %s", err, out)
628
-	}
624
+	out, _ = dockerCmd(c, "start", "-a", id)
629 625
 
630
-	msg := strings.TrimSpace(string(out))
626
+	msg := strings.TrimSpace(out)
631 627
 	if msg != expectedMsg {
632 628
 		c.Fatalf("expected %q but got %q", expectedMsg, msg)
633 629
 	}
634 630
 }
635 631
 
636 632
 func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
637
-	out, err := exec.Command(dockerBinary, "create", "--name", "test_cp", "-v", "/test", "busybox").CombinedOutput()
638
-	if err != nil {
639
-		c.Fatalf(string(out), err)
640
-	}
633
+	dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
641 634
 
642 635
 	tmpDir, err := ioutil.TempDir("", "test")
643 636
 	if err != nil {
644 637
 		c.Fatalf("unable to make temporary directory: %s", err)
645 638
 	}
646 639
 	defer os.RemoveAll(tmpDir)
647
-	out, err = exec.Command(dockerBinary, "cp", "test_cp:/bin/sh", tmpDir).CombinedOutput()
648
-	if err != nil {
649
-		c.Fatalf(string(out), err)
650
-	}
640
+	dockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir)
651 641
 }
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6 6
 	"os"
7
-	"os/exec"
8 7
 	"reflect"
9 8
 	"strings"
10 9
 	"time"
... ...
@@ -15,19 +14,11 @@ import (
15 15
 
16 16
 // Make sure we can create a simple container with some args
17 17
 func (s *DockerSuite) TestCreateArgs(c *check.C) {
18
-	runCmd := exec.Command(dockerBinary, "create", "busybox", "command", "arg1", "arg2", "arg with space")
19
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
20
-	if err != nil {
21
-		c.Fatal(out, err)
22
-	}
18
+	out, _ := dockerCmd(c, "create", "busybox", "command", "arg1", "arg2", "arg with space")
23 19
 
24 20
 	cleanedContainerID := strings.TrimSpace(out)
25 21
 
26
-	inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
27
-	out, _, err = runCommandWithOutput(inspectCmd)
28
-	if err != nil {
29
-		c.Fatalf("out should've been a container id: %s, %v", out, err)
30
-	}
22
+	out, _ = dockerCmd(c, "inspect", cleanedContainerID)
31 23
 
32 24
 	containers := []struct {
33 25
 		ID      string
... ...
@@ -65,19 +56,11 @@ func (s *DockerSuite) TestCreateArgs(c *check.C) {
65 65
 // Make sure we can set hostconfig options too
66 66
 func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
67 67
 
68
-	runCmd := exec.Command(dockerBinary, "create", "-P", "busybox", "echo")
69
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
70
-	if err != nil {
71
-		c.Fatal(out, err)
72
-	}
68
+	out, _ := dockerCmd(c, "create", "-P", "busybox", "echo")
73 69
 
74 70
 	cleanedContainerID := strings.TrimSpace(out)
75 71
 
76
-	inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
77
-	out, _, err = runCommandWithOutput(inspectCmd)
78
-	if err != nil {
79
-		c.Fatalf("out should've been a container id: %s, %v", out, err)
80
-	}
72
+	out, _ = dockerCmd(c, "inspect", cleanedContainerID)
81 73
 
82 74
 	containers := []struct {
83 75
 		HostConfig *struct {
... ...
@@ -104,19 +87,11 @@ func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
104 104
 
105 105
 func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
106 106
 
107
-	runCmd := exec.Command(dockerBinary, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo")
108
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
109
-	if err != nil {
110
-		c.Fatal(out, err)
111
-	}
107
+	out, _ := dockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo")
112 108
 
113 109
 	cleanedContainerID := strings.TrimSpace(out)
114 110
 
115
-	inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
116
-	out, _, err = runCommandWithOutput(inspectCmd)
117
-	if err != nil {
118
-		c.Fatalf("out should've been a container id: %s, %v", out, err)
119
-	}
111
+	out, _ = dockerCmd(c, "inspect", cleanedContainerID)
120 112
 
121 113
 	containers := []struct {
122 114
 		HostConfig *struct {
... ...
@@ -151,19 +126,11 @@ func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
151 151
 
152 152
 func (s *DockerSuite) TestCreateWithiLargePortRange(c *check.C) {
153 153
 
154
-	runCmd := exec.Command(dockerBinary, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo")
155
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
156
-	if err != nil {
157
-		c.Fatal(out, err)
158
-	}
154
+	out, _ := dockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo")
159 155
 
160 156
 	cleanedContainerID := strings.TrimSpace(out)
161 157
 
162
-	inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
163
-	out, _, err = runCommandWithOutput(inspectCmd)
164
-	if err != nil {
165
-		c.Fatalf("out should've been a container id: %s, %v", out, err)
166
-	}
158
+	out, _ = dockerCmd(c, "inspect", cleanedContainerID)
167 159
 
168 160
 	containers := []struct {
169 161
 		HostConfig *struct {
... ...
@@ -199,19 +166,11 @@ func (s *DockerSuite) TestCreateWithiLargePortRange(c *check.C) {
199 199
 // "test123" should be printed by docker create + start
200 200
 func (s *DockerSuite) TestCreateEchoStdout(c *check.C) {
201 201
 
202
-	runCmd := exec.Command(dockerBinary, "create", "busybox", "echo", "test123")
203
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
204
-	if err != nil {
205
-		c.Fatal(out, err)
206
-	}
202
+	out, _ := dockerCmd(c, "create", "busybox", "echo", "test123")
207 203
 
208 204
 	cleanedContainerID := strings.TrimSpace(out)
209 205
 
210
-	runCmd = exec.Command(dockerBinary, "start", "-ai", cleanedContainerID)
211
-	out, _, _, err = runCommandWithStdoutStderr(runCmd)
212
-	if err != nil {
213
-		c.Fatal(out, err)
214
-	}
206
+	out, _ = dockerCmd(c, "start", "-ai", cleanedContainerID)
215 207
 
216 208
 	if out != "test123\n" {
217 209
 		c.Errorf("container should've printed 'test123', got %q", out)
... ...
@@ -223,9 +182,8 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
223 223
 	testRequires(c, SameHostDaemon)
224 224
 
225 225
 	name := "test_create_volume"
226
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "--name", name, "-v", "/foo", "busybox")); err != nil {
227
-		c.Fatal(out, err)
228
-	}
226
+	dockerCmd(c, "create", "--name", name, "-v", "/foo", "busybox")
227
+
229 228
 	dir, err := inspectFieldMap(name, "Volumes", "/foo")
230 229
 	if err != nil {
231 230
 		c.Fatalf("Error getting volume host path: %q", err)
... ...
@@ -243,9 +201,7 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
243 243
 func (s *DockerSuite) TestCreateLabels(c *check.C) {
244 244
 	name := "test_create_labels"
245 245
 	expected := map[string]string{"k1": "v1", "k2": "v2"}
246
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")); err != nil {
247
-		c.Fatal(out, err)
248
-	}
246
+	dockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")
249 247
 
250 248
 	actual := make(map[string]string)
251 249
 	err := inspectFieldAndMarshall(name, "Config.Labels", &actual)
... ...
@@ -270,9 +226,7 @@ func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) {
270 270
 
271 271
 	name := "test_create_labels_from_image"
272 272
 	expected := map[string]string{"k2": "x", "k3": "v3"}
273
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "--name", name, "-l", "k2=x", "--label", "k3=v3", imageName)); err != nil {
274
-		c.Fatal(out, err)
275
-	}
273
+	dockerCmd(c, "create", "--name", name, "-l", "k2=x", "--label", "k3=v3", imageName)
276 274
 
277 275
 	actual := make(map[string]string)
278 276
 	err = inspectFieldAndMarshall(name, "Config.Labels", &actual)
... ...
@@ -297,47 +251,23 @@ func (s *DockerSuite) TestCreateRM(c *check.C) {
297 297
 	// "Created" state, and has ever been run. Test "rm -f" too.
298 298
 
299 299
 	// create a container
300
-	createCmd := exec.Command(dockerBinary, "create", "busybox")
301
-	out, _, err := runCommandWithOutput(createCmd)
302
-	if err != nil {
303
-		c.Fatalf("Failed to create container:%s\n%s", out, err)
304
-	}
300
+	out, _ := dockerCmd(c, "create", "busybox")
305 301
 	cID := strings.TrimSpace(out)
306 302
 
307
-	rmCmd := exec.Command(dockerBinary, "rm", cID)
308
-	out, _, err = runCommandWithOutput(rmCmd)
309
-	if err != nil {
310
-		c.Fatalf("Failed to rm container:%s\n%s", out, err)
311
-	}
303
+	dockerCmd(c, "rm", cID)
312 304
 
313 305
 	// Now do it again so we can "rm -f" this time
314
-	createCmd = exec.Command(dockerBinary, "create", "busybox")
315
-	out, _, err = runCommandWithOutput(createCmd)
316
-	if err != nil {
317
-		c.Fatalf("Failed to create 2nd container:%s\n%s", out, err)
318
-	}
306
+	out, _ = dockerCmd(c, "create", "busybox")
319 307
 
320 308
 	cID = strings.TrimSpace(out)
321
-	rmCmd = exec.Command(dockerBinary, "rm", "-f", cID)
322
-	out, _, err = runCommandWithOutput(rmCmd)
323
-	if err != nil {
324
-		c.Fatalf("Failed to rm -f container:%s\n%s", out, err)
325
-	}
309
+	dockerCmd(c, "rm", "-f", cID)
326 310
 }
327 311
 
328 312
 func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) {
329 313
 	testRequires(c, SameHostDaemon)
330 314
 
331
-	cmd := exec.Command(dockerBinary, "create", "busybox")
332
-	out, _, err := runCommandWithOutput(cmd)
333
-	if err != nil {
334
-		c.Fatal(err, out)
335
-	}
315
+	out, _ := dockerCmd(c, "create", "busybox")
336 316
 	id := strings.TrimSpace(out)
337 317
 
338
-	cmd = exec.Command(dockerBinary, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox")
339
-	out, _, err = runCommandWithOutput(cmd)
340
-	if err != nil {
341
-		c.Fatalf("Create container with ipc mode container should success with non running container: %s\n%s", out, err)
342
-	}
318
+	dockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox")
343 319
 }
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"strings"
7 6
 
8 7
 	"github.com/go-check/check"
... ...
@@ -27,8 +26,7 @@ func (s *DockerSuite) TestPause(c *check.C) {
27 27
 
28 28
 	dockerCmd(c, "unpause", name)
29 29
 
30
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
31
-	out, _, _ = runCommandWithOutput(eventsCmd)
30
+	out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
32 31
 	events := strings.Split(out, "\n")
33 32
 	if len(events) <= 1 {
34 33
 		c.Fatalf("Missing expected event")
... ...
@@ -69,8 +67,7 @@ func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
69 69
 
70 70
 	dockerCmd(c, append([]string{"unpause"}, containers...)...)
71 71
 
72
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
73
-	out, _, _ = runCommandWithOutput(eventsCmd)
72
+	out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
74 73
 	events := strings.Split(out, "\n")
75 74
 	if len(events) <= len(containers)*3-2 {
76 75
 		c.Fatalf("Missing expected event")
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"regexp"
7 6
 	"sort"
8 7
 	"strings"
... ...
@@ -13,64 +12,37 @@ import (
13 13
 func (s *DockerSuite) TestPortList(c *check.C) {
14 14
 
15 15
 	// one port
16
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox", "top")
17
-	out, _, err := runCommandWithOutput(runCmd)
18
-	if err != nil {
19
-		c.Fatal(out, err)
20
-	}
16
+	out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", "top")
21 17
 	firstID := strings.TrimSpace(out)
22 18
 
23
-	runCmd = exec.Command(dockerBinary, "port", firstID, "80")
24
-	out, _, err = runCommandWithOutput(runCmd)
25
-	if err != nil {
26
-		c.Fatal(out, err)
27
-	}
19
+	out, _ = dockerCmd(c, "port", firstID, "80")
28 20
 
29 21
 	if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
30 22
 		c.Error("Port list is not correct")
31 23
 	}
32 24
 
33
-	runCmd = exec.Command(dockerBinary, "port", firstID)
34
-	out, _, err = runCommandWithOutput(runCmd)
35
-	if err != nil {
36
-		c.Fatal(out, err)
37
-	}
25
+	out, _ = dockerCmd(c, "port", firstID)
38 26
 
39 27
 	if !assertPortList(c, out, []string{"80/tcp -> 0.0.0.0:9876"}) {
40 28
 		c.Error("Port list is not correct")
41 29
 	}
42
-	runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
43
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
44
-		c.Fatal(out, err)
45
-	}
30
+	dockerCmd(c, "rm", "-f", firstID)
46 31
 
47 32
 	// three port
48
-	runCmd = exec.Command(dockerBinary, "run", "-d",
33
+	out, _ = dockerCmd(c, "run", "-d",
49 34
 		"-p", "9876:80",
50 35
 		"-p", "9877:81",
51 36
 		"-p", "9878:82",
52 37
 		"busybox", "top")
53
-	out, _, err = runCommandWithOutput(runCmd)
54
-	if err != nil {
55
-		c.Fatal(out, err)
56
-	}
57 38
 	ID := strings.TrimSpace(out)
58 39
 
59
-	runCmd = exec.Command(dockerBinary, "port", ID, "80")
60
-	out, _, err = runCommandWithOutput(runCmd)
61
-	if err != nil {
62
-		c.Fatal(out, err)
63
-	}
40
+	out, _ = dockerCmd(c, "port", ID, "80")
64 41
 
65 42
 	if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
66 43
 		c.Error("Port list is not correct")
67 44
 	}
68 45
 
69
-	runCmd = exec.Command(dockerBinary, "port", ID)
70
-	out, _, err = runCommandWithOutput(runCmd)
71
-	if err != nil {
72
-		c.Fatal(out, err)
73
-	}
46
+	out, _ = dockerCmd(c, "port", ID)
74 47
 
75 48
 	if !assertPortList(c, out, []string{
76 49
 		"80/tcp -> 0.0.0.0:9876",
... ...
@@ -78,40 +50,24 @@ func (s *DockerSuite) TestPortList(c *check.C) {
78 78
 		"82/tcp -> 0.0.0.0:9878"}) {
79 79
 		c.Error("Port list is not correct")
80 80
 	}
81
-	runCmd = exec.Command(dockerBinary, "rm", "-f", ID)
82
-	out, _, err = runCommandWithOutput(runCmd)
83
-	if err != nil {
84
-		c.Fatal(out, err)
85
-	}
81
+	dockerCmd(c, "rm", "-f", ID)
86 82
 
87 83
 	// more and one port mapped to the same container port
88
-	runCmd = exec.Command(dockerBinary, "run", "-d",
84
+	out, _ = dockerCmd(c, "run", "-d",
89 85
 		"-p", "9876:80",
90 86
 		"-p", "9999:80",
91 87
 		"-p", "9877:81",
92 88
 		"-p", "9878:82",
93 89
 		"busybox", "top")
94
-	out, _, err = runCommandWithOutput(runCmd)
95
-	if err != nil {
96
-		c.Fatal(out, err)
97
-	}
98 90
 	ID = strings.TrimSpace(out)
99 91
 
100
-	runCmd = exec.Command(dockerBinary, "port", ID, "80")
101
-	out, _, err = runCommandWithOutput(runCmd)
102
-	if err != nil {
103
-		c.Fatal(out, err)
104
-	}
92
+	out, _ = dockerCmd(c, "port", ID, "80")
105 93
 
106 94
 	if !assertPortList(c, out, []string{"0.0.0.0:9876", "0.0.0.0:9999"}) {
107 95
 		c.Error("Port list is not correct")
108 96
 	}
109 97
 
110
-	runCmd = exec.Command(dockerBinary, "port", ID)
111
-	out, _, err = runCommandWithOutput(runCmd)
112
-	if err != nil {
113
-		c.Fatal(out, err)
114
-	}
98
+	out, _ = dockerCmd(c, "port", ID)
115 99
 
116 100
 	if !assertPortList(c, out, []string{
117 101
 		"80/tcp -> 0.0.0.0:9876",
... ...
@@ -120,10 +76,7 @@ func (s *DockerSuite) TestPortList(c *check.C) {
120 120
 		"82/tcp -> 0.0.0.0:9878"}) {
121 121
 		c.Error("Port list is not correct\n", out)
122 122
 	}
123
-	runCmd = exec.Command(dockerBinary, "rm", "-f", ID)
124
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
125
-		c.Fatal(out, err)
126
-	}
123
+	dockerCmd(c, "rm", "-f", ID)
127 124
 
128 125
 }
129 126
 
... ...
@@ -148,9 +101,7 @@ func assertPortList(c *check.C, out string, expected []string) bool {
148 148
 }
149 149
 
150 150
 func stopRemoveContainer(id string, c *check.C) {
151
-	runCmd := exec.Command(dockerBinary, "rm", "-f", id)
152
-	_, _, err := runCommandWithOutput(runCmd)
153
-	c.Assert(err, check.IsNil)
151
+	dockerCmd(c, "rm", "-f", id)
154 152
 }
155 153
 
156 154
 func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
... ...
@@ -159,31 +110,23 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
159 159
 	port2 := 443
160 160
 	expose1 := fmt.Sprintf("--expose=%d", port1)
161 161
 	expose2 := fmt.Sprintf("--expose=%d", port2)
162
-	runCmd := exec.Command(dockerBinary, "run", "-d", expose1, expose2, "busybox", "sleep", "5")
163
-	out, _, err := runCommandWithOutput(runCmd)
164
-	c.Assert(err, check.IsNil)
162
+	dockerCmd(c, "run", "-d", expose1, expose2, "busybox", "sleep", "5")
165 163
 
166 164
 	// Check docker ps o/p for last created container reports the unpublished ports
167 165
 	unpPort1 := fmt.Sprintf("%d/tcp", port1)
168 166
 	unpPort2 := fmt.Sprintf("%d/tcp", port2)
169
-	runCmd = exec.Command(dockerBinary, "ps", "-n=1")
170
-	out, _, err = runCommandWithOutput(runCmd)
171
-	c.Assert(err, check.IsNil)
167
+	out, _ := dockerCmd(c, "ps", "-n=1")
172 168
 	if !strings.Contains(out, unpPort1) || !strings.Contains(out, unpPort2) {
173 169
 		c.Errorf("Missing unpublished ports(s) (%s, %s) in docker ps output: %s", unpPort1, unpPort2, out)
174 170
 	}
175 171
 
176 172
 	// Run the container forcing to publish the exposed ports
177
-	runCmd = exec.Command(dockerBinary, "run", "-d", "-P", expose1, expose2, "busybox", "sleep", "5")
178
-	out, _, err = runCommandWithOutput(runCmd)
179
-	c.Assert(err, check.IsNil)
173
+	dockerCmd(c, "run", "-d", "-P", expose1, expose2, "busybox", "sleep", "5")
180 174
 
181 175
 	// Check docker ps o/p for last created container reports the exposed ports in the port bindings
182 176
 	expBndRegx1 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort1)
183 177
 	expBndRegx2 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort2)
184
-	runCmd = exec.Command(dockerBinary, "ps", "-n=1")
185
-	out, _, err = runCommandWithOutput(runCmd)
186
-	c.Assert(err, check.IsNil)
178
+	out, _ = dockerCmd(c, "ps", "-n=1")
187 179
 	if !expBndRegx1.MatchString(out) || !expBndRegx2.MatchString(out) {
188 180
 		c.Errorf("Cannot find expected port binding ports(s) (0.0.0.0:xxxxx->%s, 0.0.0.0:xxxxx->%s) in docker ps output:\n%s",
189 181
 			unpPort1, unpPort2, out)
... ...
@@ -193,17 +136,13 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
193 193
 	offset := 10000
194 194
 	pFlag1 := fmt.Sprintf("%d:%d", offset+port1, port1)
195 195
 	pFlag2 := fmt.Sprintf("%d:%d", offset+port2, port2)
196
-	runCmd = exec.Command(dockerBinary, "run", "-d", "-p", pFlag1, "-p", pFlag2, expose1, expose2, "busybox", "sleep", "5")
197
-	out, _, err = runCommandWithOutput(runCmd)
198
-	c.Assert(err, check.IsNil)
196
+	out, _ = dockerCmd(c, "run", "-d", "-p", pFlag1, "-p", pFlag2, expose1, expose2, "busybox", "sleep", "5")
199 197
 	id := strings.TrimSpace(out)
200 198
 
201 199
 	// Check docker ps o/p for last created container reports the specified port mappings
202 200
 	expBnd1 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port1, unpPort1)
203 201
 	expBnd2 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port2, unpPort2)
204
-	runCmd = exec.Command(dockerBinary, "ps", "-n=1")
205
-	out, _, err = runCommandWithOutput(runCmd)
206
-	c.Assert(err, check.IsNil)
202
+	out, _ = dockerCmd(c, "ps", "-n=1")
207 203
 	if !strings.Contains(out, expBnd1) || !strings.Contains(out, expBnd2) {
208 204
 		c.Errorf("Cannot find expected port binding(s) (%s, %s) in docker ps output: %s", expBnd1, expBnd2, out)
209 205
 	}
... ...
@@ -211,15 +150,11 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
211 211
 	stopRemoveContainer(id, c)
212 212
 
213 213
 	// Run the container with explicit port bindings and no exposed ports
214
-	runCmd = exec.Command(dockerBinary, "run", "-d", "-p", pFlag1, "-p", pFlag2, "busybox", "sleep", "5")
215
-	out, _, err = runCommandWithOutput(runCmd)
216
-	c.Assert(err, check.IsNil)
214
+	out, _ = dockerCmd(c, "run", "-d", "-p", pFlag1, "-p", pFlag2, "busybox", "sleep", "5")
217 215
 	id = strings.TrimSpace(out)
218 216
 
219 217
 	// Check docker ps o/p for last created container reports the specified port mappings
220
-	runCmd = exec.Command(dockerBinary, "ps", "-n=1")
221
-	out, _, err = runCommandWithOutput(runCmd)
222
-	c.Assert(err, check.IsNil)
218
+	out, _ = dockerCmd(c, "ps", "-n=1")
223 219
 	if !strings.Contains(out, expBnd1) || !strings.Contains(out, expBnd2) {
224 220
 		c.Errorf("Cannot find expected port binding(s) (%s, %s) in docker ps output: %s", expBnd1, expBnd2, out)
225 221
 	}
... ...
@@ -227,14 +162,10 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
227 227
 	stopRemoveContainer(id, c)
228 228
 
229 229
 	// Run the container with one unpublished exposed port and one explicit port binding
230
-	runCmd = exec.Command(dockerBinary, "run", "-d", expose1, "-p", pFlag2, "busybox", "sleep", "5")
231
-	out, _, err = runCommandWithOutput(runCmd)
232
-	c.Assert(err, check.IsNil)
230
+	dockerCmd(c, "run", "-d", expose1, "-p", pFlag2, "busybox", "sleep", "5")
233 231
 
234 232
 	// Check docker ps o/p for last created container reports the specified unpublished port and port mapping
235
-	runCmd = exec.Command(dockerBinary, "ps", "-n=1")
236
-	out, _, err = runCommandWithOutput(runCmd)
237
-	c.Assert(err, check.IsNil)
233
+	out, _ = dockerCmd(c, "ps", "-n=1")
238 234
 	if !strings.Contains(out, unpPort1) || !strings.Contains(out, expBnd2) {
239 235
 		c.Errorf("Missing unpublished ports or port binding (%s, %s) in docker ps output: %s", unpPort1, expBnd2, out)
240 236
 	}
... ...
@@ -4,63 +4,39 @@ package main
4 4
 
5 5
 import (
6 6
 	"net"
7
-	"os/exec"
8 7
 	"strings"
9 8
 
10 9
 	"github.com/go-check/check"
11 10
 )
12 11
 
13 12
 func (s *DockerSuite) TestPortHostBinding(c *check.C) {
14
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox",
13
+	out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
15 14
 		"nc", "-l", "-p", "80")
16
-	out, _, err := runCommandWithOutput(runCmd)
17
-	if err != nil {
18
-		c.Fatal(out, err)
19
-	}
20 15
 	firstID := strings.TrimSpace(out)
21 16
 
22
-	runCmd = exec.Command(dockerBinary, "port", firstID, "80")
23
-	out, _, err = runCommandWithOutput(runCmd)
24
-	if err != nil {
25
-		c.Fatal(out, err)
26
-	}
17
+	out, _ = dockerCmd(c, "port", firstID, "80")
27 18
 
28 19
 	if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
29 20
 		c.Error("Port list is not correct")
30 21
 	}
31 22
 
32
-	runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
23
+	dockerCmd(c, "run", "--net=host", "busybox",
33 24
 		"nc", "localhost", "9876")
34
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
35
-		c.Fatal(out, err)
36
-	}
37 25
 
38
-	runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
39
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
40
-		c.Fatal(out, err)
41
-	}
26
+	dockerCmd(c, "rm", "-f", firstID)
42 27
 
43
-	runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
44
-		"nc", "localhost", "9876")
45
-	if out, _, err = runCommandWithOutput(runCmd); err == nil {
28
+	if _, _, err := dockerCmdWithError(c, "run", "--net=host", "busybox",
29
+		"nc", "localhost", "9876"); err == nil {
46 30
 		c.Error("Port is still bound after the Container is removed")
47 31
 	}
48 32
 }
49 33
 
50 34
 func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
51
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--expose", "80", "busybox",
35
+	out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
52 36
 		"nc", "-l", "-p", "80")
53
-	out, _, err := runCommandWithOutput(runCmd)
54
-	if err != nil {
55
-		c.Fatal(out, err)
56
-	}
57 37
 	firstID := strings.TrimSpace(out)
58 38
 
59
-	runCmd = exec.Command(dockerBinary, "port", firstID, "80")
60
-	out, _, err = runCommandWithOutput(runCmd)
61
-	if err != nil {
62
-		c.Fatal(out, err)
63
-	}
39
+	out, _ = dockerCmd(c, "port", firstID, "80")
64 40
 
65 41
 	_, exposedPort, err := net.SplitHostPort(out)
66 42
 
... ...
@@ -68,20 +44,13 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
68 68
 		c.Fatal(out, err)
69 69
 	}
70 70
 
71
-	runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
71
+	dockerCmd(c, "run", "--net=host", "busybox",
72 72
 		"nc", "localhost", strings.TrimSpace(exposedPort))
73
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
74
-		c.Fatal(out, err)
75
-	}
76 73
 
77
-	runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
78
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
79
-		c.Fatal(out, err)
80
-	}
74
+	dockerCmd(c, "rm", "-f", firstID)
81 75
 
82
-	runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
83
-		"nc", "localhost", strings.TrimSpace(exposedPort))
84
-	if out, _, err = runCommandWithOutput(runCmd); err == nil {
76
+	if _, _, err = dockerCmdWithError(c, "run", "--net=host", "busybox",
77
+		"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
85 78
 		c.Error("Port is still bound after the Container is removed")
86 79
 	}
87 80
 }
... ...
@@ -337,8 +337,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
337 337
 		c.Fatal(err)
338 338
 	}
339 339
 
340
-	runCmd := exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
341
-	if out, _, err := runCommandWithOutput(runCmd); err == nil {
340
+	if out, _, err := dockerCmdWithError(c, "run", "--name", "nonzero1", "busybox", "false"); err == nil {
342 341
 		c.Fatal("Should fail.", out, err)
343 342
 	}
344 343
 
... ...
@@ -347,8 +346,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
347 347
 		c.Fatal(err)
348 348
 	}
349 349
 
350
-	runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false")
351
-	if out, _, err := runCommandWithOutput(runCmd); err == nil {
350
+	if out, _, err := dockerCmdWithError(c, "run", "--name", "nonzero2", "busybox", "false"); err == nil {
352 351
 		c.Fatal("Should fail.", out, err)
353 352
 	}
354 353
 	secondNonZero, err := getIDByName("nonzero2")
... ...
@@ -385,42 +383,25 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
385 385
 
386 386
 func (s *DockerSuite) TestPsRightTagName(c *check.C) {
387 387
 	tag := "asybox:shmatest"
388
-	if out, err := exec.Command(dockerBinary, "tag", "busybox", tag).CombinedOutput(); err != nil {
389
-		c.Fatalf("Failed to tag image: %s, out: %q", err, out)
390
-	}
388
+	dockerCmd(c, "tag", "busybox", tag)
391 389
 
392 390
 	var id1 string
393
-	if out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "top").CombinedOutput(); err != nil {
394
-		c.Fatalf("Failed to run container: %s, out: %q", err, out)
395
-	} else {
396
-		id1 = strings.TrimSpace(string(out))
397
-	}
391
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
392
+	id1 = strings.TrimSpace(string(out))
398 393
 
399 394
 	var id2 string
400
-	if out, err := exec.Command(dockerBinary, "run", "-d", tag, "top").CombinedOutput(); err != nil {
401
-		c.Fatalf("Failed to run container: %s, out: %q", err, out)
402
-	} else {
403
-		id2 = strings.TrimSpace(string(out))
404
-	}
395
+	out, _ = dockerCmd(c, "run", "-d", tag, "top")
396
+	id2 = strings.TrimSpace(string(out))
405 397
 
406 398
 	var imageID string
407
-	if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil {
408
-		c.Fatalf("failed to get the image ID of busybox: %s, %v", out, err)
409
-	} else {
410
-		imageID = strings.TrimSpace(string(out))
411
-	}
399
+	out, _ = dockerCmd(c, "inspect", "-f", "{{.Id}}", "busybox")
400
+	imageID = strings.TrimSpace(string(out))
412 401
 
413 402
 	var id3 string
414
-	if out, err := exec.Command(dockerBinary, "run", "-d", imageID, "top").CombinedOutput(); err != nil {
415
-		c.Fatalf("Failed to run container: %s, out: %q", err, out)
416
-	} else {
417
-		id3 = strings.TrimSpace(string(out))
418
-	}
403
+	out, _ = dockerCmd(c, "run", "-d", imageID, "top")
404
+	id3 = strings.TrimSpace(string(out))
419 405
 
420
-	out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
421
-	if err != nil {
422
-		c.Fatalf("Failed to run 'ps': %s, out: %q", err, out)
423
-	}
406
+	out, _ = dockerCmd(c, "ps", "--no-trunc")
424 407
 	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
425 408
 	// skip header
426 409
 	lines = lines[1:]
... ...
@@ -449,16 +430,10 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
449 449
 }
450 450
 
451 451
 func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
452
-	if out, err := exec.Command(dockerBinary, "run", "--name=first", "-d", "busybox", "top").CombinedOutput(); err != nil {
453
-		c.Fatalf("Output: %s, err: %s", out, err)
454
-	}
455
-	if out, err := exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "-d", "busybox", "top").CombinedOutput(); err != nil {
456
-		c.Fatalf("Output: %s, err: %s", out, err)
457
-	}
458
-	out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
459
-	if err != nil {
460
-		c.Fatalf("Output: %s, err: %s", out, err)
461
-	}
452
+	dockerCmd(c, "run", "--name=first", "-d", "busybox", "top")
453
+	dockerCmd(c, "run", "--name=second", "--link=first:first", "-d", "busybox", "top")
454
+
455
+	out, _ := dockerCmd(c, "ps", "--no-trunc")
462 456
 	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
463 457
 	// strip header
464 458
 	lines = lines[1:]
... ...
@@ -488,14 +463,9 @@ func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
488 488
 }
489 489
 
490 490
 func (s *DockerSuite) TestPsWithSize(c *check.C) {
491
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "sizetest", "busybox", "top"))
492
-	if err != nil {
493
-		c.Fatal(out, err)
494
-	}
495
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps", "--size"))
496
-	if err != nil {
497
-		c.Fatal(out, err)
498
-	}
491
+	dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top")
492
+
493
+	out, _ := dockerCmd(c, "ps", "--size")
499 494
 	if !strings.Contains(out, "virtual") {
500 495
 		c.Fatalf("docker ps with --size should show virtual size of container")
501 496
 	}
... ...
@@ -503,28 +473,18 @@ func (s *DockerSuite) TestPsWithSize(c *check.C) {
503 503
 
504 504
 func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
505 505
 	// create a container
506
-	createCmd := exec.Command(dockerBinary, "create", "busybox")
507
-	out, _, err := runCommandWithOutput(createCmd)
508
-	if err != nil {
509
-		c.Fatal(out, err)
510
-	}
506
+	out, _ := dockerCmd(c, "create", "busybox")
511 507
 	cID := strings.TrimSpace(out)
512 508
 	shortCID := cID[:12]
513 509
 
514 510
 	// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
515
-	runCmd := exec.Command(dockerBinary, "ps", "-q")
516
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
517
-		c.Fatal(out, err)
518
-	}
511
+	out, _ = dockerCmd(c, "ps", "-q")
519 512
 	if strings.Contains(out, shortCID) {
520 513
 		c.Fatalf("Should have not seen '%s' in ps output:\n%s", shortCID, out)
521 514
 	}
522 515
 
523 516
 	// Make sure it DOES show up as 'Created' for 'ps -a'
524
-	runCmd = exec.Command(dockerBinary, "ps", "-a")
525
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
526
-		c.Fatal(out, err)
527
-	}
517
+	out, _ = dockerCmd(c, "ps", "-a")
528 518
 
529 519
 	hits := 0
530 520
 	for _, line := range strings.Split(out, "\n") {
... ...
@@ -542,10 +502,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
542 542
 	}
543 543
 
544 544
 	// filter containers by 'create' - note, no -a needed
545
-	runCmd = exec.Command(dockerBinary, "ps", "-q", "-f", "status=created")
546
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
547
-		c.Fatal(out, err)
548
-	}
545
+	out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created")
549 546
 	containerOut := strings.TrimSpace(out)
550 547
 	if !strings.HasPrefix(cID, containerOut) {
551 548
 		c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out)
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"strings"
7 6
 
8 7
 	"github.com/go-check/check"
... ...
@@ -19,30 +18,19 @@ func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
19 19
 
20 20
 	// Tag and push the same image multiple times.
21 21
 	for _, repo := range repos {
22
-		if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil {
23
-			c.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out)
24
-		}
25
-		if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil {
26
-			c.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out))
27
-		}
22
+		dockerCmd(c, "tag", "busybox", repo)
23
+		dockerCmd(c, "push", repo)
28 24
 	}
29 25
 
30 26
 	// Clear local images store.
31 27
 	args := append([]string{"rmi"}, repos...)
32
-	if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil {
33
-		c.Fatalf("Failed to clean images: error %v, output %q", err, string(out))
34
-	}
28
+	dockerCmd(c, args...)
35 29
 
36 30
 	// Pull a single tag and verify it doesn't bring down all aliases.
37
-	pullCmd := exec.Command(dockerBinary, "pull", repos[0])
38
-	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
39
-		c.Fatalf("Failed to pull %v: error %v, output %q", repoName, err, out)
40
-	}
41
-	if err := exec.Command(dockerBinary, "inspect", repos[0]).Run(); err != nil {
42
-		c.Fatalf("Image %v was not pulled down", repos[0])
43
-	}
31
+	dockerCmd(c, "pull", repos[0])
32
+	dockerCmd(c, "inspect", repos[0])
44 33
 	for _, repo := range repos[1:] {
45
-		if err := exec.Command(dockerBinary, "inspect", repo).Run(); err == nil {
34
+		if _, _, err := dockerCmdWithError(c, "inspect", repo); err == nil {
46 35
 			c.Fatalf("Image %v shouldn't have been pulled down", repo)
47 36
 		}
48 37
 	}
... ...
@@ -59,8 +47,7 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
59 59
 
60 60
 	// pull it
61 61
 	expected := "The image you are pulling has been verified"
62
-	pullCmd := exec.Command(dockerBinary, "pull", verifiedName)
63
-	if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || !strings.Contains(out, expected) {
62
+	if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || !strings.Contains(out, expected) {
64 63
 		if err != nil || exitCode != 0 {
65 64
 			c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
66 65
 		}
... ...
@@ -68,8 +55,7 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
68 68
 	}
69 69
 
70 70
 	// pull it again
71
-	pullCmd = exec.Command(dockerBinary, "pull", verifiedName)
72
-	if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || strings.Contains(out, expected) {
71
+	if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || strings.Contains(out, expected) {
73 72
 		if err != nil || exitCode != 0 {
74 73
 			c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
75 74
 		}
... ...
@@ -82,10 +68,7 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
82 82
 func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
83 83
 	testRequires(c, Network)
84 84
 
85
-	pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
86
-	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
87
-		c.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err)
88
-	}
85
+	dockerCmd(c, "pull", "hello-world")
89 86
 }
90 87
 
91 88
 // pulling a non-existing image from the central registry should return a non-zero exit code
... ...
@@ -93,8 +76,7 @@ func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
93 93
 	testRequires(c, Network)
94 94
 
95 95
 	name := "sadfsadfasdf"
96
-	pullCmd := exec.Command(dockerBinary, "pull", name)
97
-	out, _, err := runCommandWithOutput(pullCmd)
96
+	out, _, err := dockerCmdWithError(c, "pull", name)
98 97
 
99 98
 	if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) {
100 99
 		c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
... ...
@@ -114,19 +96,15 @@ func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
114 114
 		"index.docker.io/library/hello-world",
115 115
 	}
116 116
 	for _, name := range names {
117
-		pullCmd := exec.Command(dockerBinary, "pull", name)
118
-		out, exitCode, err := runCommandWithOutput(pullCmd)
117
+		out, exitCode, err := dockerCmdWithError(c, "pull", name)
119 118
 		if err != nil || exitCode != 0 {
120 119
 			c.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
121 120
 			continue
122 121
 		}
123 122
 
124 123
 		// ensure we don't have multiple image names.
125
-		imagesCmd := exec.Command(dockerBinary, "images")
126
-		out, _, err = runCommandWithOutput(imagesCmd)
127
-		if err != nil {
128
-			c.Errorf("listing images failed with errors: %v", err)
129
-		} else if strings.Contains(out, name) {
124
+		out, _ = dockerCmd(c, "images")
125
+		if strings.Contains(out, name) {
130 126
 			c.Errorf("images should not have listed '%s'", name)
131 127
 		}
132 128
 	}
... ...
@@ -135,8 +113,7 @@ func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
135 135
 func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
136 136
 	testRequires(c, Network)
137 137
 
138
-	pullCmd := exec.Command(dockerBinary, "pull", "scratch")
139
-	out, exitCode, err := runCommandWithOutput(pullCmd)
138
+	out, exitCode, err := dockerCmdWithError(c, "pull", "scratch")
140 139
 	if err == nil {
141 140
 		c.Fatal("expected pull of scratch to fail, but it didn't")
142 141
 	}
... ...
@@ -153,38 +130,24 @@ func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
153 153
 
154 154
 // pulling an image with --all-tags=true
155 155
 func (s *DockerSuite) TestPullImageWithAllTagFromCentralRegistry(c *check.C) {
156
-	//testRequires(c, Network)
157
-	pullCmd := exec.Command(dockerBinary, "pull", "busybox")
158
-	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
159
-		c.Fatalf("pulling the busybox image from the registry has failed: %s, %v", out, err)
160
-	}
156
+	testRequires(c, Network)
161 157
 
162
-	ImageCmd := exec.Command(dockerBinary, "images", "busybox")
163
-	outImageCmd, _, err := runCommandWithOutput(ImageCmd)
158
+	dockerCmd(c, "pull", "busybox")
164 159
 
165
-	c.Assert(err, check.IsNil)
160
+	outImageCmd, _ := dockerCmd(c, "images", "busybox")
166 161
 
167
-	pullAllTagCmd := exec.Command(dockerBinary, "pull", "--all-tags=true", "busybox")
168
-	if out, _, err := runCommandWithOutput(pullAllTagCmd); err != nil {
169
-		c.Fatalf("pulling the busybox image with all tags from the registry has failed: %s, %v", out, err)
170
-	}
162
+	dockerCmd(c, "pull", "--all-tags=true", "busybox")
171 163
 
172
-	ImageCmd1 := exec.Command(dockerBinary, "images", "busybox")
173
-	outImageAllTagCmd, _, err := runCommandWithOutput(ImageCmd1)
174
-	c.Assert(err, check.IsNil)
164
+	outImageAllTagCmd, _ := dockerCmd(c, "images", "busybox")
175 165
 
176 166
 	if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
177 167
 		c.Fatalf("Pulling with all tags should get more images")
178 168
 	}
179 169
 
180
-	pullAllTagCmd = exec.Command(dockerBinary, "pull", "-a", "busybox")
181
-	if out, _, err := runCommandWithOutput(pullAllTagCmd); err != nil {
182
-		c.Fatalf("pulling the busybox image with all tags from the registry has failed: %s, %v", out, err)
183
-	}
170
+	// FIXME has probably no effect (tags already pushed)
171
+	dockerCmd(c, "pull", "-a", "busybox")
184 172
 
185
-	ImageCmd2 := exec.Command(dockerBinary, "images", "busybox")
186
-	outImageAllTagCmd, _, err = runCommandWithOutput(ImageCmd2)
187
-	c.Assert(err, check.IsNil)
173
+	outImageAllTagCmd, _ = dockerCmd(c, "images", "busybox")
188 174
 
189 175
 	if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
190 176
 		c.Fatalf("Pulling with all tags should get more images")
... ...
@@ -16,21 +16,14 @@ import (
16 16
 func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
17 17
 	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
18 18
 	// tag the image to upload it to the private registry
19
-	tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
20
-	if out, _, err := runCommandWithOutput(tagCmd); err != nil {
21
-		c.Fatalf("image tagging failed: %s, %v", out, err)
22
-	}
23
-
24
-	pushCmd := exec.Command(dockerBinary, "push", repoName)
25
-	if out, _, err := runCommandWithOutput(pushCmd); err != nil {
26
-		c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
27
-	}
19
+	dockerCmd(c, "tag", "busybox", repoName)
20
+	// push the image to the registry
21
+	dockerCmd(c, "push", repoName)
28 22
 }
29 23
 
30 24
 // pushing an image without a prefix should throw an error
31 25
 func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
32
-	pushCmd := exec.Command(dockerBinary, "push", "busybox")
33
-	if out, _, err := runCommandWithOutput(pushCmd); err == nil {
26
+	if out, _, err := dockerCmdWithError(c, "push", "busybox"); err == nil {
34 27
 		c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
35 28
 	}
36 29
 }
... ...
@@ -39,8 +32,7 @@ func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
39 39
 	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
40 40
 
41 41
 	expected := "Repository does not exist"
42
-	pushCmd := exec.Command(dockerBinary, "push", repoName)
43
-	if out, _, err := runCommandWithOutput(pushCmd); err == nil {
42
+	if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
44 43
 		c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
45 44
 	} else if !strings.Contains(out, expected) {
46 45
 		c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
... ...
@@ -51,8 +43,8 @@ func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
51 51
 	repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
52 52
 
53 53
 	expected := "does not exist"
54
-	pushCmd := exec.Command(dockerBinary, "push", repoName)
55
-	if out, _, err := runCommandWithOutput(pushCmd); err == nil {
54
+
55
+	if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
56 56
 		c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
57 57
 	} else if !strings.Contains(out, expected) {
58 58
 		c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
... ...
@@ -64,27 +56,17 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
64 64
 	repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
65 65
 	repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
66 66
 	// tag the image and upload it to the private registry
67
-	tagCmd1 := exec.Command(dockerBinary, "tag", "busybox", repoTag1)
68
-	if out, _, err := runCommandWithOutput(tagCmd1); err != nil {
69
-		c.Fatalf("image tagging failed: %s, %v", out, err)
70
-	}
71
-	tagCmd2 := exec.Command(dockerBinary, "tag", "busybox", repoTag2)
72
-	if out, _, err := runCommandWithOutput(tagCmd2); err != nil {
73
-		c.Fatalf("image tagging failed: %s, %v", out, err)
74
-	}
67
+	dockerCmd(c, "tag", "busybox", repoTag1)
75 68
 
76
-	pushCmd := exec.Command(dockerBinary, "push", repoName)
77
-	if out, _, err := runCommandWithOutput(pushCmd); err != nil {
78
-		c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
79
-	}
69
+	dockerCmd(c, "tag", "busybox", repoTag2)
70
+
71
+	dockerCmd(c, "push", repoName)
80 72
 }
81 73
 
82 74
 func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
83 75
 	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
84 76
 	// tag the image and upload it to the private registry
85
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repoName)); err != nil {
86
-		c.Fatalf("image tagging failed: %s, %v", out, err)
87
-	}
77
+	dockerCmd(c, "tag", "busybox", repoName)
88 78
 
89 79
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
90 80
 	if err := pushCmd.Start(); err != nil {
... ...
@@ -96,7 +78,7 @@ func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
96 96
 	if err := pushCmd.Process.Kill(); err != nil {
97 97
 		c.Fatalf("Failed to kill push process: %v", err)
98 98
 	}
99
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repoName)); err == nil {
99
+	if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
100 100
 		str := string(out)
101 101
 		if !strings.Contains(str, "already in progress") {
102 102
 			c.Fatalf("Push should be continued on daemon side, but seems ok: %v, %s", err, out)
... ...
@@ -133,8 +115,7 @@ func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
133 133
 	}
134 134
 
135 135
 	// Now verify we can push it
136
-	pushCmd := exec.Command(dockerBinary, "push", repoName)
137
-	if out, _, err := runCommandWithOutput(pushCmd); err != nil {
136
+	if out, _, err := dockerCmdWithError(c, "push", repoName); err != nil {
138 137
 		c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
139 138
 	}
140 139
 }