Docker ps 命令

发布于 2022-07-21 16:10:40 更新于 2022-07-21 16:10:40

作用

ps 命令可以列出当前所有容器,另外,还可额外添加参数:

  • -a 参数列出所有状态的容器;
  • -l 列出最新创建的容器,包括处于停止运行状态的容器;

用法

Usage: docker ps [OPTIONS]

List containers

-a, --all=false       Show all containers (default shows just running)
--before=             Show only container created before Id or Name
-f, --filter=[]       Filter output based on conditions provided
--help=false          Print usage
-l, --latest=false    Show the latest created container, include non-running
-n=-1                 Show n last created containers, include non-running
--no-trunc=false      Don't truncate output
-q, --quiet=false     Only display numeric IDs
-s, --size=false      Display total file sizes
--since=              Show created since Id or Name, include non-running

示例

$ sudo docker ps -a
CONTAINER ID  IMAGE    COMMAND       CREATED       STATUS                      PORTS    NAMES
b448f729a0b0  centos   "/bin/bash"   4 days ago    Exited (137) 4 days ago              pensive_wilson
54c7b6d6632e  centos   "/bin/bash"   4 days ago    Exited (0) 3 days ago                adoring_wozniak

筛选出 exied 状态是 0 的容器:

$ sudo docker ps -a --filter 'exited=0'
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                  PORTS               NAMES
8d92293a65e9        registry.liugang/centos   "/bin/bash"         7 days ago          Exited (0) 5 days ago                       web
8410f389ea65        registry.liugang/centos   "/bin/bash"         7 days ago          Exited (0) 7 days ago                       test_link