docker_cli_ps_test.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "sort"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "github.com/docker/docker/pkg/integration/checker"
  13. icmd "github.com/docker/docker/pkg/integration/cmd"
  14. "github.com/docker/docker/pkg/stringid"
  15. "github.com/go-check/check"
  16. )
  17. func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
  18. out, _ := runSleepingContainer(c, "-d")
  19. firstID := strings.TrimSpace(out)
  20. out, _ = runSleepingContainer(c, "-d")
  21. secondID := strings.TrimSpace(out)
  22. // not long running
  23. out, _ = dockerCmd(c, "run", "-d", "busybox", "true")
  24. thirdID := strings.TrimSpace(out)
  25. out, _ = runSleepingContainer(c, "-d")
  26. fourthID := strings.TrimSpace(out)
  27. // make sure the second is running
  28. c.Assert(waitRun(secondID), checker.IsNil)
  29. // make sure third one is not running
  30. dockerCmd(c, "wait", thirdID)
  31. // make sure the forth is running
  32. c.Assert(waitRun(fourthID), checker.IsNil)
  33. // all
  34. out, _ = dockerCmd(c, "ps", "-a")
  35. c.Assert(assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}), checker.Equals, true, check.Commentf("ALL: Container list is not in the correct order: \n%s", out))
  36. // running
  37. out, _ = dockerCmd(c, "ps")
  38. c.Assert(assertContainerList(out, []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
  39. // limit
  40. out, _ = dockerCmd(c, "ps", "-n=2", "-a")
  41. expected := []string{fourthID, thirdID}
  42. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
  43. out, _ = dockerCmd(c, "ps", "-n=2")
  44. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out))
  45. // filter since
  46. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-a")
  47. expected = []string{fourthID, thirdID, secondID}
  48. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
  49. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID)
  50. expected = []string{fourthID, secondID}
  51. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
  52. out, _ = dockerCmd(c, "ps", "-f", "since="+thirdID)
  53. expected = []string{fourthID}
  54. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
  55. // filter before
  56. out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-a")
  57. expected = []string{thirdID, secondID, firstID}
  58. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
  59. out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID)
  60. expected = []string{secondID, firstID}
  61. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
  62. out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID)
  63. expected = []string{secondID, firstID}
  64. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
  65. // filter since & before
  66. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-a")
  67. expected = []string{thirdID, secondID}
  68. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
  69. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID)
  70. expected = []string{secondID}
  71. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
  72. // filter since & limit
  73. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2", "-a")
  74. expected = []string{fourthID, thirdID}
  75. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
  76. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2")
  77. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
  78. // filter before & limit
  79. out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1", "-a")
  80. expected = []string{thirdID}
  81. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
  82. out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1")
  83. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
  84. // filter since & filter before & limit
  85. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1", "-a")
  86. expected = []string{thirdID}
  87. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
  88. out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1")
  89. c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
  90. }
  91. func assertContainerList(out string, expected []string) bool {
  92. lines := strings.Split(strings.Trim(out, "\n "), "\n")
  93. if len(lines)-1 != len(expected) {
  94. return false
  95. }
  96. containerIDIndex := strings.Index(lines[0], "CONTAINER ID")
  97. for i := 0; i < len(expected); i++ {
  98. foundID := lines[i+1][containerIDIndex : containerIDIndex+12]
  99. if foundID != expected[i][:12] {
  100. return false
  101. }
  102. }
  103. return true
  104. }
  105. // FIXME(vdemeester) Move this into a unit test in daemon package
  106. func (s *DockerSuite) TestPsListContainersInvalidFilterName(c *check.C) {
  107. out, _, err := dockerCmdWithError("ps", "-f", "invalidFilter=test")
  108. c.Assert(err, checker.NotNil)
  109. c.Assert(out, checker.Contains, "Invalid filter")
  110. }
  111. func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
  112. // Problematic on Windows as it doesn't report the size correctly @swernli
  113. testRequires(c, DaemonIsLinux)
  114. dockerCmd(c, "run", "-d", "busybox")
  115. baseOut, _ := dockerCmd(c, "ps", "-s", "-n=1")
  116. baseLines := strings.Split(strings.Trim(baseOut, "\n "), "\n")
  117. baseSizeIndex := strings.Index(baseLines[0], "SIZE")
  118. baseFoundsize := baseLines[1][baseSizeIndex:]
  119. baseBytes, err := strconv.Atoi(strings.Split(baseFoundsize, " ")[0])
  120. c.Assert(err, checker.IsNil)
  121. name := "test_size"
  122. dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
  123. id, err := getIDByName(name)
  124. c.Assert(err, checker.IsNil)
  125. runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1")
  126. var out string
  127. wait := make(chan struct{})
  128. go func() {
  129. out, _, err = runCommandWithOutput(runCmd)
  130. close(wait)
  131. }()
  132. select {
  133. case <-wait:
  134. case <-time.After(3 * time.Second):
  135. c.Fatalf("Calling \"docker ps -s\" timed out!")
  136. }
  137. c.Assert(err, checker.IsNil)
  138. lines := strings.Split(strings.Trim(out, "\n "), "\n")
  139. c.Assert(lines, checker.HasLen, 2, check.Commentf("Expected 2 lines for 'ps -s -n=1' output, got %d", len(lines)))
  140. sizeIndex := strings.Index(lines[0], "SIZE")
  141. idIndex := strings.Index(lines[0], "CONTAINER ID")
  142. foundID := lines[1][idIndex : idIndex+12]
  143. c.Assert(foundID, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s", id[:12], foundID))
  144. expectedSize := fmt.Sprintf("%d B", (2 + baseBytes))
  145. foundSize := lines[1][sizeIndex:]
  146. c.Assert(foundSize, checker.Contains, expectedSize, check.Commentf("Expected size %q, got %q", expectedSize, foundSize))
  147. }
  148. func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
  149. // start exited container
  150. out, _ := dockerCmd(c, "run", "-d", "busybox")
  151. firstID := strings.TrimSpace(out)
  152. // make sure the exited container is not running
  153. dockerCmd(c, "wait", firstID)
  154. // start running container
  155. out, _ = dockerCmd(c, "run", "-itd", "busybox")
  156. secondID := strings.TrimSpace(out)
  157. // filter containers by exited
  158. out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=exited")
  159. containerOut := strings.TrimSpace(out)
  160. c.Assert(containerOut, checker.Equals, firstID)
  161. out, _ = dockerCmd(c, "ps", "-a", "--no-trunc", "-q", "--filter=status=running")
  162. containerOut = strings.TrimSpace(out)
  163. c.Assert(containerOut, checker.Equals, secondID)
  164. result := dockerCmdWithTimeout(time.Second*60, "ps", "-a", "-q", "--filter=status=rubbish")
  165. c.Assert(result, icmd.Matches, icmd.Expected{
  166. ExitCode: 1,
  167. Err: "Unrecognised filter value for status",
  168. })
  169. // Windows doesn't support pausing of containers
  170. if daemonPlatform != "windows" {
  171. // pause running container
  172. out, _ = dockerCmd(c, "run", "-itd", "busybox")
  173. pausedID := strings.TrimSpace(out)
  174. dockerCmd(c, "pause", pausedID)
  175. // make sure the container is unpaused to let the daemon stop it properly
  176. defer func() { dockerCmd(c, "unpause", pausedID) }()
  177. out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused")
  178. containerOut = strings.TrimSpace(out)
  179. c.Assert(containerOut, checker.Equals, pausedID)
  180. }
  181. }
  182. func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
  183. // Test legacy no health check
  184. out, _ := runSleepingContainer(c, "--name=none_legacy")
  185. containerID := strings.TrimSpace(out)
  186. waitForContainer(containerID)
  187. out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none")
  188. containerOut := strings.TrimSpace(out)
  189. c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out))
  190. // Test no health check specified explicitly
  191. out, _ = runSleepingContainer(c, "--name=none", "--no-healthcheck")
  192. containerID = strings.TrimSpace(out)
  193. waitForContainer(containerID)
  194. out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none")
  195. containerOut = strings.TrimSpace(out)
  196. c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out))
  197. // Test failing health check
  198. out, _ = runSleepingContainer(c, "--name=failing_container", "--health-cmd=exit 1", "--health-interval=1s")
  199. containerID = strings.TrimSpace(out)
  200. waitForHealthStatus(c, "failing_container", "starting", "unhealthy")
  201. out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy")
  202. containerOut = strings.TrimSpace(out)
  203. c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out))
  204. // Check passing healthcheck
  205. out, _ = runSleepingContainer(c, "--name=passing_container", "--health-cmd=exit 0", "--health-interval=1s")
  206. containerID = strings.TrimSpace(out)
  207. waitForHealthStatus(c, "passing_container", "starting", "healthy")
  208. out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy")
  209. containerOut = strings.TrimSpace(out)
  210. c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
  211. }
  212. func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
  213. // start container
  214. out, _ := dockerCmd(c, "run", "-d", "busybox")
  215. firstID := strings.TrimSpace(out)
  216. // start another container
  217. runSleepingContainer(c)
  218. // filter containers by id
  219. out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
  220. containerOut := strings.TrimSpace(out)
  221. c.Assert(containerOut, checker.Equals, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
  222. }
  223. func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
  224. // start container
  225. dockerCmd(c, "run", "--name=a_name_to_match", "busybox")
  226. id, err := getIDByName("a_name_to_match")
  227. c.Assert(err, check.IsNil)
  228. // start another container
  229. runSleepingContainer(c, "--name=b_name_to_match")
  230. // filter containers by name
  231. out, _ := dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
  232. containerOut := strings.TrimSpace(out)
  233. c.Assert(containerOut, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", id[:12], containerOut, out))
  234. }
  235. // Test for the ancestor filter for ps.
  236. // There is also the same test but with image:tag@digest in docker_cli_by_digest_test.go
  237. //
  238. // What the test setups :
  239. // - Create 2 image based on busybox using the same repository but different tags
  240. // - Create an image based on the previous image (images_ps_filter_test2)
  241. // - Run containers for each of those image (busybox, images_ps_filter_test1, images_ps_filter_test2)
  242. // - Filter them out :P
  243. func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
  244. // Build images
  245. imageName1 := "images_ps_filter_test1"
  246. imageID1, err := buildImage(imageName1,
  247. `FROM busybox
  248. LABEL match me 1`, true)
  249. c.Assert(err, checker.IsNil)
  250. imageName1Tagged := "images_ps_filter_test1:tag"
  251. imageID1Tagged, err := buildImage(imageName1Tagged,
  252. `FROM busybox
  253. LABEL match me 1 tagged`, true)
  254. c.Assert(err, checker.IsNil)
  255. imageName2 := "images_ps_filter_test2"
  256. imageID2, err := buildImage(imageName2,
  257. fmt.Sprintf(`FROM %s
  258. LABEL match me 2`, imageName1), true)
  259. c.Assert(err, checker.IsNil)
  260. // start containers
  261. dockerCmd(c, "run", "--name=first", "busybox", "echo", "hello")
  262. firstID, err := getIDByName("first")
  263. c.Assert(err, check.IsNil)
  264. // start another container
  265. dockerCmd(c, "run", "--name=second", "busybox", "echo", "hello")
  266. secondID, err := getIDByName("second")
  267. c.Assert(err, check.IsNil)
  268. // start third container
  269. dockerCmd(c, "run", "--name=third", imageName1, "echo", "hello")
  270. thirdID, err := getIDByName("third")
  271. c.Assert(err, check.IsNil)
  272. // start fourth container
  273. dockerCmd(c, "run", "--name=fourth", imageName1Tagged, "echo", "hello")
  274. fourthID, err := getIDByName("fourth")
  275. c.Assert(err, check.IsNil)
  276. // start fifth container
  277. dockerCmd(c, "run", "--name=fifth", imageName2, "echo", "hello")
  278. fifthID, err := getIDByName("fifth")
  279. c.Assert(err, check.IsNil)
  280. var filterTestSuite = []struct {
  281. filterName string
  282. expectedIDs []string
  283. }{
  284. // non existent stuff
  285. {"nonexistent", []string{}},
  286. {"nonexistent:tag", []string{}},
  287. // image
  288. {"busybox", []string{firstID, secondID, thirdID, fourthID, fifthID}},
  289. {imageName1, []string{thirdID, fifthID}},
  290. {imageName2, []string{fifthID}},
  291. // image:tag
  292. {fmt.Sprintf("%s:latest", imageName1), []string{thirdID, fifthID}},
  293. {imageName1Tagged, []string{fourthID}},
  294. // short-id
  295. {stringid.TruncateID(imageID1), []string{thirdID, fifthID}},
  296. {stringid.TruncateID(imageID2), []string{fifthID}},
  297. // full-id
  298. {imageID1, []string{thirdID, fifthID}},
  299. {imageID1Tagged, []string{fourthID}},
  300. {imageID2, []string{fifthID}},
  301. }
  302. var out string
  303. for _, filter := range filterTestSuite {
  304. out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+filter.filterName)
  305. checkPsAncestorFilterOutput(c, out, filter.filterName, filter.expectedIDs)
  306. }
  307. // Multiple ancestor filter
  308. out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageName2, "--filter=ancestor="+imageName1Tagged)
  309. checkPsAncestorFilterOutput(c, out, imageName2+","+imageName1Tagged, []string{fourthID, fifthID})
  310. }
  311. func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expectedIDs []string) {
  312. actualIDs := []string{}
  313. if out != "" {
  314. actualIDs = strings.Split(out[:len(out)-1], "\n")
  315. }
  316. sort.Strings(actualIDs)
  317. sort.Strings(expectedIDs)
  318. c.Assert(actualIDs, checker.HasLen, len(expectedIDs), check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs))
  319. if len(expectedIDs) > 0 {
  320. same := true
  321. for i := range expectedIDs {
  322. if actualIDs[i] != expectedIDs[i] {
  323. c.Logf("%s, %s", actualIDs[i], expectedIDs[i])
  324. same = false
  325. break
  326. }
  327. }
  328. c.Assert(same, checker.Equals, true, check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
  329. }
  330. }
  331. func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
  332. // start container
  333. dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox")
  334. firstID, err := getIDByName("first")
  335. c.Assert(err, check.IsNil)
  336. // start another container
  337. dockerCmd(c, "run", "--name=second", "-l", "match=me too", "busybox")
  338. secondID, err := getIDByName("second")
  339. c.Assert(err, check.IsNil)
  340. // start third container
  341. dockerCmd(c, "run", "--name=third", "-l", "nomatch=me", "busybox")
  342. thirdID, err := getIDByName("third")
  343. c.Assert(err, check.IsNil)
  344. // filter containers by exact match
  345. out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
  346. containerOut := strings.TrimSpace(out)
  347. c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
  348. // filter containers by two labels
  349. out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
  350. containerOut = strings.TrimSpace(out)
  351. c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
  352. // filter containers by two labels, but expect not found because of AND behavior
  353. out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
  354. containerOut = strings.TrimSpace(out)
  355. c.Assert(containerOut, checker.Equals, "", check.Commentf("Expected nothing, got %s for exited filter, output: %q", containerOut, out))
  356. // filter containers by exact key
  357. out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
  358. containerOut = strings.TrimSpace(out)
  359. c.Assert(containerOut, checker.Contains, firstID)
  360. c.Assert(containerOut, checker.Contains, secondID)
  361. c.Assert(containerOut, checker.Not(checker.Contains), thirdID)
  362. }
  363. func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
  364. runSleepingContainer(c, "--name=sleep")
  365. dockerCmd(c, "run", "--name", "zero1", "busybox", "true")
  366. firstZero, err := getIDByName("zero1")
  367. c.Assert(err, checker.IsNil)
  368. dockerCmd(c, "run", "--name", "zero2", "busybox", "true")
  369. secondZero, err := getIDByName("zero2")
  370. c.Assert(err, checker.IsNil)
  371. out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
  372. c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
  373. firstNonZero, err := getIDByName("nonzero1")
  374. c.Assert(err, checker.IsNil)
  375. out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
  376. c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
  377. secondNonZero, err := getIDByName("nonzero2")
  378. c.Assert(err, checker.IsNil)
  379. // filter containers by exited=0
  380. out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
  381. ids := strings.Split(strings.TrimSpace(out), "\n")
  382. c.Assert(ids, checker.HasLen, 2, check.Commentf("Should be 2 zero exited containers got %d: %s", len(ids), out))
  383. c.Assert(ids[0], checker.Equals, secondZero, check.Commentf("First in list should be %q, got %q", secondZero, ids[0]))
  384. c.Assert(ids[1], checker.Equals, firstZero, check.Commentf("Second in list should be %q, got %q", firstZero, ids[1]))
  385. out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
  386. ids = strings.Split(strings.TrimSpace(out), "\n")
  387. c.Assert(ids, checker.HasLen, 2, check.Commentf("Should be 2 zero exited containers got %d", len(ids)))
  388. c.Assert(ids[0], checker.Equals, secondNonZero, check.Commentf("First in list should be %q, got %q", secondNonZero, ids[0]))
  389. c.Assert(ids[1], checker.Equals, firstNonZero, check.Commentf("Second in list should be %q, got %q", firstNonZero, ids[1]))
  390. }
  391. func (s *DockerSuite) TestPsRightTagName(c *check.C) {
  392. // TODO Investigate further why this fails on Windows to Windows CI
  393. testRequires(c, DaemonIsLinux)
  394. tag := "asybox:shmatest"
  395. dockerCmd(c, "tag", "busybox", tag)
  396. var id1 string
  397. out, _ := runSleepingContainer(c)
  398. id1 = strings.TrimSpace(string(out))
  399. var id2 string
  400. out, _ = runSleepingContainerInImage(c, tag)
  401. id2 = strings.TrimSpace(string(out))
  402. var imageID string
  403. out = inspectField(c, "busybox", "Id")
  404. imageID = strings.TrimSpace(string(out))
  405. var id3 string
  406. out, _ = runSleepingContainerInImage(c, imageID)
  407. id3 = strings.TrimSpace(string(out))
  408. out, _ = dockerCmd(c, "ps", "--no-trunc")
  409. lines := strings.Split(strings.TrimSpace(string(out)), "\n")
  410. // skip header
  411. lines = lines[1:]
  412. c.Assert(lines, checker.HasLen, 3, check.Commentf("There should be 3 running container, got %d", len(lines)))
  413. for _, line := range lines {
  414. f := strings.Fields(line)
  415. switch f[0] {
  416. case id1:
  417. c.Assert(f[1], checker.Equals, "busybox", check.Commentf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
  418. case id2:
  419. c.Assert(f[1], checker.Equals, tag, check.Commentf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
  420. case id3:
  421. c.Assert(f[1], checker.Equals, imageID, check.Commentf("Expected %s imageID for id %s, got %s", tag, id3, f[1]))
  422. default:
  423. c.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3)
  424. }
  425. }
  426. }
  427. func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
  428. // Problematic on Windows as it doesn't support links as of Jan 2016
  429. testRequires(c, DaemonIsLinux)
  430. runSleepingContainer(c, "--name=first")
  431. runSleepingContainer(c, "--name=second", "--link=first:first")
  432. out, _ := dockerCmd(c, "ps", "--no-trunc")
  433. lines := strings.Split(strings.TrimSpace(string(out)), "\n")
  434. // strip header
  435. lines = lines[1:]
  436. expected := []string{"second", "first,second/first"}
  437. var names []string
  438. for _, l := range lines {
  439. fields := strings.Fields(l)
  440. names = append(names, fields[len(fields)-1])
  441. }
  442. c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array: %v, got: %v", expected, names))
  443. }
  444. func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
  445. // Problematic on Windows as it doesn't support port ranges as of Jan 2016
  446. testRequires(c, DaemonIsLinux)
  447. portRange := "3850-3900"
  448. dockerCmd(c, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top")
  449. out, _ := dockerCmd(c, "ps")
  450. c.Assert(string(out), checker.Contains, portRange, check.Commentf("docker ps output should have had the port range %q: %s", portRange, string(out)))
  451. }
  452. func (s *DockerSuite) TestPsWithSize(c *check.C) {
  453. // Problematic on Windows as it doesn't report the size correctly @swernli
  454. testRequires(c, DaemonIsLinux)
  455. dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top")
  456. out, _ := dockerCmd(c, "ps", "--size")
  457. c.Assert(out, checker.Contains, "virtual", check.Commentf("docker ps with --size should show virtual size of container"))
  458. }
  459. func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
  460. // create a container
  461. out, _ := dockerCmd(c, "create", "busybox")
  462. cID := strings.TrimSpace(out)
  463. shortCID := cID[:12]
  464. // Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
  465. out, _ = dockerCmd(c, "ps", "-q")
  466. c.Assert(out, checker.Not(checker.Contains), shortCID, check.Commentf("Should have not seen '%s' in ps output:\n%s", shortCID, out))
  467. // Make sure it DOES show up as 'Created' for 'ps -a'
  468. out, _ = dockerCmd(c, "ps", "-a")
  469. hits := 0
  470. for _, line := range strings.Split(out, "\n") {
  471. if !strings.Contains(line, shortCID) {
  472. continue
  473. }
  474. hits++
  475. c.Assert(line, checker.Contains, "Created", check.Commentf("Missing 'Created' on '%s'", line))
  476. }
  477. c.Assert(hits, checker.Equals, 1, check.Commentf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out))
  478. // filter containers by 'create' - note, no -a needed
  479. out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created")
  480. containerOut := strings.TrimSpace(out)
  481. c.Assert(cID, checker.HasPrefix, containerOut)
  482. }
  483. func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
  484. // Problematic on Windows as it doesn't support link as of Jan 2016
  485. testRequires(c, DaemonIsLinux)
  486. //create 2 containers and link them
  487. dockerCmd(c, "run", "--name=child", "-d", "busybox", "top")
  488. dockerCmd(c, "run", "--name=parent", "--link=child:linkedone", "-d", "busybox", "top")
  489. //use the new format capabilities to only list the names and --no-trunc to get all names
  490. out, _ := dockerCmd(c, "ps", "--format", "{{.Names}}", "--no-trunc")
  491. lines := strings.Split(strings.TrimSpace(string(out)), "\n")
  492. expected := []string{"parent", "child,parent/linkedone"}
  493. var names []string
  494. names = append(names, lines...)
  495. c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with non-truncated names: %v, got: %v", expected, names))
  496. //now list without turning off truncation and make sure we only get the non-link names
  497. out, _ = dockerCmd(c, "ps", "--format", "{{.Names}}")
  498. lines = strings.Split(strings.TrimSpace(string(out)), "\n")
  499. expected = []string{"parent", "child"}
  500. var truncNames []string
  501. truncNames = append(truncNames, lines...)
  502. c.Assert(expected, checker.DeepEquals, truncNames, check.Commentf("Expected array with truncated names: %v, got: %v", expected, truncNames))
  503. }
  504. // Test for GitHub issue #21772
  505. func (s *DockerSuite) TestPsNamesMultipleTime(c *check.C) {
  506. runSleepingContainer(c, "--name=test1")
  507. runSleepingContainer(c, "--name=test2")
  508. //use the new format capabilities to list the names twice
  509. out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Names}}")
  510. lines := strings.Split(strings.TrimSpace(string(out)), "\n")
  511. expected := []string{"test2 test2", "test1 test1"}
  512. var names []string
  513. names = append(names, lines...)
  514. c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with names displayed twice: %v, got: %v", expected, names))
  515. }
  516. func (s *DockerSuite) TestPsFormatHeaders(c *check.C) {
  517. // make sure no-container "docker ps" still prints the header row
  518. out, _ := dockerCmd(c, "ps", "--format", "table {{.ID}}")
  519. c.Assert(out, checker.Equals, "CONTAINER ID\n", check.Commentf(`Expected 'CONTAINER ID\n', got %v`, out))
  520. // verify that "docker ps" with a container still prints the header row also
  521. runSleepingContainer(c, "--name=test")
  522. out, _ = dockerCmd(c, "ps", "--format", "table {{.Names}}")
  523. c.Assert(out, checker.Equals, "NAMES\ntest\n", check.Commentf(`Expected 'NAMES\ntest\n', got %v`, out))
  524. }
  525. func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
  526. config := `{
  527. "psFormat": "default {{ .ID }}"
  528. }`
  529. d, err := ioutil.TempDir("", "integration-cli-")
  530. c.Assert(err, checker.IsNil)
  531. defer os.RemoveAll(d)
  532. err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644)
  533. c.Assert(err, checker.IsNil)
  534. out, _ := runSleepingContainer(c, "--name=test")
  535. id := strings.TrimSpace(out)
  536. out, _ = dockerCmd(c, "--config", d, "ps", "-q")
  537. c.Assert(id, checker.HasPrefix, strings.TrimSpace(out), check.Commentf("Expected to print only the container id, got %v\n", out))
  538. }
  539. // Test for GitHub issue #12595
  540. func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
  541. // TODO: Investigate why this fails on Windows to Windows CI further.
  542. testRequires(c, DaemonIsLinux)
  543. originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
  544. updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated"
  545. runCmd := exec.Command(dockerBinary, "tag", "busybox:latest", originalImageName)
  546. out, _, err := runCommandWithOutput(runCmd)
  547. c.Assert(err, checker.IsNil)
  548. originalImageID, err := getIDByName(originalImageName)
  549. c.Assert(err, checker.IsNil)
  550. runCmd = exec.Command(dockerBinary, append([]string{"run", "-d", originalImageName}, sleepCommandForDaemonPlatform()...)...)
  551. out, _, err = runCommandWithOutput(runCmd)
  552. c.Assert(err, checker.IsNil)
  553. containerID := strings.TrimSpace(out)
  554. linesOut, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
  555. c.Assert(err, checker.IsNil)
  556. lines := strings.Split(strings.TrimSpace(string(linesOut)), "\n")
  557. // skip header
  558. lines = lines[1:]
  559. c.Assert(len(lines), checker.Equals, 1)
  560. for _, line := range lines {
  561. f := strings.Fields(line)
  562. c.Assert(f[1], checker.Equals, originalImageName)
  563. }
  564. runCmd = exec.Command(dockerBinary, "commit", containerID, updatedImageName)
  565. out, _, err = runCommandWithOutput(runCmd)
  566. c.Assert(err, checker.IsNil)
  567. runCmd = exec.Command(dockerBinary, "tag", updatedImageName, originalImageName)
  568. out, _, err = runCommandWithOutput(runCmd)
  569. c.Assert(err, checker.IsNil)
  570. linesOut, err = exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
  571. c.Assert(err, checker.IsNil)
  572. lines = strings.Split(strings.TrimSpace(string(linesOut)), "\n")
  573. // skip header
  574. lines = lines[1:]
  575. c.Assert(len(lines), checker.Equals, 1)
  576. for _, line := range lines {
  577. f := strings.Fields(line)
  578. c.Assert(f[1], checker.Equals, originalImageID)
  579. }
  580. }
  581. func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) {
  582. testRequires(c, DaemonIsLinux)
  583. dockerCmd(c, "run", "--name=foo", "-d", "-p", "5000:5000", "busybox", "top")
  584. c.Assert(waitRun("foo"), checker.IsNil)
  585. out, _ := dockerCmd(c, "ps")
  586. lines := strings.Split(strings.TrimSpace(string(out)), "\n")
  587. expected := "0.0.0.0:5000->5000/tcp"
  588. fields := strings.Fields(lines[1])
  589. c.Assert(fields[len(fields)-2], checker.Equals, expected, check.Commentf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
  590. dockerCmd(c, "kill", "foo")
  591. dockerCmd(c, "wait", "foo")
  592. out, _ = dockerCmd(c, "ps", "-l")
  593. lines = strings.Split(strings.TrimSpace(string(out)), "\n")
  594. fields = strings.Fields(lines[1])
  595. c.Assert(fields[len(fields)-2], checker.Not(checker.Equals), expected, check.Commentf("Should not got %v", expected))
  596. }
  597. func (s *DockerSuite) TestPsShowMounts(c *check.C) {
  598. prefix, slash := getPrefixAndSlashFromDaemonPlatform()
  599. mp := prefix + slash + "test"
  600. dockerCmd(c, "volume", "create", "ps-volume-test")
  601. // volume mount containers
  602. runSleepingContainer(c, "--name=volume-test-1", "--volume", "ps-volume-test:"+mp)
  603. c.Assert(waitRun("volume-test-1"), checker.IsNil)
  604. runSleepingContainer(c, "--name=volume-test-2", "--volume", mp)
  605. c.Assert(waitRun("volume-test-2"), checker.IsNil)
  606. // bind mount container
  607. var bindMountSource string
  608. var bindMountDestination string
  609. if DaemonIsWindows.Condition() {
  610. bindMountSource = "c:\\"
  611. bindMountDestination = "c:\\t"
  612. } else {
  613. bindMountSource = "/tmp"
  614. bindMountDestination = "/t"
  615. }
  616. runSleepingContainer(c, "--name=bind-mount-test", "-v", bindMountSource+":"+bindMountDestination)
  617. c.Assert(waitRun("bind-mount-test"), checker.IsNil)
  618. out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}")
  619. lines := strings.Split(strings.TrimSpace(string(out)), "\n")
  620. c.Assert(lines, checker.HasLen, 3)
  621. fields := strings.Fields(lines[0])
  622. c.Assert(fields, checker.HasLen, 2)
  623. c.Assert(fields[0], checker.Equals, "bind-mount-test")
  624. c.Assert(fields[1], checker.Equals, bindMountSource)
  625. fields = strings.Fields(lines[1])
  626. c.Assert(fields, checker.HasLen, 2)
  627. annonymounsVolumeID := fields[1]
  628. fields = strings.Fields(lines[2])
  629. c.Assert(fields[1], checker.Equals, "ps-volume-test")
  630. // filter by volume name
  631. out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=ps-volume-test")
  632. lines = strings.Split(strings.TrimSpace(string(out)), "\n")
  633. c.Assert(lines, checker.HasLen, 1)
  634. fields = strings.Fields(lines[0])
  635. c.Assert(fields[1], checker.Equals, "ps-volume-test")
  636. // empty results filtering by unknown volume
  637. out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=this-volume-should-not-exist")
  638. c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)
  639. // filter by mount destination
  640. out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+mp)
  641. lines = strings.Split(strings.TrimSpace(string(out)), "\n")
  642. c.Assert(lines, checker.HasLen, 2)
  643. fields = strings.Fields(lines[0])
  644. c.Assert(fields[1], checker.Equals, annonymounsVolumeID)
  645. fields = strings.Fields(lines[1])
  646. c.Assert(fields[1], checker.Equals, "ps-volume-test")
  647. // filter by bind mount source
  648. out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountSource)
  649. lines = strings.Split(strings.TrimSpace(string(out)), "\n")
  650. c.Assert(lines, checker.HasLen, 1)
  651. fields = strings.Fields(lines[0])
  652. c.Assert(fields, checker.HasLen, 2)
  653. c.Assert(fields[0], checker.Equals, "bind-mount-test")
  654. c.Assert(fields[1], checker.Equals, bindMountSource)
  655. // filter by bind mount destination
  656. out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountDestination)
  657. lines = strings.Split(strings.TrimSpace(string(out)), "\n")
  658. c.Assert(lines, checker.HasLen, 1)
  659. fields = strings.Fields(lines[0])
  660. c.Assert(fields, checker.HasLen, 2)
  661. c.Assert(fields[0], checker.Equals, "bind-mount-test")
  662. c.Assert(fields[1], checker.Equals, bindMountSource)
  663. // empty results filtering by unknown mount point
  664. out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+prefix+slash+"this-path-was-never-mounted")
  665. c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)
  666. }
  667. func (s *DockerSuite) TestPsFormatSize(c *check.C) {
  668. testRequires(c, DaemonIsLinux)
  669. runSleepingContainer(c)
  670. out, _ := dockerCmd(c, "ps", "--format", "table {{.Size}}")
  671. lines := strings.Split(out, "\n")
  672. c.Assert(lines[1], checker.Not(checker.Equals), "0 B", check.Commentf("Should not display a size of 0 B"))
  673. out, _ = dockerCmd(c, "ps", "--size", "--format", "table {{.Size}}")
  674. lines = strings.Split(out, "\n")
  675. c.Assert(lines[0], checker.Equals, "SIZE", check.Commentf("Should only have one size column"))
  676. out, _ = dockerCmd(c, "ps", "--size", "--format", "raw")
  677. lines = strings.Split(out, "\n")
  678. c.Assert(lines[8], checker.HasPrefix, "size:", check.Commentf("Size should be appended on a newline"))
  679. }
  680. func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
  681. // TODO default network on Windows is not called "bridge", and creating a
  682. // custom network fails on Windows fails with "Error response from daemon: plugin not found")
  683. testRequires(c, DaemonIsLinux)
  684. // create some containers
  685. runSleepingContainer(c, "--net=bridge", "--name=onbridgenetwork")
  686. runSleepingContainer(c, "--net=none", "--name=onnonenetwork")
  687. // Filter docker ps on non existing network
  688. out, _ := dockerCmd(c, "ps", "--filter", "network=doesnotexist")
  689. containerOut := strings.TrimSpace(string(out))
  690. lines := strings.Split(containerOut, "\n")
  691. // skip header
  692. lines = lines[1:]
  693. // ps output should have no containers
  694. c.Assert(lines, checker.HasLen, 0)
  695. // Filter docker ps on network bridge
  696. out, _ = dockerCmd(c, "ps", "--filter", "network=bridge")
  697. containerOut = strings.TrimSpace(string(out))
  698. lines = strings.Split(containerOut, "\n")
  699. // skip header
  700. lines = lines[1:]
  701. // ps output should have only one container
  702. c.Assert(lines, checker.HasLen, 1)
  703. // Making sure onbridgenetwork is on the output
  704. c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
  705. // Filter docker ps on networks bridge and none
  706. out, _ = dockerCmd(c, "ps", "--filter", "network=bridge", "--filter", "network=none")
  707. containerOut = strings.TrimSpace(string(out))
  708. lines = strings.Split(containerOut, "\n")
  709. // skip header
  710. lines = lines[1:]
  711. //ps output should have both the containers
  712. c.Assert(lines, checker.HasLen, 2)
  713. // Making sure onbridgenetwork and onnonenetwork is on the output
  714. c.Assert(containerOut, checker.Contains, "onnonenetwork", check.Commentf("Missing the container on none network\n"))
  715. c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on bridge network\n"))
  716. nwID, _ := dockerCmd(c, "network", "inspect", "--format", "{{.ID}}", "bridge")
  717. // Filter by network ID
  718. out, _ = dockerCmd(c, "ps", "--filter", "network="+nwID)
  719. containerOut = strings.TrimSpace(string(out))
  720. c.Assert(containerOut, checker.Contains, "onbridgenetwork")
  721. }
  722. func (s *DockerSuite) TestPsByOrder(c *check.C) {
  723. name1 := "xyz-abc"
  724. out, err := runSleepingContainer(c, "--name", name1)
  725. c.Assert(err, checker.NotNil)
  726. c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
  727. container1 := strings.TrimSpace(out)
  728. name2 := "xyz-123"
  729. out, err = runSleepingContainer(c, "--name", name2)
  730. c.Assert(err, checker.NotNil)
  731. c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
  732. container2 := strings.TrimSpace(out)
  733. name3 := "789-abc"
  734. out, err = runSleepingContainer(c, "--name", name3)
  735. c.Assert(err, checker.NotNil)
  736. c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
  737. name4 := "789-123"
  738. out, err = runSleepingContainer(c, "--name", name4)
  739. c.Assert(err, checker.NotNil)
  740. c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
  741. // Run multiple time should have the same result
  742. out, err = dockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz")
  743. c.Assert(err, checker.NotNil)
  744. c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1))
  745. // Run multiple time should have the same result
  746. out, err = dockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz")
  747. c.Assert(err, checker.NotNil)
  748. c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1))
  749. }
  750. func (s *DockerSuite) TestPsFilterMissingArgErrorCode(c *check.C) {
  751. _, errCode, _ := dockerCmdWithError("ps", "--filter")
  752. c.Assert(errCode, checker.Equals, 125)
  753. }