docker_compose_ps.yaml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. command: docker compose ps
  2. short: List containers
  3. long: |-
  4. Lists containers for a Compose project, with current status and exposed ports.
  5. ```console
  6. $ docker compose ps
  7. NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
  8. example-foo-1 alpine "/entrypoint.…" foo 4 seconds ago Up 2 seconds 0.0.0.0:8080->80/tcp
  9. ```
  10. By default, only running containers are shown. `--all` flag can be used to include stopped containers
  11. ```console
  12. $ docker compose ps --all
  13. NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
  14. example-foo-1 alpine "/entrypoint.…" foo 4 seconds ago Up 2 seconds 0.0.0.0:8080->80/tcp
  15. example-bar-1 alpine "/entrypoint.…" bar 4 seconds ago exited (0)
  16. ```
  17. usage: docker compose ps [OPTIONS] [SERVICE...]
  18. pname: docker compose
  19. plink: docker_compose.yaml
  20. options:
  21. - option: all
  22. shorthand: a
  23. value_type: bool
  24. default_value: "false"
  25. description: |
  26. Show all stopped containers (including those created by the run command)
  27. deprecated: false
  28. hidden: false
  29. experimental: false
  30. experimentalcli: false
  31. kubernetes: false
  32. swarm: false
  33. - option: filter
  34. value_type: string
  35. description: 'Filter services by a property (supported filters: status).'
  36. details_url: '#filter'
  37. deprecated: false
  38. hidden: false
  39. experimental: false
  40. experimentalcli: false
  41. kubernetes: false
  42. swarm: false
  43. - option: format
  44. value_type: string
  45. default_value: table
  46. description: 'Format the output. Values: [table | json]'
  47. details_url: '#format'
  48. deprecated: false
  49. hidden: false
  50. experimental: false
  51. experimentalcli: false
  52. kubernetes: false
  53. swarm: false
  54. - option: quiet
  55. shorthand: q
  56. value_type: bool
  57. default_value: "false"
  58. description: Only display IDs
  59. deprecated: false
  60. hidden: false
  61. experimental: false
  62. experimentalcli: false
  63. kubernetes: false
  64. swarm: false
  65. - option: services
  66. value_type: bool
  67. default_value: "false"
  68. description: Display services
  69. deprecated: false
  70. hidden: false
  71. experimental: false
  72. experimentalcli: false
  73. kubernetes: false
  74. swarm: false
  75. - option: status
  76. value_type: stringArray
  77. default_value: '[]'
  78. description: |
  79. Filter services by status. Values: [paused | restarting | removing | running | dead | created | exited]
  80. details_url: '#status'
  81. deprecated: false
  82. hidden: false
  83. experimental: false
  84. experimentalcli: false
  85. kubernetes: false
  86. swarm: false
  87. examples: |-
  88. ### Format the output (--format) {#format}
  89. By default, the `docker compose ps` command uses a table ("pretty") format to
  90. show the containers. The `--format` flag allows you to specify alternative
  91. presentations for the output. Currently, supported options are `pretty` (default),
  92. and `json`, which outputs information about the containers as a JSON array:
  93. ```console
  94. $ docker compose ps --format json
  95. [{"ID":"1553b0236cf4d2715845f053a4ee97042c4f9a2ef655731ee34f1f7940eaa41a","Name":"example-bar-1","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Project":"example","Service":"bar","State":"exited","Health":"","ExitCode":0,"Publishers":null},{"ID":"f02a4efaabb67416e1ff127d51c4b5578634a0ad5743bd65225ff7d1909a3fa0","Name":"example-foo-1","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Project":"example","Service":"foo","State":"running","Health":"","ExitCode":0,"Publishers":[{"URL":"0.0.0.0","TargetPort":80,"PublishedPort":8080,"Protocol":"tcp"}]}]
  96. ```
  97. The JSON output allows you to use the information in other tools for further
  98. processing, for example, using the [`jq` utility](https://stedolan.github.io/jq/){:target="_blank" rel="noopener" class="_"}
  99. to pretty-print the JSON:
  100. ```console
  101. $ docker compose ps --format json | jq .
  102. [
  103. {
  104. "ID": "1553b0236cf4d2715845f053a4ee97042c4f9a2ef655731ee34f1f7940eaa41a",
  105. "Name": "example-bar-1",
  106. "Command": "/docker-entrypoint.sh nginx -g 'daemon off;'",
  107. "Project": "example",
  108. "Service": "bar",
  109. "State": "exited",
  110. "Health": "",
  111. "ExitCode": 0,
  112. "Publishers": null
  113. },
  114. {
  115. "ID": "f02a4efaabb67416e1ff127d51c4b5578634a0ad5743bd65225ff7d1909a3fa0",
  116. "Name": "example-foo-1",
  117. "Command": "/docker-entrypoint.sh nginx -g 'daemon off;'",
  118. "Project": "example",
  119. "Service": "foo",
  120. "State": "running",
  121. "Health": "",
  122. "ExitCode": 0,
  123. "Publishers": [
  124. {
  125. "URL": "0.0.0.0",
  126. "TargetPort": 80,
  127. "PublishedPort": 8080,
  128. "Protocol": "tcp"
  129. }
  130. ]
  131. }
  132. ]
  133. ```
  134. ### Filter containers by status (--status) {#status}
  135. Use the `--status` flag to filter the list of containers by status. For example,
  136. to show only containers that are running or only containers that have exited:
  137. ```console
  138. $ docker compose ps --status=running
  139. NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
  140. example-foo-1 alpine "/entrypoint.…" foo 4 seconds ago Up 2 seconds 0.0.0.0:8080->80/tcp
  141. $ docker compose ps --status=exited
  142. NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
  143. example-bar-1 alpine "/entrypoint.…" bar 4 seconds ago exited (0)
  144. ```
  145. ### Filter containers by status (--filter) {#filter}
  146. The [`--status` flag](#status) is a convenient shorthand for the `--filter status=<status>`
  147. flag. The example below is the equivalent to the example from the previous section,
  148. this time using the `--filter` flag:
  149. ```console
  150. $ docker compose ps --filter status=running
  151. NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
  152. example-foo-1 alpine "/entrypoint.…" foo 4 seconds ago Up 2 seconds 0.0.0.0:8080->80/tcp
  153. ```
  154. The `docker compose ps` command currently only supports the `--filter status=<status>`
  155. option, but additional filter options may be added in the future.
  156. deprecated: false
  157. experimental: false
  158. experimentalcli: false
  159. kubernetes: false
  160. swarm: false