Browse code

CI: use dockercmd when possible

Signed-off-by: Hu Keping <hukeping@huawei.com>

Hu Keping authored on 2015/07/20 05:47:47
Showing 1 changed files
... ...
@@ -25,12 +25,7 @@ import (
25 25
 
26 26
 // "test123" should be printed by docker run
27 27
 func (s *DockerSuite) TestRunEchoStdout(c *check.C) {
28
-	runCmd := exec.Command(dockerBinary, "run", "busybox", "echo", "test123")
29
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
30
-	if err != nil {
31
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
32
-	}
33
-
28
+	out, _ := dockerCmd(c, "run", "busybox", "echo", "test123")
34 29
 	if out != "test123\n" {
35 30
 		c.Fatalf("container should've printed 'test123'")
36 31
 	}
... ...
@@ -54,24 +49,15 @@ func (s *DockerSuite) TestRunEchoStdoutWithMemoryLimit(c *check.C) {
54 54
 // should run without memory swap
55 55
 func (s *DockerSuite) TestRunWithoutMemoryswapLimit(c *check.C) {
56 56
 	testRequires(c, NativeExecDriver)
57
-	runCmd := exec.Command(dockerBinary, "run", "-m", "16m", "--memory-swap", "-1", "busybox", "true")
58
-	out, _, err := runCommandWithOutput(runCmd)
59
-	if err != nil {
60
-		c.Fatalf("failed to run container, output: %q", out)
61
-	}
57
+	dockerCmd(c, "run", "-m", "16m", "--memory-swap", "-1", "busybox", "true")
62 58
 }
63 59
 
64 60
 func (s *DockerSuite) TestRunWithSwappiness(c *check.C) {
65
-	runCmd := exec.Command(dockerBinary, "run", "--memory-swappiness", "0", "busybox", "true")
66
-	out, _, err := runCommandWithOutput(runCmd)
67
-	if err != nil {
68
-		c.Fatalf("failed to run container, output: %q", out)
69
-	}
61
+	dockerCmd(c, "run", "--memory-swappiness", "0", "busybox", "true")
70 62
 }
71 63
 
72 64
 func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) {
73
-	runCmd := exec.Command(dockerBinary, "run", "--memory-swappiness", "101", "busybox", "true")
74
-	out, _, err := runCommandWithOutput(runCmd)
65
+	out, _, err := dockerCmdWithError(c, "run", "--memory-swappiness", "101", "busybox", "true")
75 66
 	if err == nil {
76 67
 		c.Fatalf("failed. test was able to set invalid value, output: %q", out)
77 68
 	}
... ...
@@ -79,12 +65,7 @@ func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) {
79 79
 
80 80
 // "test" should be printed
81 81
 func (s *DockerSuite) TestRunEchoStdoutWitCPULimit(c *check.C) {
82
-	runCmd := exec.Command(dockerBinary, "run", "-c", "1000", "busybox", "echo", "test")
83
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
84
-	if err != nil {
85
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
86
-	}
87
-
82
+	out, _ := dockerCmd(c, "run", "-c", "1000", "busybox", "echo", "test")
88 83
 	if out != "test\n" {
89 84
 		c.Errorf("container should've printed 'test'")
90 85
 	}
... ...
@@ -105,12 +86,7 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUAndMemoryLimit(c *check.C) {
105 105
 
106 106
 // "test" should be printed
107 107
 func (s *DockerSuite) TestRunEchoNamedContainer(c *check.C) {
108
-	runCmd := exec.Command(dockerBinary, "run", "--name", "testfoonamedcontainer", "busybox", "echo", "test")
109
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
110
-	if err != nil {
111
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
112
-	}
113
-
108
+	out, _ := dockerCmd(c, "run", "--name", "testfoonamedcontainer", "busybox", "echo", "test")
114 109
 	if out != "test\n" {
115 110
 		c.Errorf("container should've printed 'test'")
116 111
 	}
... ...
@@ -118,11 +94,7 @@ func (s *DockerSuite) TestRunEchoNamedContainer(c *check.C) {
118 118
 
119 119
 // docker run should not leak file descriptors
120 120
 func (s *DockerSuite) TestRunLeakyFileDescriptors(c *check.C) {
121
-	runCmd := exec.Command(dockerBinary, "run", "busybox", "ls", "-C", "/proc/self/fd")
122
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
123
-	if err != nil {
124
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
125
-	}
121
+	out, _ := dockerCmd(c, "run", "busybox", "ls", "-C", "/proc/self/fd")
126 122
 
127 123
 	// normally, we should only get 0, 1, and 2, but 3 gets created by "ls" when it does "opendir" on the "fd" directory
128 124
 	if out != "0  1  2  3\n" {
... ...
@@ -134,27 +106,19 @@ func (s *DockerSuite) TestRunLeakyFileDescriptors(c *check.C) {
134 134
 // this will fail when Internet access is unavailable
135 135
 func (s *DockerSuite) TestRunLookupGoogleDns(c *check.C) {
136 136
 	testRequires(c, Network)
137
-
138
-	out, _, _, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, "run", "busybox", "nslookup", "google.com"))
139
-	if err != nil {
140
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
141
-	}
137
+	dockerCmd(c, "run", "busybox", "nslookup", "google.com")
142 138
 }
143 139
 
144 140
 // the exit code should be 0
145 141
 // some versions of lxc might make this test fail
146 142
 func (s *DockerSuite) TestRunExitCodeZero(c *check.C) {
147
-	runCmd := exec.Command(dockerBinary, "run", "busybox", "true")
148
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
149
-		c.Errorf("container should've exited with exit code 0: %s, %v", out, err)
150
-	}
143
+	dockerCmd(c, "run", "busybox", "true")
151 144
 }
152 145
 
153 146
 // the exit code should be 1
154 147
 // some versions of lxc might make this test fail
155 148
 func (s *DockerSuite) TestRunExitCodeOne(c *check.C) {
156
-	runCmd := exec.Command(dockerBinary, "run", "busybox", "false")
157
-	exitCode, err := runCommand(runCmd)
149
+	_, exitCode, err := dockerCmdWithError(c, "run", "busybox", "false")
158 150
 	if err != nil && !strings.Contains("exit status 1", fmt.Sprintf("%s", err)) {
159 151
 		c.Fatal(err)
160 152
 	}
... ...
@@ -174,48 +138,26 @@ func (s *DockerSuite) TestRunStdinPipe(c *check.C) {
174 174
 	}
175 175
 
176 176
 	out = strings.TrimSpace(out)
177
-	waitCmd := exec.Command(dockerBinary, "wait", out)
178
-	if waitOut, _, err := runCommandWithOutput(waitCmd); err != nil {
179
-		c.Fatalf("error thrown while waiting for container: %s, %v", waitOut, err)
180
-	}
177
+	dockerCmd(c, "wait", out)
181 178
 
182
-	logsCmd := exec.Command(dockerBinary, "logs", out)
183
-	logsOut, _, err := runCommandWithOutput(logsCmd)
184
-	if err != nil {
185
-		c.Fatalf("error thrown while trying to get container logs: %s, %v", logsOut, err)
186
-	}
179
+	logsOut, _ := dockerCmd(c, "logs", out)
187 180
 
188 181
 	containerLogs := strings.TrimSpace(logsOut)
189
-
190 182
 	if containerLogs != "blahblah" {
191 183
 		c.Errorf("logs didn't print the container's logs %s", containerLogs)
192 184
 	}
193 185
 
194
-	rmCmd := exec.Command(dockerBinary, "rm", out)
195
-	if out, _, err = runCommandWithOutput(rmCmd); err != nil {
196
-		c.Fatalf("rm failed to remove container: %s, %v", out, err)
197
-	}
186
+	dockerCmd(c, "rm", out)
198 187
 }
199 188
 
200 189
 // the container's ID should be printed when starting a container in detached mode
201 190
 func (s *DockerSuite) TestRunDetachedContainerIDPrinting(c *check.C) {
202
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
203
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
204
-	if err != nil {
205
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
206
-	}
191
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
207 192
 
208 193
 	out = strings.TrimSpace(out)
209
-	waitCmd := exec.Command(dockerBinary, "wait", out)
210
-	if waitOut, _, err := runCommandWithOutput(waitCmd); err != nil {
211
-		c.Fatalf("error thrown while waiting for container: %s, %v", waitOut, err)
212
-	}
194
+	dockerCmd(c, "wait", out)
213 195
 
214
-	rmCmd := exec.Command(dockerBinary, "rm", out)
215
-	rmOut, _, err := runCommandWithOutput(rmCmd)
216
-	if err != nil {
217
-		c.Fatalf("rm failed to remove container: %s, %v", rmOut, err)
218
-	}
196
+	rmOut, _ := dockerCmd(c, "rm", out)
219 197
 
220 198
 	rmOut = strings.TrimSpace(rmOut)
221 199
 	if rmOut != out {
... ...
@@ -225,26 +167,15 @@ func (s *DockerSuite) TestRunDetachedContainerIDPrinting(c *check.C) {
225 225
 
226 226
 // the working directory should be set correctly
227 227
 func (s *DockerSuite) TestRunWorkingDirectory(c *check.C) {
228
-	runCmd := exec.Command(dockerBinary, "run", "-w", "/root", "busybox", "pwd")
229
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
230
-	if err != nil {
231
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
232
-	}
228
+	out, _ := dockerCmd(c, "run", "-w", "/root", "busybox", "pwd")
233 229
 
234 230
 	out = strings.TrimSpace(out)
235
-
236 231
 	if out != "/root" {
237 232
 		c.Errorf("-w failed to set working directory")
238 233
 	}
239 234
 
240
-	runCmd = exec.Command(dockerBinary, "run", "--workdir", "/root", "busybox", "pwd")
241
-	out, _, _, err = runCommandWithStdoutStderr(runCmd)
242
-	if err != nil {
243
-		c.Fatal(out, err)
244
-	}
245
-
235
+	out, _ = dockerCmd(c, "run", "--workdir", "/root", "busybox", "pwd")
246 236
 	out = strings.TrimSpace(out)
247
-
248 237
 	if out != "/root" {
249 238
 		c.Errorf("--workdir failed to set working directory")
250 239
 	}
... ...
@@ -252,8 +183,7 @@ func (s *DockerSuite) TestRunWorkingDirectory(c *check.C) {
252 252
 
253 253
 // pinging Google's DNS resolver should fail when we disable the networking
254 254
 func (s *DockerSuite) TestRunWithoutNetworking(c *check.C) {
255
-	runCmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ping", "-c", "1", "8.8.8.8")
256
-	out, _, exitCode, err := runCommandWithStdoutStderr(runCmd)
255
+	out, exitCode, err := dockerCmdWithError(c, "run", "--net=none", "busybox", "ping", "-c", "1", "8.8.8.8")
257 256
 	if err != nil && exitCode != 1 {
258 257
 		c.Fatal(out, err)
259 258
 	}
... ...
@@ -261,8 +191,7 @@ func (s *DockerSuite) TestRunWithoutNetworking(c *check.C) {
261 261
 		c.Errorf("--net=none should've disabled the network; the container shouldn't have been able to ping 8.8.8.8")
262 262
 	}
263 263
 
264
-	runCmd = exec.Command(dockerBinary, "run", "-n=false", "busybox", "ping", "-c", "1", "8.8.8.8")
265
-	out, _, exitCode, err = runCommandWithStdoutStderr(runCmd)
264
+	out, exitCode, err = dockerCmdWithError(c, "run", "-n=false", "busybox", "ping", "-c", "1", "8.8.8.8")
266 265
 	if err != nil && exitCode != 1 {
267 266
 		c.Fatal(out, err)
268 267
 	}
... ...
@@ -273,18 +202,12 @@ func (s *DockerSuite) TestRunWithoutNetworking(c *check.C) {
273 273
 
274 274
 //test --link use container name to link target
275 275
 func (s *DockerSuite) TestRunLinksContainerWithContainerName(c *check.C) {
276
-	cmd := exec.Command(dockerBinary, "run", "-i", "-t", "-d", "--name", "parent", "busybox")
277
-	out, _, _, err := runCommandWithStdoutStderr(cmd)
278
-	if err != nil {
279
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
280
-	}
276
+	dockerCmd(c, "run", "-i", "-t", "-d", "--name", "parent", "busybox")
277
+
281 278
 	ip, err := inspectField("parent", "NetworkSettings.IPAddress")
282 279
 	c.Assert(err, check.IsNil)
283
-	cmd = exec.Command(dockerBinary, "run", "--link", "parent:test", "busybox", "/bin/cat", "/etc/hosts")
284
-	out, _, err = runCommandWithOutput(cmd)
285
-	if err != nil {
286
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
287
-	}
280
+
281
+	out, _ := dockerCmd(c, "run", "--link", "parent:test", "busybox", "/bin/cat", "/etc/hosts")
288 282
 	if !strings.Contains(out, ip+"	test") {
289 283
 		c.Fatalf("use a container name to link target failed")
290 284
 	}
... ...
@@ -292,19 +215,13 @@ func (s *DockerSuite) TestRunLinksContainerWithContainerName(c *check.C) {
292 292
 
293 293
 //test --link use container id to link target
294 294
 func (s *DockerSuite) TestRunLinksContainerWithContainerId(c *check.C) {
295
-	cmd := exec.Command(dockerBinary, "run", "-i", "-t", "-d", "busybox")
296
-	cID, _, _, err := runCommandWithStdoutStderr(cmd)
297
-	if err != nil {
298
-		c.Fatalf("failed to run container: %v, output: %q", err, cID)
299
-	}
295
+	cID, _ := dockerCmd(c, "run", "-i", "-t", "-d", "busybox")
296
+
300 297
 	cID = strings.TrimSpace(cID)
301 298
 	ip, err := inspectField(cID, "NetworkSettings.IPAddress")
302 299
 	c.Assert(err, check.IsNil)
303
-	cmd = exec.Command(dockerBinary, "run", "--link", cID+":test", "busybox", "/bin/cat", "/etc/hosts")
304
-	out, _, err := runCommandWithOutput(cmd)
305
-	if err != nil {
306
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
307
-	}
300
+
301
+	out, _ := dockerCmd(c, "run", "--link", cID+":test", "busybox", "/bin/cat", "/etc/hosts")
308 302
 	if !strings.Contains(out, ip+"	test") {
309 303
 		c.Fatalf("use a container id to link target failed")
310 304
 	}
... ...
@@ -312,16 +229,14 @@ func (s *DockerSuite) TestRunLinksContainerWithContainerId(c *check.C) {
312 312
 
313 313
 // Regression test for #4979
314 314
 func (s *DockerSuite) TestRunWithVolumesFromExited(c *check.C) {
315
-	runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", "/some/dir", "busybox", "touch", "/some/dir/file")
316
-	out, stderr, exitCode, err := runCommandWithStdoutStderr(runCmd)
317
-	if err != nil && exitCode != 0 {
318
-		c.Fatal("1", out, stderr, err)
315
+	out, exitCode := dockerCmd(c, "run", "--name", "test-data", "--volume", "/some/dir", "busybox", "touch", "/some/dir/file")
316
+	if exitCode != 0 {
317
+		c.Fatal("1", out, exitCode)
319 318
 	}
320 319
 
321
-	runCmd = exec.Command(dockerBinary, "run", "--volumes-from", "test-data", "busybox", "cat", "/some/dir/file")
322
-	out, stderr, exitCode, err = runCommandWithStdoutStderr(runCmd)
323
-	if err != nil && exitCode != 0 {
324
-		c.Fatal("2", out, stderr, err)
320
+	out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", "busybox", "cat", "/some/dir/file")
321
+	if exitCode != 0 {
322
+		c.Fatal("2", out, exitCode)
325 323
 	}
326 324
 }
327 325
 
... ...
@@ -349,72 +264,47 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir(c *check.C) {
349 349
 		c.Fatal(err)
350 350
 	}
351 351
 
352
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-v", "/test/test", name))
353
-	if err != nil {
354
-		c.Fatalf("Failed with errors: %s, %v", out, err)
355
-	}
352
+	dockerCmd(c, "run", "-v", "/test/test", name)
356 353
 }
357 354
 
358 355
 func (s *DockerSuite) TestRunVolumesMountedAsReadonly(c *check.C) {
359
-	cmd := exec.Command(dockerBinary, "run", "-v", "/test:/test:ro", "busybox", "touch", "/test/somefile")
360
-	if code, err := runCommand(cmd); err == nil || code == 0 {
356
+	if _, code, err := dockerCmdWithError(c, "run", "-v", "/test:/test:ro", "busybox", "touch", "/test/somefile"); err == nil || code == 0 {
361 357
 		c.Fatalf("run should fail because volume is ro: exit code %d", code)
362 358
 	}
363 359
 }
364 360
 
365 361
 func (s *DockerSuite) TestRunVolumesFromInReadonlyMode(c *check.C) {
366
-	cmd := exec.Command(dockerBinary, "run", "--name", "parent", "-v", "/test", "busybox", "true")
367
-	if _, err := runCommand(cmd); err != nil {
368
-		c.Fatal(err)
369
-	}
362
+	dockerCmd(c, "run", "--name", "parent", "-v", "/test", "busybox", "true")
370 363
 
371
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent:ro", "busybox", "touch", "/test/file")
372
-	if code, err := runCommand(cmd); err == nil || code == 0 {
364
+	if _, code, err := dockerCmdWithError(c, "run", "--volumes-from", "parent:ro", "busybox", "touch", "/test/file"); err == nil || code == 0 {
373 365
 		c.Fatalf("run should fail because volume is ro: exit code %d", code)
374 366
 	}
375 367
 }
376 368
 
377 369
 // Regression test for #1201
378 370
 func (s *DockerSuite) TestRunVolumesFromInReadWriteMode(c *check.C) {
379
-	cmd := exec.Command(dockerBinary, "run", "--name", "parent", "-v", "/test", "busybox", "true")
380
-	if _, err := runCommand(cmd); err != nil {
381
-		c.Fatal(err)
382
-	}
383
-
384
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent:rw", "busybox", "touch", "/test/file")
385
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
386
-		c.Fatalf("running --volumes-from parent:rw failed with output: %q\nerror: %v", out, err)
387
-	}
371
+	dockerCmd(c, "run", "--name", "parent", "-v", "/test", "busybox", "true")
372
+	dockerCmd(c, "run", "--volumes-from", "parent:rw", "busybox", "touch", "/test/file")
388 373
 
389
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent:bar", "busybox", "touch", "/test/file")
390
-	if out, _, err := runCommandWithOutput(cmd); err == nil || !strings.Contains(out, "invalid mode for volumes-from: bar") {
374
+	if out, _, err := dockerCmdWithError(c, "run", "--volumes-from", "parent:bar", "busybox", "touch", "/test/file"); err == nil || !strings.Contains(out, "invalid mode for volumes-from: bar") {
391 375
 		c.Fatalf("running --volumes-from foo:bar should have failed with invalid mount mode: %q", out)
392 376
 	}
393 377
 
394
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent", "busybox", "touch", "/test/file")
395
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
396
-		c.Fatalf("running --volumes-from parent failed with output: %q\nerror: %v", out, err)
397
-	}
378
+	dockerCmd(c, "run", "--volumes-from", "parent", "busybox", "touch", "/test/file")
398 379
 }
399 380
 
400 381
 func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) {
401
-	cmd := exec.Command(dockerBinary, "run", "--name", "parent", "-v", "/test:/test:ro", "busybox", "true")
402
-	if _, err := runCommand(cmd); err != nil {
403
-		c.Fatal(err)
404
-	}
382
+	dockerCmd(c, "run", "--name", "parent", "-v", "/test:/test:ro", "busybox", "true")
383
+
405 384
 	// Expect this "rw" mode to be be ignored since the inherited volume is "ro"
406
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent:rw", "busybox", "touch", "/test/file")
407
-	if _, err := runCommand(cmd); err == nil {
385
+	if _, _, err := dockerCmdWithError(c, "run", "--volumes-from", "parent:rw", "busybox", "touch", "/test/file"); err == nil {
408 386
 		c.Fatal("Expected volumes-from to inherit read-only volume even when passing in `rw`")
409 387
 	}
410 388
 
411
-	cmd = exec.Command(dockerBinary, "run", "--name", "parent2", "-v", "/test:/test:ro", "busybox", "true")
412
-	if _, err := runCommand(cmd); err != nil {
413
-		c.Fatal(err)
414
-	}
389
+	dockerCmd(c, "run", "--name", "parent2", "-v", "/test:/test:ro", "busybox", "true")
390
+
415 391
 	// Expect this to be read-only since both are "ro"
416
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent2:ro", "busybox", "touch", "/test/file")
417
-	if _, err := runCommand(cmd); err == nil {
392
+	if _, _, err := dockerCmdWithError(c, "run", "--volumes-from", "parent2:ro", "busybox", "touch", "/test/file"); err == nil {
418 393
 		c.Fatal("Expected volumes-from to inherit read-only volume even when passing in `ro`")
419 394
 	}
420 395
 }
... ...
@@ -424,8 +314,7 @@ func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) {
424 424
 	mountstr1 := randomUnixTmpDirPath("test1") + ":/someplace"
425 425
 	mountstr2 := randomUnixTmpDirPath("test2") + ":/someplace"
426 426
 
427
-	cmd := exec.Command(dockerBinary, "run", "-v", mountstr1, "-v", mountstr2, "busybox", "true")
428
-	if out, _, err := runCommandWithOutput(cmd); err == nil {
427
+	if out, _, err := dockerCmdWithError(c, "run", "-v", mountstr1, "-v", mountstr2, "busybox", "true"); err == nil {
429 428
 		c.Fatal("Expected error about duplicate volume definitions")
430 429
 	} else {
431 430
 		if !strings.Contains(out, "Duplicate bind mount") {
... ...
@@ -436,45 +325,26 @@ func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) {
436 436
 
437 437
 // Test for #1351
438 438
 func (s *DockerSuite) TestRunApplyVolumesFromBeforeVolumes(c *check.C) {
439
-	cmd := exec.Command(dockerBinary, "run", "--name", "parent", "-v", "/test", "busybox", "touch", "/test/foo")
440
-	if _, err := runCommand(cmd); err != nil {
441
-		c.Fatal(err)
442
-	}
443
-
444
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent", "-v", "/test", "busybox", "cat", "/test/foo")
445
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
446
-		c.Fatal(out, err)
447
-	}
439
+	dockerCmd(c, "run", "--name", "parent", "-v", "/test", "busybox", "touch", "/test/foo")
440
+	dockerCmd(c, "run", "--volumes-from", "parent", "-v", "/test", "busybox", "cat", "/test/foo")
448 441
 }
449 442
 
450 443
 func (s *DockerSuite) TestRunMultipleVolumesFrom(c *check.C) {
451
-	cmd := exec.Command(dockerBinary, "run", "--name", "parent1", "-v", "/test", "busybox", "touch", "/test/foo")
452
-	if _, err := runCommand(cmd); err != nil {
453
-		c.Fatal(err)
454
-	}
455
-
456
-	cmd = exec.Command(dockerBinary, "run", "--name", "parent2", "-v", "/other", "busybox", "touch", "/other/bar")
457
-	if _, err := runCommand(cmd); err != nil {
458
-		c.Fatal(err)
459
-	}
460
-
461
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "parent1", "--volumes-from", "parent2",
462
-		"busybox", "sh", "-c", "cat /test/foo && cat /other/bar")
463
-	if _, err := runCommand(cmd); err != nil {
464
-		c.Fatal(err)
465
-	}
444
+	dockerCmd(c, "run", "--name", "parent1", "-v", "/test", "busybox", "touch", "/test/foo")
445
+	dockerCmd(c, "run", "--name", "parent2", "-v", "/other", "busybox", "touch", "/other/bar")
446
+	dockerCmd(c, "run", "--volumes-from", "parent1", "--volumes-from", "parent2", "busybox", "sh", "-c", "cat /test/foo && cat /other/bar")
466 447
 }
467 448
 
468 449
 // this tests verifies the ID format for the container
469 450
 func (s *DockerSuite) TestRunVerifyContainerID(c *check.C) {
470
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
471
-	out, exit, err := runCommandWithOutput(cmd)
451
+	out, exit, err := dockerCmdWithError(c, "run", "-d", "busybox", "true")
472 452
 	if err != nil {
473 453
 		c.Fatal(err)
474 454
 	}
475 455
 	if exit != 0 {
476 456
 		c.Fatalf("expected exit code 0 received %d", exit)
477 457
 	}
458
+
478 459
 	match, err := regexp.MatchString("^[0-9a-f]{64}$", strings.TrimSuffix(out, "\n"))
479 460
 	if err != nil {
480 461
 		c.Fatal(err)
... ...
@@ -486,10 +356,7 @@ func (s *DockerSuite) TestRunVerifyContainerID(c *check.C) {
486 486
 
487 487
 // Test that creating a container with a volume doesn't crash. Regression test for #995.
488 488
 func (s *DockerSuite) TestRunCreateVolume(c *check.C) {
489
-	cmd := exec.Command(dockerBinary, "run", "-v", "/var/lib/data", "busybox", "true")
490
-	if _, err := runCommand(cmd); err != nil {
491
-		c.Fatal(err)
492
-	}
489
+	dockerCmd(c, "run", "-v", "/var/lib/data", "busybox", "true")
493 490
 }
494 491
 
495 492
 // Test that creating a volume with a symlink in its path works correctly. Test for #5152.
... ...
@@ -506,21 +373,18 @@ func (s *DockerSuite) TestRunCreateVolumeWithSymlink(c *check.C) {
506 506
 		c.Fatalf("could not build '%s': %v", image, err)
507 507
 	}
508 508
 
509
-	cmd := exec.Command(dockerBinary, "run", "-v", "/bar/foo", "--name", "test-createvolumewithsymlink", image, "sh", "-c", "mount | grep -q /home/foo")
510
-	exitCode, err := runCommand(cmd)
509
+	_, exitCode, err := dockerCmdWithError(c, "run", "-v", "/bar/foo", "--name", "test-createvolumewithsymlink", image, "sh", "-c", "mount | grep -q /home/foo")
511 510
 	if err != nil || exitCode != 0 {
512 511
 		c.Fatalf("[run] err: %v, exitcode: %d", err, exitCode)
513 512
 	}
514 513
 
515 514
 	var volPath string
516
-	cmd = exec.Command(dockerBinary, "inspect", "-f", "{{range .Volumes}}{{.}}{{end}}", "test-createvolumewithsymlink")
517
-	volPath, exitCode, err = runCommandWithOutput(cmd)
515
+	volPath, exitCode, err = dockerCmdWithError(c, "inspect", "-f", "{{range .Volumes}}{{.}}{{end}}", "test-createvolumewithsymlink")
518 516
 	if err != nil || exitCode != 0 {
519 517
 		c.Fatalf("[inspect] err: %v, exitcode: %d", err, exitCode)
520 518
 	}
521 519
 
522
-	cmd = exec.Command(dockerBinary, "rm", "-v", "test-createvolumewithsymlink")
523
-	exitCode, err = runCommand(cmd)
520
+	_, exitCode, err = dockerCmdWithError(c, "rm", "-v", "test-createvolumewithsymlink")
524 521
 	if err != nil || exitCode != 0 {
525 522
 		c.Fatalf("[rm] err: %v, exitcode: %d", err, exitCode)
526 523
 	}
... ...
@@ -546,23 +410,19 @@ func (s *DockerSuite) TestRunVolumesFromSymlinkPath(c *check.C) {
546 546
 		c.Fatalf("could not build 'docker-test-volumesfromsymlinkpath': %v", err)
547 547
 	}
548 548
 
549
-	cmd := exec.Command(dockerBinary, "run", "--name", "test-volumesfromsymlinkpath", name)
550
-	exitCode, err := runCommand(cmd)
549
+	_, exitCode, err := dockerCmdWithError(c, "run", "--name", "test-volumesfromsymlinkpath", name)
551 550
 	if err != nil || exitCode != 0 {
552 551
 		c.Fatalf("[run] (volume) err: %v, exitcode: %d", err, exitCode)
553 552
 	}
554 553
 
555
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "test-volumesfromsymlinkpath", "busybox", "sh", "-c", "ls /foo | grep -q bar")
556
-	exitCode, err = runCommand(cmd)
554
+	_, exitCode, err = dockerCmdWithError(c, "run", "--volumes-from", "test-volumesfromsymlinkpath", "busybox", "sh", "-c", "ls /foo | grep -q bar")
557 555
 	if err != nil || exitCode != 0 {
558 556
 		c.Fatalf("[run] err: %v, exitcode: %d", err, exitCode)
559 557
 	}
560 558
 }
561 559
 
562 560
 func (s *DockerSuite) TestRunExitCode(c *check.C) {
563
-	cmd := exec.Command(dockerBinary, "run", "busybox", "/bin/sh", "-c", "exit 72")
564
-
565
-	exit, err := runCommand(cmd)
561
+	_, exit, err := dockerCmdWithError(c, "run", "busybox", "/bin/sh", "-c", "exit 72")
566 562
 	if err == nil {
567 563
 		c.Fatal("should not have a non nil error")
568 564
 	}
... ...
@@ -572,41 +432,28 @@ func (s *DockerSuite) TestRunExitCode(c *check.C) {
572 572
 }
573 573
 
574 574
 func (s *DockerSuite) TestRunUserDefaultsToRoot(c *check.C) {
575
-	cmd := exec.Command(dockerBinary, "run", "busybox", "id")
576
-	out, _, err := runCommandWithOutput(cmd)
577
-	if err != nil {
578
-		c.Fatal(err, out)
579
-	}
575
+	out, _ := dockerCmd(c, "run", "busybox", "id")
580 576
 	if !strings.Contains(out, "uid=0(root) gid=0(root)") {
581 577
 		c.Fatalf("expected root user got %s", out)
582 578
 	}
583 579
 }
584 580
 
585 581
 func (s *DockerSuite) TestRunUserByName(c *check.C) {
586
-	cmd := exec.Command(dockerBinary, "run", "-u", "root", "busybox", "id")
587
-	out, _, err := runCommandWithOutput(cmd)
588
-	if err != nil {
589
-		c.Fatal(err, out)
590
-	}
582
+	out, _ := dockerCmd(c, "run", "-u", "root", "busybox", "id")
591 583
 	if !strings.Contains(out, "uid=0(root) gid=0(root)") {
592 584
 		c.Fatalf("expected root user got %s", out)
593 585
 	}
594 586
 }
595 587
 
596 588
 func (s *DockerSuite) TestRunUserByID(c *check.C) {
597
-	cmd := exec.Command(dockerBinary, "run", "-u", "1", "busybox", "id")
598
-	out, _, err := runCommandWithOutput(cmd)
599
-	if err != nil {
600
-		c.Fatal(err, out)
601
-	}
589
+	out, _ := dockerCmd(c, "run", "-u", "1", "busybox", "id")
602 590
 	if !strings.Contains(out, "uid=1(daemon) gid=1(daemon)") {
603 591
 		c.Fatalf("expected daemon user got %s", out)
604 592
 	}
605 593
 }
606 594
 
607 595
 func (s *DockerSuite) TestRunUserByIDBig(c *check.C) {
608
-	cmd := exec.Command(dockerBinary, "run", "-u", "2147483648", "busybox", "id")
609
-	out, _, err := runCommandWithOutput(cmd)
596
+	out, _, err := dockerCmdWithError(c, "run", "-u", "2147483648", "busybox", "id")
610 597
 	if err == nil {
611 598
 		c.Fatal("No error, but must be.", out)
612 599
 	}
... ...
@@ -616,8 +463,7 @@ func (s *DockerSuite) TestRunUserByIDBig(c *check.C) {
616 616
 }
617 617
 
618 618
 func (s *DockerSuite) TestRunUserByIDNegative(c *check.C) {
619
-	cmd := exec.Command(dockerBinary, "run", "-u", "-1", "busybox", "id")
620
-	out, _, err := runCommandWithOutput(cmd)
619
+	out, _, err := dockerCmdWithError(c, "run", "-u", "-1", "busybox", "id")
621 620
 	if err == nil {
622 621
 		c.Fatal("No error, but must be.", out)
623 622
 	}
... ...
@@ -627,8 +473,7 @@ func (s *DockerSuite) TestRunUserByIDNegative(c *check.C) {
627 627
 }
628 628
 
629 629
 func (s *DockerSuite) TestRunUserByIDZero(c *check.C) {
630
-	cmd := exec.Command(dockerBinary, "run", "-u", "0", "busybox", "id")
631
-	out, _, err := runCommandWithOutput(cmd)
630
+	out, _, err := dockerCmdWithError(c, "run", "-u", "0", "busybox", "id")
632 631
 	if err != nil {
633 632
 		c.Fatal(err, out)
634 633
 	}
... ...
@@ -638,8 +483,7 @@ func (s *DockerSuite) TestRunUserByIDZero(c *check.C) {
638 638
 }
639 639
 
640 640
 func (s *DockerSuite) TestRunUserNotFound(c *check.C) {
641
-	cmd := exec.Command(dockerBinary, "run", "-u", "notme", "busybox", "id")
642
-	_, err := runCommand(cmd)
641
+	_, _, err := dockerCmdWithError(c, "run", "-u", "notme", "busybox", "id")
643 642
 	if err == nil {
644 643
 		c.Fatal("unknown user should cause container to fail")
645 644
 	}
... ...
@@ -653,8 +497,7 @@ func (s *DockerSuite) TestRunTwoConcurrentContainers(c *check.C) {
653 653
 	for i := 0; i < 2; i++ {
654 654
 		go func() {
655 655
 			defer group.Done()
656
-			cmd := exec.Command(dockerBinary, "run", "busybox", "sleep", "2")
657
-			_, err := runCommand(cmd)
656
+			_, _, err := dockerCmdWithError(c, "run", "busybox", "sleep", "2")
658 657
 			errChan <- err
659 658
 		}()
660 659
 	}
... ...
@@ -784,19 +627,13 @@ func (s *DockerSuite) TestRunEnvironmentOverride(c *check.C) {
784 784
 }
785 785
 
786 786
 func (s *DockerSuite) TestRunContainerNetwork(c *check.C) {
787
-	cmd := exec.Command(dockerBinary, "run", "busybox", "ping", "-c", "1", "127.0.0.1")
788
-	if _, err := runCommand(cmd); err != nil {
789
-		c.Fatal(err)
790
-	}
787
+	dockerCmd(c, "run", "busybox", "ping", "-c", "1", "127.0.0.1")
791 788
 }
792 789
 
793 790
 func (s *DockerSuite) TestRunNetHostNotAllowedWithLinks(c *check.C) {
794
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "linked", "busybox", "true"))
795
-	if err != nil {
796
-		c.Fatalf("Failed with errors: %s, %v", out, err)
797
-	}
798
-	cmd := exec.Command(dockerBinary, "run", "--net=host", "--link", "linked:linked", "busybox", "true")
799
-	_, _, err = runCommandWithOutput(cmd)
791
+	dockerCmd(c, "run", "--name", "linked", "busybox", "true")
792
+
793
+	_, _, err := dockerCmdWithError(c, "run", "--net=host", "--link", "linked:linked", "busybox", "true")
800 794
 	if err == nil {
801 795
 		c.Fatal("Expected error")
802 796
 	}
... ...
@@ -808,91 +645,67 @@ func (s *DockerSuite) TestRunNetHostNotAllowedWithLinks(c *check.C) {
808 808
 // codepath is executed with "docker run -h <hostname>".  Both were manually
809 809
 // tested, but this testcase takes the simpler path of using "run -h .."
810 810
 func (s *DockerSuite) TestRunFullHostnameSet(c *check.C) {
811
-	cmd := exec.Command(dockerBinary, "run", "-h", "foo.bar.baz", "busybox", "hostname")
812
-	out, _, err := runCommandWithOutput(cmd)
813
-	if err != nil {
814
-		c.Fatal(err, out)
815
-	}
816
-
811
+	out, _ := dockerCmd(c, "run", "-h", "foo.bar.baz", "busybox", "hostname")
817 812
 	if actual := strings.Trim(out, "\r\n"); actual != "foo.bar.baz" {
818 813
 		c.Fatalf("expected hostname 'foo.bar.baz', received %s", actual)
819 814
 	}
820 815
 }
821 816
 
822 817
 func (s *DockerSuite) TestRunPrivilegedCanMknod(c *check.C) {
823
-	cmd := exec.Command(dockerBinary, "run", "--privileged", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
824
-	out, _, err := runCommandWithOutput(cmd)
825
-	if err != nil {
826
-		c.Fatal(err)
827
-	}
828
-
818
+	out, _ := dockerCmd(c, "run", "--privileged", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
829 819
 	if actual := strings.Trim(out, "\r\n"); actual != "ok" {
830 820
 		c.Fatalf("expected output ok received %s", actual)
831 821
 	}
832 822
 }
833 823
 
834 824
 func (s *DockerSuite) TestRunUnprivilegedCanMknod(c *check.C) {
835
-	cmd := exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
836
-	out, _, err := runCommandWithOutput(cmd)
837
-	if err != nil {
838
-		c.Fatal(err)
839
-	}
840
-
825
+	out, _ := dockerCmd(c, "run", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
841 826
 	if actual := strings.Trim(out, "\r\n"); actual != "ok" {
842 827
 		c.Fatalf("expected output ok received %s", actual)
843 828
 	}
844 829
 }
845 830
 
846 831
 func (s *DockerSuite) TestRunCapDropInvalid(c *check.C) {
847
-	cmd := exec.Command(dockerBinary, "run", "--cap-drop=CHPASS", "busybox", "ls")
848
-	out, _, err := runCommandWithOutput(cmd)
832
+	out, _, err := dockerCmdWithError(c, "run", "--cap-drop=CHPASS", "busybox", "ls")
849 833
 	if err == nil {
850 834
 		c.Fatal(err, out)
851 835
 	}
852 836
 }
853 837
 
854 838
 func (s *DockerSuite) TestRunCapDropCannotMknod(c *check.C) {
855
-	cmd := exec.Command(dockerBinary, "run", "--cap-drop=MKNOD", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
856
-	out, _, err := runCommandWithOutput(cmd)
839
+	out, _, err := dockerCmdWithError(c, "run", "--cap-drop=MKNOD", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
840
+
857 841
 	if err == nil {
858 842
 		c.Fatal(err, out)
859 843
 	}
860
-
861 844
 	if actual := strings.Trim(out, "\r\n"); actual == "ok" {
862 845
 		c.Fatalf("expected output not ok received %s", actual)
863 846
 	}
864 847
 }
865 848
 
866 849
 func (s *DockerSuite) TestRunCapDropCannotMknodLowerCase(c *check.C) {
867
-	cmd := exec.Command(dockerBinary, "run", "--cap-drop=mknod", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
868
-	out, _, err := runCommandWithOutput(cmd)
850
+	out, _, err := dockerCmdWithError(c, "run", "--cap-drop=mknod", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
851
+
869 852
 	if err == nil {
870 853
 		c.Fatal(err, out)
871 854
 	}
872
-
873 855
 	if actual := strings.Trim(out, "\r\n"); actual == "ok" {
874 856
 		c.Fatalf("expected output not ok received %s", actual)
875 857
 	}
876 858
 }
877 859
 
878 860
 func (s *DockerSuite) TestRunCapDropALLCannotMknod(c *check.C) {
879
-	cmd := exec.Command(dockerBinary, "run", "--cap-drop=ALL", "--cap-add=SETGID", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
880
-	out, _, err := runCommandWithOutput(cmd)
861
+	out, _, err := dockerCmdWithError(c, "run", "--cap-drop=ALL", "--cap-add=SETGID", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
881 862
 	if err == nil {
882 863
 		c.Fatal(err, out)
883 864
 	}
884
-
885 865
 	if actual := strings.Trim(out, "\r\n"); actual == "ok" {
886 866
 		c.Fatalf("expected output not ok received %s", actual)
887 867
 	}
888 868
 }
889 869
 
890 870
 func (s *DockerSuite) TestRunCapDropALLAddMknodCanMknod(c *check.C) {
891
-	cmd := exec.Command(dockerBinary, "run", "--cap-drop=ALL", "--cap-add=MKNOD", "--cap-add=SETGID", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
892
-	out, _, err := runCommandWithOutput(cmd)
893
-	if err != nil {
894
-		c.Fatal(err, out)
895
-	}
871
+	out, _ := dockerCmd(c, "run", "--cap-drop=ALL", "--cap-add=MKNOD", "--cap-add=SETGID", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
896 872
 
897 873
 	if actual := strings.Trim(out, "\r\n"); actual != "ok" {
898 874
 		c.Fatalf("expected output ok received %s", actual)
... ...
@@ -900,19 +713,14 @@ func (s *DockerSuite) TestRunCapDropALLAddMknodCanMknod(c *check.C) {
900 900
 }
901 901
 
902 902
 func (s *DockerSuite) TestRunCapAddInvalid(c *check.C) {
903
-	cmd := exec.Command(dockerBinary, "run", "--cap-add=CHPASS", "busybox", "ls")
904
-	out, _, err := runCommandWithOutput(cmd)
903
+	out, _, err := dockerCmdWithError(c, "run", "--cap-add=CHPASS", "busybox", "ls")
905 904
 	if err == nil {
906 905
 		c.Fatal(err, out)
907 906
 	}
908 907
 }
909 908
 
910 909
 func (s *DockerSuite) TestRunCapAddCanDownInterface(c *check.C) {
911
-	cmd := exec.Command(dockerBinary, "run", "--cap-add=NET_ADMIN", "busybox", "sh", "-c", "ip link set eth0 down && echo ok")
912
-	out, _, err := runCommandWithOutput(cmd)
913
-	if err != nil {
914
-		c.Fatal(err, out)
915
-	}
910
+	out, _ := dockerCmd(c, "run", "--cap-add=NET_ADMIN", "busybox", "sh", "-c", "ip link set eth0 down && echo ok")
916 911
 
917 912
 	if actual := strings.Trim(out, "\r\n"); actual != "ok" {
918 913
 		c.Fatalf("expected output ok received %s", actual)
... ...
@@ -920,11 +728,7 @@ func (s *DockerSuite) TestRunCapAddCanDownInterface(c *check.C) {
920 920
 }
921 921
 
922 922
 func (s *DockerSuite) TestRunCapAddALLCanDownInterface(c *check.C) {
923
-	cmd := exec.Command(dockerBinary, "run", "--cap-add=ALL", "busybox", "sh", "-c", "ip link set eth0 down && echo ok")
924
-	out, _, err := runCommandWithOutput(cmd)
925
-	if err != nil {
926
-		c.Fatal(err, out)
927
-	}
923
+	out, _ := dockerCmd(c, "run", "--cap-add=ALL", "busybox", "sh", "-c", "ip link set eth0 down && echo ok")
928 924
 
929 925
 	if actual := strings.Trim(out, "\r\n"); actual != "ok" {
930 926
 		c.Fatalf("expected output ok received %s", actual)
... ...
@@ -932,23 +736,17 @@ func (s *DockerSuite) TestRunCapAddALLCanDownInterface(c *check.C) {
932 932
 }
933 933
 
934 934
 func (s *DockerSuite) TestRunCapAddALLDropNetAdminCanDownInterface(c *check.C) {
935
-	cmd := exec.Command(dockerBinary, "run", "--cap-add=ALL", "--cap-drop=NET_ADMIN", "busybox", "sh", "-c", "ip link set eth0 down && echo ok")
936
-	out, _, err := runCommandWithOutput(cmd)
935
+	out, _, err := dockerCmdWithError(c, "run", "--cap-add=ALL", "--cap-drop=NET_ADMIN", "busybox", "sh", "-c", "ip link set eth0 down && echo ok")
937 936
 	if err == nil {
938 937
 		c.Fatal(err, out)
939 938
 	}
940
-
941 939
 	if actual := strings.Trim(out, "\r\n"); actual == "ok" {
942 940
 		c.Fatalf("expected output not ok received %s", actual)
943 941
 	}
944 942
 }
945 943
 
946 944
 func (s *DockerSuite) TestRunGroupAdd(c *check.C) {
947
-	cmd := exec.Command(dockerBinary, "run", "--group-add=audio", "--group-add=dbus", "--group-add=777", "busybox", "sh", "-c", "id")
948
-	out, _, err := runCommandWithOutput(cmd)
949
-	if err != nil {
950
-		c.Fatal(err, out)
951
-	}
945
+	out, _ := dockerCmd(c, "run", "--group-add=audio", "--group-add=dbus", "--group-add=777", "busybox", "sh", "-c", "id")
952 946
 
953 947
 	groupsList := "uid=0(root) gid=0(root) groups=10(wheel),29(audio),81(dbus),777"
954 948
 	if actual := strings.Trim(out, "\r\n"); actual != groupsList {
... ...
@@ -957,11 +755,7 @@ func (s *DockerSuite) TestRunGroupAdd(c *check.C) {
957 957
 }
958 958
 
959 959
 func (s *DockerSuite) TestRunPrivilegedCanMount(c *check.C) {
960
-	cmd := exec.Command(dockerBinary, "run", "--privileged", "busybox", "sh", "-c", "mount -t tmpfs none /tmp && echo ok")
961
-	out, _, err := runCommandWithOutput(cmd)
962
-	if err != nil {
963
-		c.Fatal(err)
964
-	}
960
+	out, _ := dockerCmd(c, "run", "--privileged", "busybox", "sh", "-c", "mount -t tmpfs none /tmp && echo ok")
965 961
 
966 962
 	if actual := strings.Trim(out, "\r\n"); actual != "ok" {
967 963
 		c.Fatalf("expected output ok received %s", actual)
... ...
@@ -969,86 +763,72 @@ func (s *DockerSuite) TestRunPrivilegedCanMount(c *check.C) {
969 969
 }
970 970
 
971 971
 func (s *DockerSuite) TestRunUnprivilegedCannotMount(c *check.C) {
972
-	cmd := exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "mount -t tmpfs none /tmp && echo ok")
973
-	out, _, err := runCommandWithOutput(cmd)
972
+	out, _, err := dockerCmdWithError(c, "run", "busybox", "sh", "-c", "mount -t tmpfs none /tmp && echo ok")
973
+
974 974
 	if err == nil {
975 975
 		c.Fatal(err, out)
976 976
 	}
977
-
978 977
 	if actual := strings.Trim(out, "\r\n"); actual == "ok" {
979 978
 		c.Fatalf("expected output not ok received %s", actual)
980 979
 	}
981 980
 }
982 981
 
983 982
 func (s *DockerSuite) TestRunSysNotWritableInNonPrivilegedContainers(c *check.C) {
984
-	cmd := exec.Command(dockerBinary, "run", "busybox", "touch", "/sys/kernel/profiling")
985
-	if code, err := runCommand(cmd); err == nil || code == 0 {
983
+	if _, code, err := dockerCmdWithError(c, "run", "busybox", "touch", "/sys/kernel/profiling"); err == nil || code == 0 {
986 984
 		c.Fatal("sys should not be writable in a non privileged container")
987 985
 	}
988 986
 }
989 987
 
990 988
 func (s *DockerSuite) TestRunSysWritableInPrivilegedContainers(c *check.C) {
991
-	cmd := exec.Command(dockerBinary, "run", "--privileged", "busybox", "touch", "/sys/kernel/profiling")
992
-	if code, err := runCommand(cmd); err != nil || code != 0 {
989
+	if _, code, err := dockerCmdWithError(c, "run", "--privileged", "busybox", "touch", "/sys/kernel/profiling"); err != nil || code != 0 {
993 990
 		c.Fatalf("sys should be writable in privileged container")
994 991
 	}
995 992
 }
996 993
 
997 994
 func (s *DockerSuite) TestRunProcNotWritableInNonPrivilegedContainers(c *check.C) {
998
-	cmd := exec.Command(dockerBinary, "run", "busybox", "touch", "/proc/sysrq-trigger")
999
-	if code, err := runCommand(cmd); err == nil || code == 0 {
995
+	if _, code, err := dockerCmdWithError(c, "run", "busybox", "touch", "/proc/sysrq-trigger"); err == nil || code == 0 {
1000 996
 		c.Fatal("proc should not be writable in a non privileged container")
1001 997
 	}
1002 998
 }
1003 999
 
1004 1000
 func (s *DockerSuite) TestRunProcWritableInPrivilegedContainers(c *check.C) {
1005
-	cmd := exec.Command(dockerBinary, "run", "--privileged", "busybox", "touch", "/proc/sysrq-trigger")
1006
-	if code, err := runCommand(cmd); err != nil || code != 0 {
1001
+	if _, code := dockerCmd(c, "run", "--privileged", "busybox", "touch", "/proc/sysrq-trigger"); code != 0 {
1007 1002
 		c.Fatalf("proc should be writable in privileged container")
1008 1003
 	}
1009 1004
 }
1010 1005
 
1011 1006
 func (s *DockerSuite) TestRunWithCpuset(c *check.C) {
1012
-	cmd := exec.Command(dockerBinary, "run", "--cpuset", "0", "busybox", "true")
1013
-	if code, err := runCommand(cmd); err != nil || code != 0 {
1014
-		c.Fatalf("container should run successfully with cpuset of 0: %s", err)
1007
+	if _, code := dockerCmd(c, "run", "--cpuset", "0", "busybox", "true"); code != 0 {
1008
+		c.Fatalf("container should run successfully with cpuset of 0")
1015 1009
 	}
1016 1010
 }
1017 1011
 
1018 1012
 func (s *DockerSuite) TestRunWithCpusetCpus(c *check.C) {
1019
-	cmd := exec.Command(dockerBinary, "run", "--cpuset-cpus", "0", "busybox", "true")
1020
-	if code, err := runCommand(cmd); err != nil || code != 0 {
1021
-		c.Fatalf("container should run successfully with cpuset-cpus of 0: %s", err)
1013
+	if _, code := dockerCmd(c, "run", "--cpuset-cpus", "0", "busybox", "true"); code != 0 {
1014
+		c.Fatalf("container should run successfully with cpuset-cpus of 0")
1022 1015
 	}
1023 1016
 }
1024 1017
 
1025 1018
 func (s *DockerSuite) TestRunWithCpusetMems(c *check.C) {
1026
-	cmd := exec.Command(dockerBinary, "run", "--cpuset-mems", "0", "busybox", "true")
1027
-	if code, err := runCommand(cmd); err != nil || code != 0 {
1028
-		c.Fatalf("container should run successfully with cpuset-mems of 0: %s", err)
1019
+	if _, code := dockerCmd(c, "run", "--cpuset-mems", "0", "busybox", "true"); code != 0 {
1020
+		c.Fatalf("container should run successfully with cpuset-mems of 0")
1029 1021
 	}
1030 1022
 }
1031 1023
 
1032 1024
 func (s *DockerSuite) TestRunWithBlkioWeight(c *check.C) {
1033
-	cmd := exec.Command(dockerBinary, "run", "--blkio-weight", "300", "busybox", "true")
1034
-	if code, err := runCommand(cmd); err != nil || code != 0 {
1035
-		c.Fatalf("container should run successfully with blkio-weight of 300: %s", err)
1025
+	if _, code := dockerCmd(c, "run", "--blkio-weight", "300", "busybox", "true"); code != 0 {
1026
+		c.Fatalf("container should run successfully with blkio-weight of 300")
1036 1027
 	}
1037 1028
 }
1038 1029
 
1039 1030
 func (s *DockerSuite) TestRunWithBlkioInvalidWeight(c *check.C) {
1040
-	cmd := exec.Command(dockerBinary, "run", "--blkio-weight", "5", "busybox", "true")
1041
-	if _, err := runCommand(cmd); err == nil {
1031
+	if _, _, err := dockerCmdWithError(c, "run", "--blkio-weight", "5", "busybox", "true"); err == nil {
1042 1032
 		c.Fatalf("run with invalid blkio-weight should failed")
1043 1033
 	}
1044 1034
 }
1045 1035
 
1046 1036
 func (s *DockerSuite) TestRunDeviceNumbers(c *check.C) {
1047
-	cmd := exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "ls -l /dev/null")
1048
-	out, _, err := runCommandWithOutput(cmd)
1049
-	if err != nil {
1050
-		c.Fatal(err, out)
1051
-	}
1037
+	out, _ := dockerCmd(c, "run", "busybox", "sh", "-c", "ls -l /dev/null")
1052 1038
 	deviceLineFields := strings.Fields(out)
1053 1039
 	deviceLineFields[6] = ""
1054 1040
 	deviceLineFields[7] = ""
... ...
@@ -1061,31 +841,18 @@ func (s *DockerSuite) TestRunDeviceNumbers(c *check.C) {
1061 1061
 }
1062 1062
 
1063 1063
 func (s *DockerSuite) TestRunThatCharacterDevicesActLikeCharacterDevices(c *check.C) {
1064
-	cmd := exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "dd if=/dev/zero of=/zero bs=1k count=5 2> /dev/null ; du -h /zero")
1065
-	out, _, err := runCommandWithOutput(cmd)
1066
-	if err != nil {
1067
-		c.Fatal(err, out)
1068
-	}
1069
-
1064
+	out, _ := dockerCmd(c, "run", "busybox", "sh", "-c", "dd if=/dev/zero of=/zero bs=1k count=5 2> /dev/null ; du -h /zero")
1070 1065
 	if actual := strings.Trim(out, "\r\n"); actual[0] == '0' {
1071 1066
 		c.Fatalf("expected a new file called /zero to be create that is greater than 0 bytes long, but du says: %s", actual)
1072 1067
 	}
1073 1068
 }
1074 1069
 
1075 1070
 func (s *DockerSuite) TestRunUnprivilegedWithChroot(c *check.C) {
1076
-	cmd := exec.Command(dockerBinary, "run", "busybox", "chroot", "/", "true")
1077
-	if _, err := runCommand(cmd); err != nil {
1078
-		c.Fatal(err)
1079
-	}
1071
+	dockerCmd(c, "run", "busybox", "chroot", "/", "true")
1080 1072
 }
1081 1073
 
1082 1074
 func (s *DockerSuite) TestRunAddingOptionalDevices(c *check.C) {
1083
-	cmd := exec.Command(dockerBinary, "run", "--device", "/dev/zero:/dev/nulo", "busybox", "sh", "-c", "ls /dev/nulo")
1084
-	out, _, err := runCommandWithOutput(cmd)
1085
-	if err != nil {
1086
-		c.Fatal(err, out)
1087
-	}
1088
-
1075
+	out, _ := dockerCmd(c, "run", "--device", "/dev/zero:/dev/nulo", "busybox", "sh", "-c", "ls /dev/nulo")
1089 1076
 	if actual := strings.Trim(out, "\r\n"); actual != "/dev/nulo" {
1090 1077
 		c.Fatalf("expected output /dev/nulo, received %s", actual)
1091 1078
 	}
... ...
@@ -1094,22 +861,14 @@ func (s *DockerSuite) TestRunAddingOptionalDevices(c *check.C) {
1094 1094
 func (s *DockerSuite) TestRunModeHostname(c *check.C) {
1095 1095
 	testRequires(c, SameHostDaemon)
1096 1096
 
1097
-	cmd := exec.Command(dockerBinary, "run", "-h=testhostname", "busybox", "cat", "/etc/hostname")
1098
-	out, _, err := runCommandWithOutput(cmd)
1099
-	if err != nil {
1100
-		c.Fatal(err, out)
1101
-	}
1097
+	out, _ := dockerCmd(c, "run", "-h=testhostname", "busybox", "cat", "/etc/hostname")
1102 1098
 
1103 1099
 	if actual := strings.Trim(out, "\r\n"); actual != "testhostname" {
1104 1100
 		c.Fatalf("expected 'testhostname', but says: %q", actual)
1105 1101
 	}
1106 1102
 
1107
-	cmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hostname")
1103
+	out, _ = dockerCmd(c, "run", "--net=host", "busybox", "cat", "/etc/hostname")
1108 1104
 
1109
-	out, _, err = runCommandWithOutput(cmd)
1110
-	if err != nil {
1111
-		c.Fatal(err, out)
1112
-	}
1113 1105
 	hostname, err := os.Hostname()
1114 1106
 	if err != nil {
1115 1107
 		c.Fatal(err)
... ...
@@ -1120,25 +879,18 @@ func (s *DockerSuite) TestRunModeHostname(c *check.C) {
1120 1120
 }
1121 1121
 
1122 1122
 func (s *DockerSuite) TestRunRootWorkdir(c *check.C) {
1123
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--workdir", "/", "busybox", "pwd"))
1124
-	if err != nil {
1125
-		c.Fatalf("Failed with errors: %s, %v", out, err)
1126
-	}
1123
+	out, _ := dockerCmd(c, "run", "--workdir", "/", "busybox", "pwd")
1127 1124
 	if out != "/\n" {
1128 1125
 		c.Fatalf("pwd returned %q (expected /\\n)", s)
1129 1126
 	}
1130 1127
 }
1131 1128
 
1132 1129
 func (s *DockerSuite) TestRunAllowBindMountingRoot(c *check.C) {
1133
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-v", "/:/host", "busybox", "ls", "/host"))
1134
-	if err != nil {
1135
-		c.Fatalf("Failed with errors: %s, %v", out, err)
1136
-	}
1130
+	dockerCmd(c, "run", "-v", "/:/host", "busybox", "ls", "/host")
1137 1131
 }
1138 1132
 
1139 1133
 func (s *DockerSuite) TestRunDisallowBindMountingRootToRoot(c *check.C) {
1140
-	cmd := exec.Command(dockerBinary, "run", "-v", "/:/", "busybox", "ls", "/host")
1141
-	out, _, err := runCommandWithOutput(cmd)
1134
+	out, _, err := dockerCmdWithError(c, "run", "-v", "/:/", "busybox", "ls", "/host")
1142 1135
 	if err == nil {
1143 1136
 		c.Fatal(out, err)
1144 1137
 	}
... ...
@@ -1168,13 +920,7 @@ func (s *DockerSuite) TestRunDnsDefaultOptions(c *check.C) {
1168 1168
 		c.Fatal(err)
1169 1169
 	}
1170 1170
 
1171
-	cmd := exec.Command(dockerBinary, "run", "busybox", "cat", "/etc/resolv.conf")
1172
-
1173
-	actual, _, err := runCommandWithOutput(cmd)
1174
-	if err != nil {
1175
-		c.Fatal(err, actual)
1176
-	}
1177
-
1171
+	actual, _ := dockerCmd(c, "run", "busybox", "cat", "/etc/resolv.conf")
1178 1172
 	// check that the actual defaults are appended to the commented out
1179 1173
 	// localhost resolver (which should be preserved)
1180 1174
 	// NOTE: if we ever change the defaults from google dns, this will break
... ...
@@ -1227,10 +973,7 @@ func (s *DockerSuite) TestRunDnsOptionsBasedOnHostResolvConf(c *check.C) {
1227 1227
 	hostSearch := resolvconf.GetSearchDomains(origResolvConf)
1228 1228
 
1229 1229
 	var out string
1230
-	cmd := exec.Command(dockerBinary, "run", "--dns=127.0.0.1", "busybox", "cat", "/etc/resolv.conf")
1231
-	if out, _, _, err = runCommandWithStdoutStderr(cmd); err != nil {
1232
-		c.Fatal(err, out)
1233
-	}
1230
+	out, _ = dockerCmd(c, "run", "--dns=127.0.0.1", "busybox", "cat", "/etc/resolv.conf")
1234 1231
 
1235 1232
 	if actualNameservers := resolvconf.GetNameservers([]byte(out)); string(actualNameservers[0]) != "127.0.0.1" {
1236 1233
 		c.Fatalf("expected '127.0.0.1', but says: %q", string(actualNameservers[0]))
... ...
@@ -1246,11 +989,7 @@ func (s *DockerSuite) TestRunDnsOptionsBasedOnHostResolvConf(c *check.C) {
1246 1246
 		}
1247 1247
 	}
1248 1248
 
1249
-	cmd = exec.Command(dockerBinary, "run", "--dns-search=mydomain", "busybox", "cat", "/etc/resolv.conf")
1250
-
1251
-	if out, _, err = runCommandWithOutput(cmd); err != nil {
1252
-		c.Fatal(err, out)
1253
-	}
1249
+	out, _ = dockerCmd(c, "run", "--dns-search=mydomain", "busybox", "cat", "/etc/resolv.conf")
1254 1250
 
1255 1251
 	actualNameservers := resolvconf.GetNameservers([]byte(out))
1256 1252
 	if len(actualNameservers) != len(hostNamservers) {
... ...
@@ -1286,12 +1025,7 @@ func (s *DockerSuite) TestRunDnsOptionsBasedOnHostResolvConf(c *check.C) {
1286 1286
 	hostNamservers = resolvconf.GetNameservers(resolvConf)
1287 1287
 	hostSearch = resolvconf.GetSearchDomains(resolvConf)
1288 1288
 
1289
-	cmd = exec.Command(dockerBinary, "run", "busybox", "cat", "/etc/resolv.conf")
1290
-
1291
-	if out, _, err = runCommandWithOutput(cmd); err != nil {
1292
-		c.Fatal(err, out)
1293
-	}
1294
-
1289
+	out, _ = dockerCmd(c, "run", "busybox", "cat", "/etc/resolv.conf")
1295 1290
 	if actualNameservers = resolvconf.GetNameservers([]byte(out)); string(actualNameservers[0]) != "12.34.56.78" || len(actualNameservers) != 1 {
1296 1291
 		c.Fatalf("expected '12.34.56.78', but has: %v", actualNameservers)
1297 1292
 	}
... ...
@@ -1313,10 +1047,7 @@ func (s *DockerSuite) TestRunNonRootUserResolvName(c *check.C) {
1313 1313
 	testRequires(c, SameHostDaemon)
1314 1314
 	testRequires(c, Network)
1315 1315
 
1316
-	cmd := exec.Command(dockerBinary, "run", "--name=testperm", "--user=default", "busybox", "ping", "-c", "1", "www.docker.io")
1317
-	if out, err := runCommand(cmd); err != nil {
1318
-		c.Fatal(err, out)
1319
-	}
1316
+	dockerCmd(c, "run", "--name=testperm", "--user=default", "busybox", "ping", "-c", "1", "www.docker.io")
1320 1317
 
1321 1318
 	cID, err := getIDByName("testperm")
1322 1319
 	if err != nil {
... ...
@@ -1365,10 +1096,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1365 1365
 	}()
1366 1366
 
1367 1367
 	//1. test that a restarting container gets an updated resolv.conf
1368
-	cmd = exec.Command(dockerBinary, "run", "--name='first'", "busybox", "true")
1369
-	if _, err := runCommand(cmd); err != nil {
1370
-		c.Fatal(err)
1371
-	}
1368
+	dockerCmd(c, "run", "--name='first'", "busybox", "true")
1372 1369
 	containerID1, err := getIDByName("first")
1373 1370
 	if err != nil {
1374 1371
 		c.Fatal(err)
... ...
@@ -1381,10 +1109,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1381 1381
 	}
1382 1382
 
1383 1383
 	// start the container again to pickup changes
1384
-	cmd = exec.Command(dockerBinary, "start", "first")
1385
-	if out, err := runCommand(cmd); err != nil {
1386
-		c.Fatalf("Errored out %s, \nerror: %v", string(out), err)
1387
-	}
1384
+	dockerCmd(c, "start", "first")
1388 1385
 
1389 1386
 	// check for update in container
1390 1387
 	containerResolv, err := readContainerFile(containerID1, "resolv.conf")
... ...
@@ -1397,14 +1122,11 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1397 1397
 
1398 1398
 	/*	//make a change to resolv.conf (in this case replacing our tmp copy with orig copy)
1399 1399
 		if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil {
1400
-			c.Fatal(err)
1401
-		} */
1400
+						c.Fatal(err)
1401
+								} */
1402 1402
 	//2. test that a restarting container does not receive resolv.conf updates
1403 1403
 	//   if it modified the container copy of the starting point resolv.conf
1404
-	cmd = exec.Command(dockerBinary, "run", "--name='second'", "busybox", "sh", "-c", "echo 'search mylittlepony.com' >>/etc/resolv.conf")
1405
-	if _, err = runCommand(cmd); err != nil {
1406
-		c.Fatal(err)
1407
-	}
1404
+	dockerCmd(c, "run", "--name='second'", "busybox", "sh", "-c", "echo 'search mylittlepony.com' >>/etc/resolv.conf")
1408 1405
 	containerID2, err := getIDByName("second")
1409 1406
 	if err != nil {
1410 1407
 		c.Fatal(err)
... ...
@@ -1416,10 +1138,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1416 1416
 	}
1417 1417
 
1418 1418
 	// start the container again
1419
-	cmd = exec.Command(dockerBinary, "start", "second")
1420
-	if out, err := runCommand(cmd); err != nil {
1421
-		c.Fatalf("Errored out %s, \nerror: %v", string(out), err)
1422
-	}
1419
+	dockerCmd(c, "start", "second")
1423 1420
 
1424 1421
 	// check for update in container
1425 1422
 	containerResolv, err = readContainerFile(containerID2, "resolv.conf")
... ...
@@ -1432,11 +1151,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1432 1432
 	}
1433 1433
 
1434 1434
 	//3. test that a running container's resolv.conf is not modified while running
1435
-	cmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1436
-	out, _, err := runCommandWithOutput(cmd)
1437
-	if err != nil {
1438
-		c.Fatal(err)
1439
-	}
1435
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
1440 1436
 	runningContainerID := strings.TrimSpace(out)
1441 1437
 
1442 1438
 	// replace resolv.conf
... ...
@@ -1456,10 +1171,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1456 1456
 
1457 1457
 	//4. test that a running container's resolv.conf is updated upon restart
1458 1458
 	//   (the above container is still running..)
1459
-	cmd = exec.Command(dockerBinary, "restart", runningContainerID)
1460
-	if _, err = runCommand(cmd); err != nil {
1461
-		c.Fatal(err)
1462
-	}
1459
+	dockerCmd(c, "restart", runningContainerID)
1463 1460
 
1464 1461
 	// check for update in container
1465 1462
 	containerResolv, err = readContainerFile(runningContainerID, "resolv.conf")
... ...
@@ -1480,10 +1192,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1480 1480
 	}
1481 1481
 
1482 1482
 	// start the container again to pickup changes
1483
-	cmd = exec.Command(dockerBinary, "start", "first")
1484
-	if out, err := runCommand(cmd); err != nil {
1485
-		c.Fatalf("Errored out %s, \nerror: %v", string(out), err)
1486
-	}
1483
+	dockerCmd(c, "start", "first")
1487 1484
 
1488 1485
 	// our first exited container ID should have been updated, but with default DNS
1489 1486
 	// after the cleanup of resolv.conf found only a localhost nameserver:
... ...
@@ -1506,10 +1215,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1506 1506
 	}
1507 1507
 
1508 1508
 	// Run the container so it picks up the old settings
1509
-	cmd = exec.Command(dockerBinary, "run", "--name='third'", "busybox", "true")
1510
-	if _, err := runCommand(cmd); err != nil {
1511
-		c.Fatal(err)
1512
-	}
1509
+	dockerCmd(c, "run", "--name='third'", "busybox", "true")
1513 1510
 	containerID3, err := getIDByName("third")
1514 1511
 	if err != nil {
1515 1512
 		c.Fatal(err)
... ...
@@ -1527,10 +1233,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1527 1527
 	}
1528 1528
 
1529 1529
 	// start the container again to pickup changes
1530
-	cmd = exec.Command(dockerBinary, "start", "third")
1531
-	if out, err := runCommand(cmd); err != nil {
1532
-		c.Fatalf("Errored out %s, \nerror: %v", string(out), err)
1533
-	}
1530
+	dockerCmd(c, "start", "third")
1534 1531
 
1535 1532
 	// check for update in container
1536 1533
 	containerResolv, err = readContainerFile(containerID3, "resolv.conf")
... ...
@@ -1545,12 +1248,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1545 1545
 }
1546 1546
 
1547 1547
 func (s *DockerSuite) TestRunAddHost(c *check.C) {
1548
-	cmd := exec.Command(dockerBinary, "run", "--add-host=extra:86.75.30.9", "busybox", "grep", "extra", "/etc/hosts")
1549
-
1550
-	out, _, err := runCommandWithOutput(cmd)
1551
-	if err != nil {
1552
-		c.Fatal(err, out)
1553
-	}
1548
+	out, _ := dockerCmd(c, "run", "--add-host=extra:86.75.30.9", "busybox", "grep", "extra", "/etc/hosts")
1554 1549
 
1555 1550
 	actual := strings.Trim(out, "\r\n")
1556 1551
 	if actual != "86.75.30.9\textra" {
... ...
@@ -1560,34 +1258,24 @@ func (s *DockerSuite) TestRunAddHost(c *check.C) {
1560 1560
 
1561 1561
 // Regression test for #6983
1562 1562
 func (s *DockerSuite) TestRunAttachStdErrOnlyTTYMode(c *check.C) {
1563
-	cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stderr", "busybox", "true")
1564
-	exitCode, err := runCommand(cmd)
1565
-	if err != nil {
1566
-		c.Fatal(err)
1567
-	} else if exitCode != 0 {
1563
+	_, exitCode := dockerCmd(c, "run", "-t", "-a", "stderr", "busybox", "true")
1564
+	if exitCode != 0 {
1568 1565
 		c.Fatalf("Container should have exited with error code 0")
1569 1566
 	}
1570 1567
 }
1571 1568
 
1572 1569
 // Regression test for #6983
1573 1570
 func (s *DockerSuite) TestRunAttachStdOutOnlyTTYMode(c *check.C) {
1574
-	cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stdout", "busybox", "true")
1575
-
1576
-	exitCode, err := runCommand(cmd)
1577
-	if err != nil {
1578
-		c.Fatal(err)
1579
-	} else if exitCode != 0 {
1571
+	_, exitCode := dockerCmd(c, "run", "-t", "-a", "stdout", "busybox", "true")
1572
+	if exitCode != 0 {
1580 1573
 		c.Fatalf("Container should have exited with error code 0")
1581 1574
 	}
1582 1575
 }
1583 1576
 
1584 1577
 // Regression test for #6983
1585 1578
 func (s *DockerSuite) TestRunAttachStdOutAndErrTTYMode(c *check.C) {
1586
-	cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stdout", "-a", "stderr", "busybox", "true")
1587
-	exitCode, err := runCommand(cmd)
1588
-	if err != nil {
1589
-		c.Fatal(err)
1590
-	} else if exitCode != 0 {
1579
+	_, exitCode := dockerCmd(c, "run", "-t", "-a", "stdout", "-a", "stderr", "busybox", "true")
1580
+	if exitCode != 0 {
1591 1581
 		c.Fatalf("Container should have exited with error code 0")
1592 1582
 	}
1593 1583
 }
... ...
@@ -1605,12 +1293,8 @@ func (s *DockerSuite) TestRunAttachWithDetach(c *check.C) {
1605 1605
 }
1606 1606
 
1607 1607
 func (s *DockerSuite) TestRunState(c *check.C) {
1608
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1608
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
1609 1609
 
1610
-	out, _, err := runCommandWithOutput(cmd)
1611
-	if err != nil {
1612
-		c.Fatal(err, out)
1613
-	}
1614 1610
 	id := strings.TrimSpace(out)
1615 1611
 	state, err := inspectField(id, "State.Running")
1616 1612
 	c.Assert(err, check.IsNil)
... ...
@@ -1623,11 +1307,7 @@ func (s *DockerSuite) TestRunState(c *check.C) {
1623 1623
 		c.Fatal("Container state Pid 0")
1624 1624
 	}
1625 1625
 
1626
-	cmd = exec.Command(dockerBinary, "stop", id)
1627
-	out, _, err = runCommandWithOutput(cmd)
1628
-	if err != nil {
1629
-		c.Fatal(err, out)
1630
-	}
1626
+	dockerCmd(c, "stop", id)
1631 1627
 	state, err = inspectField(id, "State.Running")
1632 1628
 	c.Assert(err, check.IsNil)
1633 1629
 	if state != "false" {
... ...
@@ -1639,11 +1319,7 @@ func (s *DockerSuite) TestRunState(c *check.C) {
1639 1639
 		c.Fatalf("Container state Pid %s, but expected %s", pid2, pid1)
1640 1640
 	}
1641 1641
 
1642
-	cmd = exec.Command(dockerBinary, "start", id)
1643
-	out, _, err = runCommandWithOutput(cmd)
1644
-	if err != nil {
1645
-		c.Fatal(err, out)
1646
-	}
1642
+	dockerCmd(c, "start", id)
1647 1643
 	state, err = inspectField(id, "State.Running")
1648 1644
 	c.Assert(err, check.IsNil)
1649 1645
 	if state != "true" {
... ...
@@ -1670,11 +1346,7 @@ func (s *DockerSuite) TestRunCopyVolumeUidGid(c *check.C) {
1670 1670
 	}
1671 1671
 
1672 1672
 	// Test that the uid and gid is copied from the image to the volume
1673
-	cmd := exec.Command(dockerBinary, "run", "--rm", "-v", "/hello", name, "sh", "-c", "ls -l / | grep hello | awk '{print $3\":\"$4}'")
1674
-	out, _, err := runCommandWithOutput(cmd)
1675
-	if err != nil {
1676
-		c.Fatal(err, out)
1677
-	}
1673
+	out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "sh", "-c", "ls -l / | grep hello | awk '{print $3\":\"$4}'")
1678 1674
 	out = strings.TrimSpace(out)
1679 1675
 	if out != "dockerio:dockerio" {
1680 1676
 		c.Fatalf("Wrong /hello ownership: %s, expected dockerio:dockerio", out)
... ...
@@ -1693,11 +1365,7 @@ func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) {
1693 1693
 	}
1694 1694
 
1695 1695
 	// Test that the content is copied from the image to the volume
1696
-	cmd := exec.Command(dockerBinary, "run", "--rm", "-v", "/hello", name, "find", "/hello")
1697
-	out, _, err := runCommandWithOutput(cmd)
1698
-	if err != nil {
1699
-		c.Fatal(err, out)
1700
-	}
1696
+	out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "find", "/hello")
1701 1697
 	if !(strings.Contains(out, "/hello/local/world") && strings.Contains(out, "/hello/local")) {
1702 1698
 		c.Fatal("Container failed to transfer content to volume")
1703 1699
 	}
... ...
@@ -1708,15 +1376,12 @@ func (s *DockerSuite) TestRunCleanupCmdOnEntrypoint(c *check.C) {
1708 1708
 	if _, err := buildImage(name,
1709 1709
 		`FROM busybox
1710 1710
 		ENTRYPOINT ["echo"]
1711
-	CMD ["testingpoint"]`,
1711
+		CMD ["testingpoint"]`,
1712 1712
 		true); err != nil {
1713 1713
 		c.Fatal(err)
1714 1714
 	}
1715
-	runCmd := exec.Command(dockerBinary, "run", "--entrypoint", "whoami", name)
1716
-	out, exit, err := runCommandWithOutput(runCmd)
1717
-	if err != nil {
1718
-		c.Fatalf("Error: %v, out: %q", err, out)
1719
-	}
1715
+
1716
+	out, exit := dockerCmd(c, "run", "--entrypoint", "whoami", name)
1720 1717
 	if exit != 0 {
1721 1718
 		c.Fatalf("expected exit code 0 received %d, out: %q", exit, out)
1722 1719
 	}
... ...
@@ -1728,8 +1393,7 @@ func (s *DockerSuite) TestRunCleanupCmdOnEntrypoint(c *check.C) {
1728 1728
 
1729 1729
 // TestRunWorkdirExistsAndIsFile checks that if 'docker run -w' with existing file can be detected
1730 1730
 func (s *DockerSuite) TestRunWorkdirExistsAndIsFile(c *check.C) {
1731
-	runCmd := exec.Command(dockerBinary, "run", "-w", "/bin/cat", "busybox")
1732
-	out, exit, err := runCommandWithOutput(runCmd)
1731
+	out, exit, err := dockerCmdWithError(c, "run", "-w", "/bin/cat", "busybox")
1733 1732
 	if !(err != nil && exit == 1 && strings.Contains(out, "Cannot mkdir: /bin/cat is not a directory")) {
1734 1733
 		c.Fatalf("Docker must complains about making dir, but we got out: %s, exit: %d, err: %s", out, exit, err)
1735 1734
 	}
... ...
@@ -1789,38 +1453,22 @@ func (s *DockerSuite) TestRunExitOnStdinClose(c *check.C) {
1789 1789
 // Test for #2267
1790 1790
 func (s *DockerSuite) TestRunWriteHostsFileAndNotCommit(c *check.C) {
1791 1791
 	name := "writehosts"
1792
-	cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hosts && cat /etc/hosts")
1793
-	out, _, err := runCommandWithOutput(cmd)
1794
-	if err != nil {
1795
-		c.Fatal(err, out)
1796
-	}
1792
+	out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hosts && cat /etc/hosts")
1797 1793
 	if !strings.Contains(out, "test2267") {
1798 1794
 		c.Fatal("/etc/hosts should contain 'test2267'")
1799 1795
 	}
1800 1796
 
1801
-	cmd = exec.Command(dockerBinary, "diff", name)
1802
-	if err != nil {
1803
-		c.Fatal(err, out)
1804
-	}
1805
-	out, _, err = runCommandWithOutput(cmd)
1806
-	if err != nil {
1807
-		c.Fatal(err, out)
1808
-	}
1809
-
1797
+	out, _ = dockerCmd(c, "diff", name)
1810 1798
 	if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, c) {
1811 1799
 		c.Fatal("diff should be empty")
1812 1800
 	}
1813 1801
 }
1814 1802
 
1815 1803
 func eqToBaseDiff(out string, c *check.C) bool {
1816
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
1817
-	out1, _, err := runCommandWithOutput(cmd)
1804
+	out1, _ := dockerCmd(c, "run", "-d", "busybox", "echo", "hello")
1818 1805
 	cID := strings.TrimSpace(out1)
1819
-	cmd = exec.Command(dockerBinary, "diff", cID)
1820
-	baseDiff, _, err := runCommandWithOutput(cmd)
1821
-	if err != nil {
1822
-		c.Fatal(err, baseDiff)
1823
-	}
1806
+
1807
+	baseDiff, _ := dockerCmd(c, "diff", cID)
1824 1808
 	baseArr := strings.Split(baseDiff, "\n")
1825 1809
 	sort.Strings(baseArr)
1826 1810
 	outArr := strings.Split(out, "\n")
... ...
@@ -1845,23 +1493,12 @@ func sliceEq(a, b []string) bool {
1845 1845
 // Test for #2267
1846 1846
 func (s *DockerSuite) TestRunWriteHostnameFileAndNotCommit(c *check.C) {
1847 1847
 	name := "writehostname"
1848
-	cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hostname && cat /etc/hostname")
1849
-	out, _, err := runCommandWithOutput(cmd)
1850
-	if err != nil {
1851
-		c.Fatal(err, out)
1852
-	}
1848
+	out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hostname && cat /etc/hostname")
1853 1849
 	if !strings.Contains(out, "test2267") {
1854 1850
 		c.Fatal("/etc/hostname should contain 'test2267'")
1855 1851
 	}
1856 1852
 
1857
-	cmd = exec.Command(dockerBinary, "diff", name)
1858
-	if err != nil {
1859
-		c.Fatal(err, out)
1860
-	}
1861
-	out, _, err = runCommandWithOutput(cmd)
1862
-	if err != nil {
1863
-		c.Fatal(err, out)
1864
-	}
1853
+	out, _ = dockerCmd(c, "diff", name)
1865 1854
 	if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, c) {
1866 1855
 		c.Fatal("diff should be empty")
1867 1856
 	}
... ...
@@ -1870,23 +1507,12 @@ func (s *DockerSuite) TestRunWriteHostnameFileAndNotCommit(c *check.C) {
1870 1870
 // Test for #2267
1871 1871
 func (s *DockerSuite) TestRunWriteResolvFileAndNotCommit(c *check.C) {
1872 1872
 	name := "writeresolv"
1873
-	cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/resolv.conf && cat /etc/resolv.conf")
1874
-	out, _, err := runCommandWithOutput(cmd)
1875
-	if err != nil {
1876
-		c.Fatal(err, out)
1877
-	}
1873
+	out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/resolv.conf && cat /etc/resolv.conf")
1878 1874
 	if !strings.Contains(out, "test2267") {
1879 1875
 		c.Fatal("/etc/resolv.conf should contain 'test2267'")
1880 1876
 	}
1881 1877
 
1882
-	cmd = exec.Command(dockerBinary, "diff", name)
1883
-	if err != nil {
1884
-		c.Fatal(err, out)
1885
-	}
1886
-	out, _, err = runCommandWithOutput(cmd)
1887
-	if err != nil {
1888
-		c.Fatal(err, out)
1889
-	}
1878
+	out, _ = dockerCmd(c, "diff", name)
1890 1879
 	if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, c) {
1891 1880
 		c.Fatal("diff should be empty")
1892 1881
 	}
... ...
@@ -1894,8 +1520,8 @@ func (s *DockerSuite) TestRunWriteResolvFileAndNotCommit(c *check.C) {
1894 1894
 
1895 1895
 func (s *DockerSuite) TestRunWithBadDevice(c *check.C) {
1896 1896
 	name := "baddevice"
1897
-	cmd := exec.Command(dockerBinary, "run", "--name", name, "--device", "/etc", "busybox", "true")
1898
-	out, _, err := runCommandWithOutput(cmd)
1897
+	out, _, err := dockerCmdWithError(c, "run", "--name", name, "--device", "/etc", "busybox", "true")
1898
+
1899 1899
 	if err == nil {
1900 1900
 		c.Fatal("Run should fail with bad device")
1901 1901
 	}
... ...
@@ -1907,11 +1533,8 @@ func (s *DockerSuite) TestRunWithBadDevice(c *check.C) {
1907 1907
 
1908 1908
 func (s *DockerSuite) TestRunEntrypoint(c *check.C) {
1909 1909
 	name := "entrypoint"
1910
-	cmd := exec.Command(dockerBinary, "run", "--name", name, "--entrypoint", "/bin/echo", "busybox", "-n", "foobar")
1911
-	out, _, err := runCommandWithOutput(cmd)
1912
-	if err != nil {
1913
-		c.Fatal(err, out)
1914
-	}
1910
+	out, _ := dockerCmd(c, "run", "--name", name, "--entrypoint", "/bin/echo", "busybox", "-n", "foobar")
1911
+
1915 1912
 	expected := "foobar"
1916 1913
 	if out != expected {
1917 1914
 		c.Fatalf("Output should be %q, actual out: %q", expected, out)
... ...
@@ -1930,36 +1553,24 @@ func (s *DockerSuite) TestRunBindMounts(c *check.C) {
1930 1930
 	writeFile(path.Join(tmpDir, "touch-me"), "", c)
1931 1931
 
1932 1932
 	// Test reading from a read-only bind mount
1933
-	cmd := exec.Command(dockerBinary, "run", "-v", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox", "ls", "/tmp")
1934
-	out, _, err := runCommandWithOutput(cmd)
1935
-	if err != nil {
1936
-		c.Fatal(err, out)
1937
-	}
1933
+	out, _ := dockerCmd(c, "run", "-v", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox", "ls", "/tmp")
1938 1934
 	if !strings.Contains(out, "touch-me") {
1939 1935
 		c.Fatal("Container failed to read from bind mount")
1940 1936
 	}
1941 1937
 
1942 1938
 	// test writing to bind mount
1943
-	cmd = exec.Command(dockerBinary, "run", "-v", fmt.Sprintf("%s:/tmp:rw", tmpDir), "busybox", "touch", "/tmp/holla")
1944
-	out, _, err = runCommandWithOutput(cmd)
1945
-	if err != nil {
1946
-		c.Fatal(err, out)
1947
-	}
1939
+	dockerCmd(c, "run", "-v", fmt.Sprintf("%s:/tmp:rw", tmpDir), "busybox", "touch", "/tmp/holla")
1940
+
1948 1941
 	readFile(path.Join(tmpDir, "holla"), c) // Will fail if the file doesn't exist
1949 1942
 
1950 1943
 	// test mounting to an illegal destination directory
1951
-	cmd = exec.Command(dockerBinary, "run", "-v", fmt.Sprintf("%s:.", tmpDir), "busybox", "ls", ".")
1952
-	_, err = runCommand(cmd)
1944
+	_, _, err = dockerCmdWithError(c, "run", "-v", fmt.Sprintf("%s:.", tmpDir), "busybox", "ls", ".")
1953 1945
 	if err == nil {
1954 1946
 		c.Fatal("Container bind mounted illegal directory")
1955 1947
 	}
1956 1948
 
1957 1949
 	// test mount a file
1958
-	cmd = exec.Command(dockerBinary, "run", "-v", fmt.Sprintf("%s/holla:/tmp/holla:rw", tmpDir), "busybox", "sh", "-c", "echo -n 'yotta' > /tmp/holla")
1959
-	_, err = runCommand(cmd)
1960
-	if err != nil {
1961
-		c.Fatal(err, out)
1962
-	}
1950
+	dockerCmd(c, "run", "-v", fmt.Sprintf("%s/holla:/tmp/holla:rw", tmpDir), "busybox", "sh", "-c", "echo -n 'yotta' > /tmp/holla")
1963 1951
 	content := readFile(path.Join(tmpDir, "holla"), c) // Will fail if the file doesn't exist
1964 1952
 	expected := "yotta"
1965 1953
 	if content != expected {
... ...
@@ -1976,8 +1587,8 @@ func (s *DockerSuite) TestRunCidFileCleanupIfEmpty(c *check.C) {
1976 1976
 	}
1977 1977
 	defer os.RemoveAll(tmpDir)
1978 1978
 	tmpCidFile := path.Join(tmpDir, "cid")
1979
-	cmd := exec.Command(dockerBinary, "run", "--cidfile", tmpCidFile, "emptyfs")
1980
-	out, _, err := runCommandWithOutput(cmd)
1979
+
1980
+	out, _, err := dockerCmdWithError(c, "run", "--cidfile", tmpCidFile, "emptyfs")
1981 1981
 	if err == nil {
1982 1982
 		c.Fatalf("Run without command must fail. out=%s", out)
1983 1983
 	} else if !strings.Contains(out, "No command specified") {
... ...
@@ -1999,11 +1610,9 @@ func (s *DockerSuite) TestRunCidFileCheckIDLength(c *check.C) {
1999 1999
 	}
2000 2000
 	tmpCidFile := path.Join(tmpDir, "cid")
2001 2001
 	defer os.RemoveAll(tmpDir)
2002
-	cmd := exec.Command(dockerBinary, "run", "-d", "--cidfile", tmpCidFile, "busybox", "true")
2003
-	out, _, err := runCommandWithOutput(cmd)
2004
-	if err != nil {
2005
-		c.Fatal(err)
2006
-	}
2002
+
2003
+	out, _ := dockerCmd(c, "run", "-d", "--cidfile", tmpCidFile, "busybox", "true")
2004
+
2007 2005
 	id := strings.TrimSpace(out)
2008 2006
 	buffer, err := ioutil.ReadFile(tmpCidFile)
2009 2007
 	if err != nil {
... ...
@@ -2021,11 +1630,8 @@ func (s *DockerSuite) TestRunCidFileCheckIDLength(c *check.C) {
2021 2021
 func (s *DockerSuite) TestRunSetMacAddress(c *check.C) {
2022 2022
 	mac := "12:34:56:78:9a:bc"
2023 2023
 
2024
-	cmd := exec.Command(dockerBinary, "run", "-i", "--rm", fmt.Sprintf("--mac-address=%s", mac), "busybox", "/bin/sh", "-c", "ip link show eth0 | tail -1 | awk '{print $2}'")
2025
-	out, ec, err := runCommandWithOutput(cmd)
2026
-	if err != nil {
2027
-		c.Fatalf("exec failed:\nexit code=%v\noutput=%s", ec, out)
2028
-	}
2024
+	out, _ := dockerCmd(c, "run", "-i", "--rm", fmt.Sprintf("--mac-address=%s", mac), "busybox", "/bin/sh", "-c", "ip link show eth0 | tail -1 | awk '{print $2}'")
2025
+
2029 2026
 	actualMac := strings.TrimSpace(out)
2030 2027
 	if actualMac != mac {
2031 2028
 		c.Fatalf("Set MAC address with --mac-address failed. The container has an incorrect MAC address: %q, expected: %q", actualMac, mac)
... ...
@@ -2034,11 +1640,8 @@ func (s *DockerSuite) TestRunSetMacAddress(c *check.C) {
2034 2034
 
2035 2035
 func (s *DockerSuite) TestRunInspectMacAddress(c *check.C) {
2036 2036
 	mac := "12:34:56:78:9a:bc"
2037
-	cmd := exec.Command(dockerBinary, "run", "-d", "--mac-address="+mac, "busybox", "top")
2038
-	out, _, err := runCommandWithOutput(cmd)
2039
-	if err != nil {
2040
-		c.Fatal(err)
2041
-	}
2037
+	out, _ := dockerCmd(c, "run", "-d", "--mac-address="+mac, "busybox", "top")
2038
+
2042 2039
 	id := strings.TrimSpace(out)
2043 2040
 	inspectedMac, err := inspectField(id, "NetworkSettings.MacAddress")
2044 2041
 	c.Assert(err, check.IsNil)
... ...
@@ -2049,8 +1652,7 @@ func (s *DockerSuite) TestRunInspectMacAddress(c *check.C) {
2049 2049
 
2050 2050
 // test docker run use a invalid mac address
2051 2051
 func (s *DockerSuite) TestRunWithInvalidMacAddress(c *check.C) {
2052
-	runCmd := exec.Command(dockerBinary, "run", "--mac-address", "92:d0:c6:0a:29", "busybox")
2053
-	out, _, err := runCommandWithOutput(runCmd)
2052
+	out, _, err := dockerCmdWithError(c, "run", "--mac-address", "92:d0:c6:0a:29", "busybox")
2054 2053
 	//use a invalid mac address should with a error out
2055 2054
 	if err == nil || !strings.Contains(out, "is not a valid mac address") {
2056 2055
 		c.Fatalf("run with an invalid --mac-address should with error out")
... ...
@@ -2060,11 +1662,8 @@ func (s *DockerSuite) TestRunWithInvalidMacAddress(c *check.C) {
2060 2060
 func (s *DockerSuite) TestRunDeallocatePortOnMissingIptablesRule(c *check.C) {
2061 2061
 	testRequires(c, SameHostDaemon)
2062 2062
 
2063
-	cmd := exec.Command(dockerBinary, "run", "-d", "-p", "23:23", "busybox", "top")
2064
-	out, _, err := runCommandWithOutput(cmd)
2065
-	if err != nil {
2066
-		c.Fatal(err)
2067
-	}
2063
+	out, _ := dockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top")
2064
+
2068 2065
 	id := strings.TrimSpace(out)
2069 2066
 	ip, err := inspectField(id, "NetworkSettings.IPAddress")
2070 2067
 	c.Assert(err, check.IsNil)
... ...
@@ -2077,25 +1676,17 @@ func (s *DockerSuite) TestRunDeallocatePortOnMissingIptablesRule(c *check.C) {
2077 2077
 	if err := deleteContainer(id); err != nil {
2078 2078
 		c.Fatal(err)
2079 2079
 	}
2080
-	cmd = exec.Command(dockerBinary, "run", "-d", "-p", "23:23", "busybox", "top")
2081
-	out, _, err = runCommandWithOutput(cmd)
2082
-	if err != nil {
2083
-		c.Fatal(err, out)
2084
-	}
2080
+
2081
+	dockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top")
2085 2082
 }
2086 2083
 
2087 2084
 func (s *DockerSuite) TestRunPortInUse(c *check.C) {
2088 2085
 	testRequires(c, SameHostDaemon)
2089 2086
 
2090 2087
 	port := "1234"
2091
-	cmd := exec.Command(dockerBinary, "run", "-d", "-p", port+":80", "busybox", "top")
2092
-	out, _, err := runCommandWithOutput(cmd)
2093
-	if err != nil {
2094
-		c.Fatalf("Fail to run listening container")
2095
-	}
2088
+	dockerCmd(c, "run", "-d", "-p", port+":80", "busybox", "top")
2096 2089
 
2097
-	cmd = exec.Command(dockerBinary, "run", "-d", "-p", port+":80", "busybox", "top")
2098
-	out, _, err = runCommandWithOutput(cmd)
2090
+	out, _, err := dockerCmdWithError(c, "run", "-d", "-p", port+":80", "busybox", "top")
2099 2091
 	if err == nil {
2100 2092
 		c.Fatalf("Binding on used port must fail")
2101 2093
 	}
... ...
@@ -2107,18 +1698,11 @@ func (s *DockerSuite) TestRunPortInUse(c *check.C) {
2107 2107
 // https://github.com/docker/docker/issues/12148
2108 2108
 func (s *DockerSuite) TestRunAllocatePortInReservedRange(c *check.C) {
2109 2109
 	// allocate a dynamic port to get the most recent
2110
-	cmd := exec.Command(dockerBinary, "run", "-d", "-P", "-p", "80", "busybox", "top")
2111
-	out, _, err := runCommandWithOutput(cmd)
2112
-	if err != nil {
2113
-		c.Fatalf("Failed to run, output: %s, error: %s", out, err)
2114
-	}
2110
+	out, _ := dockerCmd(c, "run", "-d", "-P", "-p", "80", "busybox", "top")
2111
+
2115 2112
 	id := strings.TrimSpace(out)
2113
+	out, _ = dockerCmd(c, "port", id, "80")
2116 2114
 
2117
-	cmd = exec.Command(dockerBinary, "port", id, "80")
2118
-	out, _, err = runCommandWithOutput(cmd)
2119
-	if err != nil {
2120
-		c.Fatalf("Failed to get port, output: %s, error: %s", out, err)
2121
-	}
2122 2115
 	strPort := strings.Split(strings.TrimSpace(out), ":")[1]
2123 2116
 	port, err := strconv.ParseInt(strPort, 10, 64)
2124 2117
 	if err != nil {
... ...
@@ -2127,14 +1711,7 @@ func (s *DockerSuite) TestRunAllocatePortInReservedRange(c *check.C) {
2127 2127
 
2128 2128
 	// allocate a static port and a dynamic port together, with static port
2129 2129
 	// takes the next recent port in dynamic port range.
2130
-	cmd = exec.Command(dockerBinary, "run", "-d", "-P",
2131
-		"-p", "80",
2132
-		"-p", fmt.Sprintf("%d:8080", port+1),
2133
-		"busybox", "top")
2134
-	out, _, err = runCommandWithOutput(cmd)
2135
-	if err != nil {
2136
-		c.Fatalf("Failed to run, output: %s, error: %s", out, err)
2137
-	}
2130
+	dockerCmd(c, "run", "-d", "-P", "-p", "80", "-p", fmt.Sprintf("%d:8080", port+1), "busybox", "top")
2138 2131
 }
2139 2132
 
2140 2133
 // Regression test for #7792
... ...
@@ -2171,17 +1748,13 @@ func (s *DockerSuite) TestRunMountOrdering(c *check.C) {
2171 2171
 		c.Fatal(err)
2172 2172
 	}
2173 2173
 
2174
-	cmd := exec.Command(dockerBinary, "run",
2174
+	dockerCmd(c, "run",
2175 2175
 		"-v", fmt.Sprintf("%s:/tmp", tmpDir),
2176 2176
 		"-v", fmt.Sprintf("%s:/tmp/foo", fooDir),
2177 2177
 		"-v", fmt.Sprintf("%s:/tmp/tmp2", tmpDir2),
2178 2178
 		"-v", fmt.Sprintf("%s:/tmp/tmp2/foo", fooDir),
2179 2179
 		"busybox:latest", "sh", "-c",
2180 2180
 		"ls /tmp/touch-me && ls /tmp/foo/touch-me && ls /tmp/tmp2/touch-me && ls /tmp/tmp2/foo/touch-me")
2181
-	out, _, err := runCommandWithOutput(cmd)
2182
-	if err != nil {
2183
-		c.Fatal(out, err)
2184
-	}
2185 2181
 }
2186 2182
 
2187 2183
 // Regression test for https://github.com/docker/docker/issues/8259
... ...
@@ -2201,44 +1774,26 @@ func (s *DockerSuite) TestRunReuseBindVolumeThatIsSymlink(c *check.C) {
2201 2201
 	defer os.RemoveAll(linkPath)
2202 2202
 
2203 2203
 	// Create first container
2204
-	cmd := exec.Command(dockerBinary, "run", "-v", fmt.Sprintf("%s:/tmp/test", linkPath), "busybox", "ls", "-lh", "/tmp/test")
2205
-	if _, err := runCommand(cmd); err != nil {
2206
-		c.Fatal(err)
2207
-	}
2204
+	dockerCmd(c, "run", "-v", fmt.Sprintf("%s:/tmp/test", linkPath), "busybox", "ls", "-lh", "/tmp/test")
2208 2205
 
2209 2206
 	// Create second container with same symlinked path
2210 2207
 	// This will fail if the referenced issue is hit with a "Volume exists" error
2211
-	cmd = exec.Command(dockerBinary, "run", "-v", fmt.Sprintf("%s:/tmp/test", linkPath), "busybox", "ls", "-lh", "/tmp/test")
2212
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
2213
-		c.Fatal(err, out)
2214
-	}
2208
+	dockerCmd(c, "run", "-v", fmt.Sprintf("%s:/tmp/test", linkPath), "busybox", "ls", "-lh", "/tmp/test")
2215 2209
 }
2216 2210
 
2217 2211
 //GH#10604: Test an "/etc" volume doesn't overlay special bind mounts in container
2218 2212
 func (s *DockerSuite) TestRunCreateVolumeEtc(c *check.C) {
2219
-	cmd := exec.Command(dockerBinary, "run", "--dns=127.0.0.1", "-v", "/etc", "busybox", "cat", "/etc/resolv.conf")
2220
-	out, _, err := runCommandWithOutput(cmd)
2221
-	if err != nil {
2222
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
2223
-	}
2213
+	out, _ := dockerCmd(c, "run", "--dns=127.0.0.1", "-v", "/etc", "busybox", "cat", "/etc/resolv.conf")
2224 2214
 	if !strings.Contains(out, "nameserver 127.0.0.1") {
2225 2215
 		c.Fatal("/etc volume mount hides /etc/resolv.conf")
2226 2216
 	}
2227 2217
 
2228
-	cmd = exec.Command(dockerBinary, "run", "-h=test123", "-v", "/etc", "busybox", "cat", "/etc/hostname")
2229
-	out, _, err = runCommandWithOutput(cmd)
2230
-	if err != nil {
2231
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
2232
-	}
2218
+	out, _ = dockerCmd(c, "run", "-h=test123", "-v", "/etc", "busybox", "cat", "/etc/hostname")
2233 2219
 	if !strings.Contains(out, "test123") {
2234 2220
 		c.Fatal("/etc volume mount hides /etc/hostname")
2235 2221
 	}
2236 2222
 
2237
-	cmd = exec.Command(dockerBinary, "run", "--add-host=test:192.168.0.1", "-v", "/etc", "busybox", "cat", "/etc/hosts")
2238
-	out, _, err = runCommandWithOutput(cmd)
2239
-	if err != nil {
2240
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
2241
-	}
2223
+	out, _ = dockerCmd(c, "run", "--add-host=test:192.168.0.1", "-v", "/etc", "busybox", "cat", "/etc/hosts")
2242 2224
 	out = strings.Replace(out, "\n", " ", -1)
2243 2225
 	if !strings.Contains(out, "192.168.0.1\ttest") || !strings.Contains(out, "127.0.0.1\tlocalhost") {
2244 2226
 		c.Fatal("/etc volume mount hides /etc/hosts")
... ...
@@ -2248,25 +1803,20 @@ func (s *DockerSuite) TestRunCreateVolumeEtc(c *check.C) {
2248 2248
 func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) {
2249 2249
 	if _, err := buildImage("dataimage",
2250 2250
 		`FROM busybox
2251
-		 RUN mkdir -p /foo
2252
-		 RUN touch /foo/bar`,
2251
+		RUN mkdir -p /foo
2252
+		RUN touch /foo/bar`,
2253 2253
 		true); err != nil {
2254 2254
 		c.Fatal(err)
2255 2255
 	}
2256 2256
 
2257
-	cmd := exec.Command(dockerBinary, "run", "--name", "test", "-v", "/foo", "busybox")
2258
-	if _, err := runCommand(cmd); err != nil {
2259
-		c.Fatal(err)
2260
-	}
2257
+	dockerCmd(c, "run", "--name", "test", "-v", "/foo", "busybox")
2261 2258
 
2262
-	cmd = exec.Command(dockerBinary, "run", "--volumes-from", "test", "dataimage", "ls", "-lh", "/foo/bar")
2263
-	if out, _, err := runCommandWithOutput(cmd); err == nil || !strings.Contains(out, "No such file or directory") {
2259
+	if out, _, err := dockerCmdWithError(c, "run", "--volumes-from", "test", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") {
2264 2260
 		c.Fatalf("Data was copied on volumes-from but shouldn't be:\n%q", out)
2265 2261
 	}
2266 2262
 
2267 2263
 	tmpDir := randomUnixTmpDirPath("docker_test_bind_mount_copy_data")
2268
-	cmd = exec.Command(dockerBinary, "run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar")
2269
-	if out, _, err := runCommandWithOutput(cmd); err == nil || !strings.Contains(out, "No such file or directory") {
2264
+	if out, _, err := dockerCmdWithError(c, "run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") {
2270 2265
 		c.Fatalf("Data was copied on bind-mount but shouldn't be:\n%q", out)
2271 2266
 	}
2272 2267
 }
... ...
@@ -2287,15 +1837,12 @@ func (s *DockerSuite) TestRunNoOutputFromPullInStdout(c *check.C) {
2287 2287
 func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) {
2288 2288
 	if _, err := buildImage("run_volumes_clean_paths",
2289 2289
 		`FROM busybox
2290
-		 VOLUME /foo/`,
2290
+		VOLUME /foo/`,
2291 2291
 		true); err != nil {
2292 2292
 		c.Fatal(err)
2293 2293
 	}
2294 2294
 
2295
-	cmd := exec.Command(dockerBinary, "run", "-v", "/foo", "-v", "/bar/", "--name", "dark_helmet", "run_volumes_clean_paths")
2296
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
2297
-		c.Fatal(err, out)
2298
-	}
2295
+	dockerCmd(c, "run", "-v", "/foo", "-v", "/bar/", "--name", "dark_helmet", "run_volumes_clean_paths")
2299 2296
 
2300 2297
 	out, err := inspectFieldMap("dark_helmet", "Volumes", "/foo/")
2301 2298
 	c.Assert(err, check.IsNil)
... ...
@@ -2345,11 +1892,8 @@ func (s *DockerSuite) TestRunSlowStdoutConsumer(c *check.C) {
2345 2345
 }
2346 2346
 
2347 2347
 func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) {
2348
-	cmd := exec.Command(dockerBinary, "run", "-d", "--expose", "3000-3003", "-P", "busybox", "top")
2349
-	out, _, err := runCommandWithOutput(cmd)
2350
-	if err != nil {
2351
-		c.Fatal(err)
2352
-	}
2348
+	out, _ := dockerCmd(c, "run", "-d", "--expose", "3000-3003", "-P", "busybox", "top")
2349
+
2353 2350
 	id := strings.TrimSpace(out)
2354 2351
 	portstr, err := inspectFieldJSON(id, "NetworkSettings.Ports")
2355 2352
 	c.Assert(err, check.IsNil)
... ...
@@ -2370,8 +1914,7 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) {
2370 2370
 
2371 2371
 // test docker run expose a invalid port
2372 2372
 func (s *DockerSuite) TestRunExposePort(c *check.C) {
2373
-	runCmd := exec.Command(dockerBinary, "run", "--expose", "80000", "busybox")
2374
-	out, _, err := runCommandWithOutput(runCmd)
2373
+	out, _, err := dockerCmdWithError(c, "run", "--expose", "80000", "busybox")
2375 2374
 	//expose a invalid port should with a error out
2376 2375
 	if err == nil || !strings.Contains(out, "Invalid range format for --expose") {
2377 2376
 		c.Fatalf("run --expose a invalid port should with error out")
... ...
@@ -2405,37 +1948,24 @@ func (s *DockerSuite) TestRunModeIpcHost(c *check.C) {
2405 2405
 		c.Fatal(err)
2406 2406
 	}
2407 2407
 
2408
-	cmd := exec.Command(dockerBinary, "run", "--ipc=host", "busybox", "readlink", "/proc/self/ns/ipc")
2409
-	out2, _, err := runCommandWithOutput(cmd)
2410
-	if err != nil {
2411
-		c.Fatal(err, out2)
2412
-	}
2413
-
2414
-	out2 = strings.Trim(out2, "\n")
2415
-	if hostIpc != out2 {
2416
-		c.Fatalf("IPC different with --ipc=host %s != %s\n", hostIpc, out2)
2417
-	}
2418
-
2419
-	cmd = exec.Command(dockerBinary, "run", "busybox", "readlink", "/proc/self/ns/ipc")
2420
-	out2, _, err = runCommandWithOutput(cmd)
2421
-	if err != nil {
2422
-		c.Fatal(err, out2)
2408
+	out, _ := dockerCmd(c, "run", "--ipc=host", "busybox", "readlink", "/proc/self/ns/ipc")
2409
+	out = strings.Trim(out, "\n")
2410
+	if hostIpc != out {
2411
+		c.Fatalf("IPC different with --ipc=host %s != %s\n", hostIpc, out)
2423 2412
 	}
2424 2413
 
2425
-	out2 = strings.Trim(out2, "\n")
2426
-	if hostIpc == out2 {
2427
-		c.Fatalf("IPC should be different without --ipc=host %s == %s\n", hostIpc, out2)
2414
+	out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/ipc")
2415
+	out = strings.Trim(out, "\n")
2416
+	if hostIpc == out {
2417
+		c.Fatalf("IPC should be different without --ipc=host %s == %s\n", hostIpc, out)
2428 2418
 	}
2429 2419
 }
2430 2420
 
2431 2421
 func (s *DockerSuite) TestRunModeIpcContainer(c *check.C) {
2432 2422
 	testRequires(c, SameHostDaemon)
2433 2423
 
2434
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
2435
-	out, _, err := runCommandWithOutput(cmd)
2436
-	if err != nil {
2437
-		c.Fatal(err, out)
2438
-	}
2424
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
2425
+
2439 2426
 	id := strings.TrimSpace(out)
2440 2427
 	state, err := inspectField(id, "State.Running")
2441 2428
 	c.Assert(err, check.IsNil)
... ...
@@ -2449,21 +1979,16 @@ func (s *DockerSuite) TestRunModeIpcContainer(c *check.C) {
2449 2449
 	if err != nil {
2450 2450
 		c.Fatal(err)
2451 2451
 	}
2452
-	cmd = exec.Command(dockerBinary, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "readlink", "/proc/self/ns/ipc")
2453
-	out2, _, err := runCommandWithOutput(cmd)
2454
-	if err != nil {
2455
-		c.Fatal(err, out2)
2456
-	}
2457 2452
 
2458
-	out2 = strings.Trim(out2, "\n")
2459
-	if parentContainerIpc != out2 {
2460
-		c.Fatalf("IPC different with --ipc=container:%s %s != %s\n", id, parentContainerIpc, out2)
2453
+	out, _ = dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "readlink", "/proc/self/ns/ipc")
2454
+	out = strings.Trim(out, "\n")
2455
+	if parentContainerIpc != out {
2456
+		c.Fatalf("IPC different with --ipc=container:%s %s != %s\n", id, parentContainerIpc, out)
2461 2457
 	}
2462 2458
 }
2463 2459
 
2464 2460
 func (s *DockerSuite) TestRunModeIpcContainerNotExists(c *check.C) {
2465
-	cmd := exec.Command(dockerBinary, "run", "-d", "--ipc", "container:abcd1234", "busybox", "top")
2466
-	out, _, err := runCommandWithOutput(cmd)
2461
+	out, _, err := dockerCmdWithError(c, "run", "-d", "--ipc", "container:abcd1234", "busybox", "top")
2467 2462
 	if !strings.Contains(out, "abcd1234") || err == nil {
2468 2463
 		c.Fatalf("run IPC from a non exists container should with correct error out")
2469 2464
 	}
... ...
@@ -2472,15 +1997,10 @@ func (s *DockerSuite) TestRunModeIpcContainerNotExists(c *check.C) {
2472 2472
 func (s *DockerSuite) TestRunModeIpcContainerNotRunning(c *check.C) {
2473 2473
 	testRequires(c, SameHostDaemon)
2474 2474
 
2475
-	cmd := exec.Command(dockerBinary, "create", "busybox")
2476
-	out, _, err := runCommandWithOutput(cmd)
2477
-	if err != nil {
2478
-		c.Fatal(err, out)
2479
-	}
2480
-	id := strings.TrimSpace(out)
2475
+	out, _ := dockerCmd(c, "create", "busybox")
2481 2476
 
2482
-	cmd = exec.Command(dockerBinary, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox")
2483
-	out, _, err = runCommandWithOutput(cmd)
2477
+	id := strings.TrimSpace(out)
2478
+	out, _, err := dockerCmdWithError(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox")
2484 2479
 	if err == nil {
2485 2480
 		c.Fatalf("Run container with ipc mode container should fail with non running container: %s\n%s", out, err)
2486 2481
 	}
... ...
@@ -2489,11 +2009,7 @@ func (s *DockerSuite) TestRunModeIpcContainerNotRunning(c *check.C) {
2489 2489
 func (s *DockerSuite) TestContainerNetworkMode(c *check.C) {
2490 2490
 	testRequires(c, SameHostDaemon)
2491 2491
 
2492
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
2493
-	out, _, err := runCommandWithOutput(cmd)
2494
-	if err != nil {
2495
-		c.Fatal(err, out)
2496
-	}
2492
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
2497 2493
 	id := strings.TrimSpace(out)
2498 2494
 	if err := waitRun(id); err != nil {
2499 2495
 		c.Fatal(err)
... ...
@@ -2505,15 +2021,11 @@ func (s *DockerSuite) TestContainerNetworkMode(c *check.C) {
2505 2505
 	if err != nil {
2506 2506
 		c.Fatal(err)
2507 2507
 	}
2508
-	cmd = exec.Command(dockerBinary, "run", fmt.Sprintf("--net=container:%s", id), "busybox", "readlink", "/proc/self/ns/net")
2509
-	out2, _, err := runCommandWithOutput(cmd)
2510
-	if err != nil {
2511
-		c.Fatal(err, out2)
2512
-	}
2513 2508
 
2514
-	out2 = strings.Trim(out2, "\n")
2515
-	if parentContainerNet != out2 {
2516
-		c.Fatalf("NET different with --net=container:%s %s != %s\n", id, parentContainerNet, out2)
2509
+	out, _ = dockerCmd(c, "run", fmt.Sprintf("--net=container:%s", id), "busybox", "readlink", "/proc/self/ns/net")
2510
+	out = strings.Trim(out, "\n")
2511
+	if parentContainerNet != out {
2512
+		c.Fatalf("NET different with --net=container:%s %s != %s\n", id, parentContainerNet, out)
2517 2513
 	}
2518 2514
 }
2519 2515
 
... ...
@@ -2525,26 +2037,16 @@ func (s *DockerSuite) TestRunModePidHost(c *check.C) {
2525 2525
 		c.Fatal(err)
2526 2526
 	}
2527 2527
 
2528
-	cmd := exec.Command(dockerBinary, "run", "--pid=host", "busybox", "readlink", "/proc/self/ns/pid")
2529
-	out2, _, err := runCommandWithOutput(cmd)
2530
-	if err != nil {
2531
-		c.Fatal(err, out2)
2532
-	}
2533
-
2534
-	out2 = strings.Trim(out2, "\n")
2535
-	if hostPid != out2 {
2536
-		c.Fatalf("PID different with --pid=host %s != %s\n", hostPid, out2)
2537
-	}
2538
-
2539
-	cmd = exec.Command(dockerBinary, "run", "busybox", "readlink", "/proc/self/ns/pid")
2540
-	out2, _, err = runCommandWithOutput(cmd)
2541
-	if err != nil {
2542
-		c.Fatal(err, out2)
2528
+	out, _ := dockerCmd(c, "run", "--pid=host", "busybox", "readlink", "/proc/self/ns/pid")
2529
+	out = strings.Trim(out, "\n")
2530
+	if hostPid != out {
2531
+		c.Fatalf("PID different with --pid=host %s != %s\n", hostPid, out)
2543 2532
 	}
2544 2533
 
2545
-	out2 = strings.Trim(out2, "\n")
2546
-	if hostPid == out2 {
2547
-		c.Fatalf("PID should be different without --pid=host %s == %s\n", hostPid, out2)
2534
+	out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/pid")
2535
+	out = strings.Trim(out, "\n")
2536
+	if hostPid == out {
2537
+		c.Fatalf("PID should be different without --pid=host %s == %s\n", hostPid, out)
2548 2538
 	}
2549 2539
 }
2550 2540
 
... ...
@@ -2556,67 +2058,45 @@ func (s *DockerSuite) TestRunModeUTSHost(c *check.C) {
2556 2556
 		c.Fatal(err)
2557 2557
 	}
2558 2558
 
2559
-	cmd := exec.Command(dockerBinary, "run", "--uts=host", "busybox", "readlink", "/proc/self/ns/uts")
2560
-	out2, _, err := runCommandWithOutput(cmd)
2561
-	if err != nil {
2562
-		c.Fatal(err, out2)
2563
-	}
2564
-
2565
-	out2 = strings.Trim(out2, "\n")
2566
-	if hostUTS != out2 {
2567
-		c.Fatalf("UTS different with --uts=host %s != %s\n", hostUTS, out2)
2568
-	}
2569
-
2570
-	cmd = exec.Command(dockerBinary, "run", "busybox", "readlink", "/proc/self/ns/uts")
2571
-	out2, _, err = runCommandWithOutput(cmd)
2572
-	if err != nil {
2573
-		c.Fatal(err, out2)
2559
+	out, _ := dockerCmd(c, "run", "--uts=host", "busybox", "readlink", "/proc/self/ns/uts")
2560
+	out = strings.Trim(out, "\n")
2561
+	if hostUTS != out {
2562
+		c.Fatalf("UTS different with --uts=host %s != %s\n", hostUTS, out)
2574 2563
 	}
2575 2564
 
2576
-	out2 = strings.Trim(out2, "\n")
2577
-	if hostUTS == out2 {
2578
-		c.Fatalf("UTS should be different without --uts=host %s == %s\n", hostUTS, out2)
2565
+	out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/uts")
2566
+	out = strings.Trim(out, "\n")
2567
+	if hostUTS == out {
2568
+		c.Fatalf("UTS should be different without --uts=host %s == %s\n", hostUTS, out)
2579 2569
 	}
2580 2570
 }
2581 2571
 
2582 2572
 func (s *DockerSuite) TestRunTLSverify(c *check.C) {
2583
-	cmd := exec.Command(dockerBinary, "ps")
2584
-	out, ec, err := runCommandWithOutput(cmd)
2585
-	if err != nil || ec != 0 {
2573
+	if out, code, err := dockerCmdWithError(c, "ps"); err != nil || code != 0 {
2586 2574
 		c.Fatalf("Should have worked: %v:\n%v", err, out)
2587 2575
 	}
2588 2576
 
2589 2577
 	// Regardless of whether we specify true or false we need to
2590 2578
 	// test to make sure tls is turned on if --tlsverify is specified at all
2591
-
2592
-	cmd = exec.Command(dockerBinary, "--tlsverify=false", "ps")
2593
-	out, ec, err = runCommandWithOutput(cmd)
2594
-	if err == nil || ec == 0 || !strings.Contains(out, "trying to connect") {
2595
-		c.Fatalf("Should have failed: \net:%v\nout:%v\nerr:%v", ec, out, err)
2579
+	out, code, err := dockerCmdWithError(c, "--tlsverify=false", "ps")
2580
+	if err == nil || code == 0 || !strings.Contains(out, "trying to connect") {
2581
+		c.Fatalf("Should have failed: \net:%v\nout:%v\nerr:%v", code, out, err)
2596 2582
 	}
2597 2583
 
2598
-	cmd = exec.Command(dockerBinary, "--tlsverify=true", "ps")
2599
-	out, ec, err = runCommandWithOutput(cmd)
2600
-	if err == nil || ec == 0 || !strings.Contains(out, "cert") {
2601
-		c.Fatalf("Should have failed: \net:%v\nout:%v\nerr:%v", ec, out, err)
2584
+	out, code, err = dockerCmdWithError(c, "--tlsverify=true", "ps")
2585
+	if err == nil || code == 0 || !strings.Contains(out, "cert") {
2586
+		c.Fatalf("Should have failed: \net:%v\nout:%v\nerr:%v", code, out, err)
2602 2587
 	}
2603 2588
 }
2604 2589
 
2605 2590
 func (s *DockerSuite) TestRunPortFromDockerRangeInUse(c *check.C) {
2606 2591
 	// first find allocator current position
2607
-	cmd := exec.Command(dockerBinary, "run", "-d", "-p", ":80", "busybox", "top")
2608
-	out, _, err := runCommandWithOutput(cmd)
2609
-	if err != nil {
2610
-		c.Fatal(out, err)
2611
-	}
2592
+	out, _ := dockerCmd(c, "run", "-d", "-p", ":80", "busybox", "top")
2593
+
2612 2594
 	id := strings.TrimSpace(out)
2613
-	cmd = exec.Command(dockerBinary, "port", id)
2614
-	out, _, err = runCommandWithOutput(cmd)
2615
-	if err != nil {
2616
-		c.Fatal(out, err)
2617
-	}
2618
-	out = strings.TrimSpace(out)
2595
+	out, _ = dockerCmd(c, "port", id)
2619 2596
 
2597
+	out = strings.TrimSpace(out)
2620 2598
 	if out == "" {
2621 2599
 		c.Fatal("docker port command output is empty")
2622 2600
 	}
... ...
@@ -2631,17 +2111,11 @@ func (s *DockerSuite) TestRunPortFromDockerRangeInUse(c *check.C) {
2631 2631
 		c.Fatal(err)
2632 2632
 	}
2633 2633
 	defer l.Close()
2634
-	cmd = exec.Command(dockerBinary, "run", "-d", "-p", ":80", "busybox", "top")
2635
-	out, _, err = runCommandWithOutput(cmd)
2636
-	if err != nil {
2637
-		c.Fatalf(out, err)
2638
-	}
2634
+
2635
+	out, _ = dockerCmd(c, "run", "-d", "-p", ":80", "busybox", "top")
2636
+
2639 2637
 	id = strings.TrimSpace(out)
2640
-	cmd = exec.Command(dockerBinary, "port", id)
2641
-	out, _, err = runCommandWithOutput(cmd)
2642
-	if err != nil {
2643
-		c.Fatal(out, err)
2644
-	}
2638
+	dockerCmd(c, "port", id)
2645 2639
 }
2646 2640
 
2647 2641
 func (s *DockerSuite) TestRunTtyWithPipe(c *check.C) {
... ...
@@ -2676,9 +2150,8 @@ func (s *DockerSuite) TestRunTtyWithPipe(c *check.C) {
2676 2676
 func (s *DockerSuite) TestRunNonLocalMacAddress(c *check.C) {
2677 2677
 	addr := "00:16:3E:08:00:50"
2678 2678
 
2679
-	cmd := exec.Command(dockerBinary, "run", "--mac-address", addr, "busybox", "ifconfig")
2680
-	if out, _, err := runCommandWithOutput(cmd); err != nil || !strings.Contains(out, addr) {
2681
-		c.Fatalf("Output should have contained %q: %s, %v", addr, out, err)
2679
+	if out, _ := dockerCmd(c, "run", "--mac-address", addr, "busybox", "ifconfig"); !strings.Contains(out, addr) {
2680
+		c.Fatalf("Output should have contained %q: %s", addr, out)
2682 2681
 	}
2683 2682
 }
2684 2683
 
... ...
@@ -2690,43 +2163,24 @@ func (s *DockerSuite) TestRunNetHost(c *check.C) {
2690 2690
 		c.Fatal(err)
2691 2691
 	}
2692 2692
 
2693
-	cmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "readlink", "/proc/self/ns/net")
2694
-	out2, _, err := runCommandWithOutput(cmd)
2695
-	if err != nil {
2696
-		c.Fatal(err, out2)
2697
-	}
2698
-
2699
-	out2 = strings.Trim(out2, "\n")
2700
-	if hostNet != out2 {
2701
-		c.Fatalf("Net namespace different with --net=host %s != %s\n", hostNet, out2)
2702
-	}
2703
-
2704
-	cmd = exec.Command(dockerBinary, "run", "busybox", "readlink", "/proc/self/ns/net")
2705
-	out2, _, err = runCommandWithOutput(cmd)
2706
-	if err != nil {
2707
-		c.Fatal(err, out2)
2693
+	out, _ := dockerCmd(c, "run", "--net=host", "busybox", "readlink", "/proc/self/ns/net")
2694
+	out = strings.Trim(out, "\n")
2695
+	if hostNet != out {
2696
+		c.Fatalf("Net namespace different with --net=host %s != %s\n", hostNet, out)
2708 2697
 	}
2709 2698
 
2710
-	out2 = strings.Trim(out2, "\n")
2711
-	if hostNet == out2 {
2712
-		c.Fatalf("Net namespace should be different without --net=host %s == %s\n", hostNet, out2)
2699
+	out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/net")
2700
+	out = strings.Trim(out, "\n")
2701
+	if hostNet == out {
2702
+		c.Fatalf("Net namespace should be different without --net=host %s == %s\n", hostNet, out)
2713 2703
 	}
2714 2704
 }
2715 2705
 
2716 2706
 func (s *DockerSuite) TestRunNetHostTwiceSameName(c *check.C) {
2717 2707
 	testRequires(c, SameHostDaemon)
2718 2708
 
2719
-	cmd := exec.Command(dockerBinary, "run", "--rm", "--name=thost", "--net=host", "busybox", "true")
2720
-	out2, _, err := runCommandWithOutput(cmd)
2721
-	if err != nil {
2722
-		c.Fatal(err, out2)
2723
-	}
2724
-
2725
-	cmd = exec.Command(dockerBinary, "run", "--rm", "--name=thost", "--net=host", "busybox", "true")
2726
-	out2, _, err = runCommandWithOutput(cmd)
2727
-	if err != nil {
2728
-		c.Fatal(err, out2)
2729
-	}
2709
+	dockerCmd(c, "run", "--rm", "--name=thost", "--net=host", "busybox", "true")
2710
+	dockerCmd(c, "run", "--rm", "--name=thost", "--net=host", "busybox", "true")
2730 2711
 }
2731 2712
 
2732 2713
 func (s *DockerSuite) TestRunNetContainerWhichHost(c *check.C) {
... ...
@@ -2737,18 +2191,9 @@ func (s *DockerSuite) TestRunNetContainerWhichHost(c *check.C) {
2737 2737
 		c.Fatal(err)
2738 2738
 	}
2739 2739
 
2740
-	cmd := exec.Command(dockerBinary, "run", "-d", "--net=host", "--name=test", "busybox", "top")
2741
-	out, _, err := runCommandWithOutput(cmd)
2742
-	if err != nil {
2743
-		c.Fatal(err, out)
2744
-	}
2745
-
2746
-	cmd = exec.Command(dockerBinary, "run", "--net=container:test", "busybox", "readlink", "/proc/self/ns/net")
2747
-	out, _, err = runCommandWithOutput(cmd)
2748
-	if err != nil {
2749
-		c.Fatal(err, out)
2750
-	}
2740
+	dockerCmd(c, "run", "-d", "--net=host", "--name=test", "busybox", "top")
2751 2741
 
2742
+	out, _ := dockerCmd(c, "run", "--net=container:test", "busybox", "readlink", "/proc/self/ns/net")
2752 2743
 	out = strings.Trim(out, "\n")
2753 2744
 	if hostNet != out {
2754 2745
 		c.Fatalf("Container should have host network namespace")
... ...
@@ -2756,12 +2201,12 @@ func (s *DockerSuite) TestRunNetContainerWhichHost(c *check.C) {
2756 2756
 }
2757 2757
 
2758 2758
 func (s *DockerSuite) TestRunAllowPortRangeThroughPublish(c *check.C) {
2759
-	cmd := exec.Command(dockerBinary, "run", "-d", "--expose", "3000-3003", "-p", "3000-3003", "busybox", "top")
2760
-	out, _, err := runCommandWithOutput(cmd)
2759
+	out, _ := dockerCmd(c, "run", "-d", "--expose", "3000-3003", "-p", "3000-3003", "busybox", "top")
2761 2760
 
2762 2761
 	id := strings.TrimSpace(out)
2763 2762
 	portstr, err := inspectFieldJSON(id, "NetworkSettings.Ports")
2764 2763
 	c.Assert(err, check.IsNil)
2764
+
2765 2765
 	var ports nat.PortMap
2766 2766
 	err = unmarshalJSON([]byte(portstr), &ports)
2767 2767
 	for port, binding := range ports {
... ...
@@ -2776,10 +2221,8 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughPublish(c *check.C) {
2776 2776
 }
2777 2777
 
2778 2778
 func (s *DockerSuite) TestRunSetDefaultRestartPolicy(c *check.C) {
2779
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "test", "busybox", "top")
2780
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
2781
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
2782
-	}
2779
+	dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
2780
+
2783 2781
 	out, err := inspectField("test", "HostConfig.RestartPolicy.Name")
2784 2782
 	c.Assert(err, check.IsNil)
2785 2783
 	if out != "no" {
... ...
@@ -2788,19 +2231,19 @@ func (s *DockerSuite) TestRunSetDefaultRestartPolicy(c *check.C) {
2788 2788
 }
2789 2789
 
2790 2790
 func (s *DockerSuite) TestRunRestartMaxRetries(c *check.C) {
2791
-	out, err := exec.Command(dockerBinary, "run", "-d", "--restart=on-failure:3", "busybox", "false").CombinedOutput()
2792
-	if err != nil {
2793
-		c.Fatal(string(out), err)
2794
-	}
2791
+	out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "false")
2792
+
2795 2793
 	id := strings.TrimSpace(string(out))
2796 2794
 	if err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false false", 10); err != nil {
2797 2795
 		c.Fatal(err)
2798 2796
 	}
2797
+
2799 2798
 	count, err := inspectField(id, "RestartCount")
2800 2799
 	c.Assert(err, check.IsNil)
2801 2800
 	if count != "3" {
2802 2801
 		c.Fatalf("Container was restarted %s times, expected %d", count, 3)
2803 2802
 	}
2803
+
2804 2804
 	MaximumRetryCount, err := inspectField(id, "HostConfig.RestartPolicy.MaximumRetryCount")
2805 2805
 	c.Assert(err, check.IsNil)
2806 2806
 	if MaximumRetryCount != "3" {
... ...
@@ -2809,10 +2252,7 @@ func (s *DockerSuite) TestRunRestartMaxRetries(c *check.C) {
2809 2809
 }
2810 2810
 
2811 2811
 func (s *DockerSuite) TestRunContainerWithWritableRootfs(c *check.C) {
2812
-	out, err := exec.Command(dockerBinary, "run", "--rm", "busybox", "touch", "/file").CombinedOutput()
2813
-	if err != nil {
2814
-		c.Fatal(string(out), err)
2815
-	}
2812
+	dockerCmd(c, "run", "--rm", "busybox", "touch", "/file")
2816 2813
 }
2817 2814
 
2818 2815
 func (s *DockerSuite) TestRunContainerWithReadonlyRootfs(c *check.C) {
... ...
@@ -2840,7 +2280,7 @@ func (s *DockerSuite) TestPermissionsPtsReadonlyRootfs(c *check.C) {
2840 2840
 func testReadOnlyFile(filename string, c *check.C) {
2841 2841
 	testRequires(c, NativeExecDriver)
2842 2842
 
2843
-	out, err := exec.Command(dockerBinary, "run", "--read-only", "--rm", "busybox", "touch", filename).CombinedOutput()
2843
+	out, _, err := dockerCmdWithError(c, "run", "--read-only", "--rm", "busybox", "touch", filename)
2844 2844
 	if err == nil {
2845 2845
 		c.Fatal("expected container to error on run with read only error")
2846 2846
 	}
... ...
@@ -2849,7 +2289,7 @@ func testReadOnlyFile(filename string, c *check.C) {
2849 2849
 		c.Fatalf("expected output from failure to contain %s but contains %s", expected, out)
2850 2850
 	}
2851 2851
 
2852
-	out, err = exec.Command(dockerBinary, "run", "--read-only", "--privileged", "--rm", "busybox", "touch", filename).CombinedOutput()
2852
+	out, _, err = dockerCmdWithError(c, "run", "--read-only", "--privileged", "--rm", "busybox", "touch", filename)
2853 2853
 	if err == nil {
2854 2854
 		c.Fatal("expected container to error on run with read only error")
2855 2855
 	}
... ...
@@ -2862,12 +2302,9 @@ func testReadOnlyFile(filename string, c *check.C) {
2862 2862
 func (s *DockerSuite) TestRunContainerWithReadonlyEtcHostsAndLinkedContainer(c *check.C) {
2863 2863
 	testRequires(c, NativeExecDriver)
2864 2864
 
2865
-	_, err := runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "test-etc-hosts-ro-linked", "busybox", "top"))
2866
-	c.Assert(err, check.IsNil)
2867
-
2868
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--read-only", "--link", "test-etc-hosts-ro-linked:testlinked", "busybox", "cat", "/etc/hosts"))
2869
-	c.Assert(err, check.IsNil)
2865
+	dockerCmd(c, "run", "-d", "--name", "test-etc-hosts-ro-linked", "busybox", "top")
2870 2866
 
2867
+	out, _ := dockerCmd(c, "run", "--read-only", "--link", "test-etc-hosts-ro-linked:testlinked", "busybox", "cat", "/etc/hosts")
2871 2868
 	if !strings.Contains(string(out), "testlinked") {
2872 2869
 		c.Fatal("Expected /etc/hosts to be updated even if --read-only enabled")
2873 2870
 	}
... ...
@@ -2876,9 +2313,7 @@ func (s *DockerSuite) TestRunContainerWithReadonlyEtcHostsAndLinkedContainer(c *
2876 2876
 func (s *DockerSuite) TestRunContainerWithReadonlyRootfsWithDnsFlag(c *check.C) {
2877 2877
 	testRequires(c, NativeExecDriver)
2878 2878
 
2879
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--read-only", "--dns", "1.1.1.1", "busybox", "/bin/cat", "/etc/resolv.conf"))
2880
-	c.Assert(err, check.IsNil)
2881
-
2879
+	out, _ := dockerCmd(c, "run", "--read-only", "--dns", "1.1.1.1", "busybox", "/bin/cat", "/etc/resolv.conf")
2882 2880
 	if !strings.Contains(string(out), "1.1.1.1") {
2883 2881
 		c.Fatal("Expected /etc/resolv.conf to be updated even if --read-only enabled and --dns flag used")
2884 2882
 	}
... ...
@@ -2887,43 +2322,27 @@ func (s *DockerSuite) TestRunContainerWithReadonlyRootfsWithDnsFlag(c *check.C)
2887 2887
 func (s *DockerSuite) TestRunContainerWithReadonlyRootfsWithAddHostFlag(c *check.C) {
2888 2888
 	testRequires(c, NativeExecDriver)
2889 2889
 
2890
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--read-only", "--add-host", "testreadonly:127.0.0.1", "busybox", "/bin/cat", "/etc/hosts"))
2891
-	c.Assert(err, check.IsNil)
2892
-
2890
+	out, _ := dockerCmd(c, "run", "--read-only", "--add-host", "testreadonly:127.0.0.1", "busybox", "/bin/cat", "/etc/hosts")
2893 2891
 	if !strings.Contains(string(out), "testreadonly") {
2894 2892
 		c.Fatal("Expected /etc/hosts to be updated even if --read-only enabled and --add-host flag used")
2895 2893
 	}
2896 2894
 }
2897 2895
 
2898 2896
 func (s *DockerSuite) TestRunVolumesFromRestartAfterRemoved(c *check.C) {
2899
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "voltest", "-v", "/foo", "busybox"))
2900
-	if err != nil {
2901
-		c.Fatal(out, err)
2902
-	}
2903
-
2904
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "restarter", "--volumes-from", "voltest", "busybox", "top"))
2905
-	if err != nil {
2906
-		c.Fatal(out, err)
2907
-	}
2897
+	dockerCmd(c, "run", "-d", "--name", "voltest", "-v", "/foo", "busybox")
2898
+	dockerCmd(c, "run", "-d", "--name", "restarter", "--volumes-from", "voltest", "busybox", "top")
2908 2899
 
2909 2900
 	// Remove the main volume container and restart the consuming container
2910
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "rm", "-f", "voltest"))
2911
-	if err != nil {
2912
-		c.Fatal(out, err)
2913
-	}
2901
+	dockerCmd(c, "rm", "-f", "voltest")
2914 2902
 
2915 2903
 	// This should not fail since the volumes-from were already applied
2916
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "restart", "restarter"))
2917
-	if err != nil {
2918
-		c.Fatalf("expected container to restart successfully: %v\n%s", err, out)
2919
-	}
2904
+	dockerCmd(c, "restart", "restarter")
2920 2905
 }
2921 2906
 
2922 2907
 // run container with --rm should remove container if exit code != 0
2923 2908
 func (s *DockerSuite) TestRunContainerWithRmFlagExitCodeNotEqualToZero(c *check.C) {
2924 2909
 	name := "flowers"
2925
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "--rm", "busybox", "ls", "/notexists")
2926
-	out, _, err := runCommandWithOutput(runCmd)
2910
+	out, _, err := dockerCmdWithError(c, "run", "--name", name, "--rm", "busybox", "ls", "/notexists")
2927 2911
 	if err == nil {
2928 2912
 		c.Fatal("Expected docker run to fail", out, err)
2929 2913
 	}
... ...
@@ -2940,8 +2359,7 @@ func (s *DockerSuite) TestRunContainerWithRmFlagExitCodeNotEqualToZero(c *check.
2940 2940
 
2941 2941
 func (s *DockerSuite) TestRunContainerWithRmFlagCannotStartContainer(c *check.C) {
2942 2942
 	name := "sparkles"
2943
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "--rm", "busybox", "commandNotFound")
2944
-	out, _, err := runCommandWithOutput(runCmd)
2943
+	out, _, err := dockerCmdWithError(c, "run", "--name", name, "--rm", "busybox", "commandNotFound")
2945 2944
 	if err == nil {
2946 2945
 		c.Fatal("Expected docker run to fail", out, err)
2947 2946
 	}
... ...
@@ -2958,13 +2376,12 @@ func (s *DockerSuite) TestRunContainerWithRmFlagCannotStartContainer(c *check.C)
2958 2958
 
2959 2959
 func (s *DockerSuite) TestRunPidHostWithChildIsKillable(c *check.C) {
2960 2960
 	name := "ibuildthecloud"
2961
-	if out, err := exec.Command(dockerBinary, "run", "-d", "--pid=host", "--name", name, "busybox", "sh", "-c", "sleep 30; echo hi").CombinedOutput(); err != nil {
2962
-		c.Fatal(err, out)
2963
-	}
2961
+	dockerCmd(c, "run", "-d", "--pid=host", "--name", name, "busybox", "sh", "-c", "sleep 30; echo hi")
2962
+
2964 2963
 	time.Sleep(1 * time.Second)
2965 2964
 	errchan := make(chan error)
2966 2965
 	go func() {
2967
-		if out, err := exec.Command(dockerBinary, "kill", name).CombinedOutput(); err != nil {
2966
+		if out, _, err := dockerCmdWithError(c, "kill", name); err != nil {
2968 2967
 			errchan <- fmt.Errorf("%v:\n%s", err, out)
2969 2968
 		}
2970 2969
 		close(errchan)
... ...
@@ -2980,14 +2397,14 @@ func (s *DockerSuite) TestRunPidHostWithChildIsKillable(c *check.C) {
2980 2980
 func (s *DockerSuite) TestRunWithTooSmallMemoryLimit(c *check.C) {
2981 2981
 	// this memory limit is 1 byte less than the min, which is 4MB
2982 2982
 	// https://github.com/docker/docker/blob/v1.5.0/daemon/create.go#L22
2983
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-m", "4194303", "busybox"))
2983
+	out, _, err := dockerCmdWithError(c, "run", "-m", "4194303", "busybox")
2984 2984
 	if err == nil || !strings.Contains(out, "Minimum memory limit allowed is 4MB") {
2985 2985
 		c.Fatalf("expected run to fail when using too low a memory limit: %q", out)
2986 2986
 	}
2987 2987
 }
2988 2988
 
2989 2989
 func (s *DockerSuite) TestRunWriteToProcAsound(c *check.C) {
2990
-	code, err := runCommand(exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "echo 111 >> /proc/asound/version"))
2990
+	_, code, err := dockerCmdWithError(c, "run", "busybox", "sh", "-c", "echo 111 >> /proc/asound/version")
2991 2991
 	if err == nil || code == 0 {
2992 2992
 		c.Fatal("standard container should not be able to write to /proc/asound")
2993 2993
 	}
... ...
@@ -2995,7 +2412,7 @@ func (s *DockerSuite) TestRunWriteToProcAsound(c *check.C) {
2995 2995
 
2996 2996
 func (s *DockerSuite) TestRunReadProcTimer(c *check.C) {
2997 2997
 	testRequires(c, NativeExecDriver)
2998
-	out, code, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "busybox", "cat", "/proc/timer_stats"))
2998
+	out, code, err := dockerCmdWithError(c, "run", "busybox", "cat", "/proc/timer_stats")
2999 2999
 	if err != nil || code != 0 {
3000 3000
 		c.Fatal(err)
3001 3001
 	}
... ...
@@ -3012,7 +2429,7 @@ func (s *DockerSuite) TestRunReadProcLatency(c *check.C) {
3012 3012
 		c.Skip("kernel doesnt have latency_stats configured")
3013 3013
 		return
3014 3014
 	}
3015
-	out, code, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "busybox", "cat", "/proc/latency_stats"))
3015
+	out, code, err := dockerCmdWithError(c, "run", "busybox", "cat", "/proc/latency_stats")
3016 3016
 	if err != nil || code != 0 {
3017 3017
 		c.Fatal(err)
3018 3018
 	}
... ...
@@ -3023,7 +2440,7 @@ func (s *DockerSuite) TestRunReadProcLatency(c *check.C) {
3023 3023
 
3024 3024
 func (s *DockerSuite) TestMountIntoProc(c *check.C) {
3025 3025
 	testRequires(c, NativeExecDriver)
3026
-	code, err := runCommand(exec.Command(dockerBinary, "run", "-v", "/proc//sys", "busybox", "true"))
3026
+	_, code, err := dockerCmdWithError(c, "run", "-v", "/proc//sys", "busybox", "true")
3027 3027
 	if err == nil || code == 0 {
3028 3028
 		c.Fatal("container should not be able to mount into /proc")
3029 3029
 	}
... ...
@@ -3031,40 +2448,32 @@ func (s *DockerSuite) TestMountIntoProc(c *check.C) {
3031 3031
 
3032 3032
 func (s *DockerSuite) TestMountIntoSys(c *check.C) {
3033 3033
 	testRequires(c, NativeExecDriver)
3034
-	_, err := runCommand(exec.Command(dockerBinary, "run", "-v", "/sys/fs/cgroup", "busybox", "true"))
3035
-	if err != nil {
3036
-		c.Fatal("container should be able to mount into /sys/fs/cgroup")
3037
-	}
3034
+	dockerCmd(c, "run", "-v", "/sys/fs/cgroup", "busybox", "true")
3038 3035
 }
3039 3036
 
3040 3037
 func (s *DockerSuite) TestRunUnshareProc(c *check.C) {
3041 3038
 	testRequires(c, Apparmor, NativeExecDriver)
3042 3039
 
3043 3040
 	name := "acidburn"
3044
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount")
3045
-	if out, _, err := runCommandWithOutput(runCmd); err == nil || !strings.Contains(out, "Permission denied") {
3041
+	if out, _, err := dockerCmdWithError(c, "run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount"); err == nil || !strings.Contains(out, "Permission denied") {
3046 3042
 		c.Fatalf("unshare should have failed with permission denied, got: %s, %v", out, err)
3047 3043
 	}
3048 3044
 
3049 3045
 	name = "cereal"
3050
-	runCmd = exec.Command(dockerBinary, "run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc")
3051
-	if out, _, err := runCommandWithOutput(runCmd); err == nil || !strings.Contains(out, "Permission denied") {
3046
+	if out, _, err := dockerCmdWithError(c, "run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc"); err == nil || !strings.Contains(out, "Permission denied") {
3052 3047
 		c.Fatalf("unshare should have failed with permission denied, got: %s, %v", out, err)
3053 3048
 	}
3054 3049
 
3055 3050
 	/* Ensure still fails if running privileged with the default policy */
3056 3051
 	name = "crashoverride"
3057
-	runCmd = exec.Command(dockerBinary, "run", "--privileged", "--security-opt", "apparmor:docker-default", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc")
3058
-	if out, _, err := runCommandWithOutput(runCmd); err == nil || !strings.Contains(out, "Permission denied") {
3052
+	if out, _, err := dockerCmdWithError(c, "run", "--privileged", "--security-opt", "apparmor:docker-default", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc"); err == nil || !strings.Contains(out, "Permission denied") {
3059 3053
 		c.Fatalf("unshare should have failed with permission denied, got: %s, %v", out, err)
3060 3054
 	}
3061 3055
 }
3062 3056
 
3063 3057
 func (s *DockerSuite) TestRunPublishPort(c *check.C) {
3064
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "test", "--expose", "8080", "busybox", "top"))
3065
-	c.Assert(err, check.IsNil)
3066
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "port", "test"))
3067
-	c.Assert(err, check.IsNil)
3058
+	dockerCmd(c, "run", "-d", "--name", "test", "--expose", "8080", "busybox", "top")
3059
+	out, _ := dockerCmd(c, "port", "test")
3068 3060
 	out = strings.Trim(out, "\r\n")
3069 3061
 	if out != "" {
3070 3062
 		c.Fatalf("run without --publish-all should not publish port, out should be nil, but got: %s", out)
... ...
@@ -3085,11 +2494,7 @@ func (s *DockerSuite) TestDevicePermissions(c *check.C) {
3085 3085
 }
3086 3086
 
3087 3087
 func (s *DockerSuite) TestRunCapAddCHOWN(c *check.C) {
3088
-	cmd := exec.Command(dockerBinary, "run", "--cap-drop=ALL", "--cap-add=CHOWN", "busybox", "sh", "-c", "adduser -D -H newuser && chown newuser /home && echo ok")
3089
-	out, _, err := runCommandWithOutput(cmd)
3090
-	if err != nil {
3091
-		c.Fatal(err, out)
3092
-	}
3088
+	out, _ := dockerCmd(c, "run", "--cap-drop=ALL", "--cap-add=CHOWN", "busybox", "sh", "-c", "adduser -D -H newuser && chown newuser /home && echo ok")
3093 3089
 
3094 3090
 	if actual := strings.Trim(out, "\r\n"); actual != "ok" {
3095 3091
 		c.Fatalf("expected output ok received %s", actual)