百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

better-docker-ps

> 编程语言
开源

因为"Docker"的ps很烦人,不符合我的显示器/平面宽度

348 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

因为"Docker"的ps很烦人,不符合我的显示器/平面宽度

./dops - better docker ps

A replacement for the default docker-ps that tries really hard to fit within your terminal width.

Rationale

By default, my docker ps output is really wide and every line wraps around into three. This (obviously) breaks the tabular display and makes everything chaotic.
(This gets especially bad if one container has multiple port mappings, and they are all displayed in a single row) It doesn't look like we'll get improved output in the foreseeable future (see moby#7477), so I decided to make my own drop-in replacement.

Features

  • All normal commandline flags/options from docker-ps work (almost) the same.
  • Write multi-value data (like multiple port mappings, multiple networks, etc.) into multiple lines instead of concatenating them.
  • Add color to the STATE and STATUS column (green / yellow / red).
  • Automatically remove columns in the output until it fits in the current terminal width.
  • sort the output with the --sort argument
  • Enter watch mode with the --watch argument

More Changes from default docker-ps:

  • Show (by default) the container-cmd without arguments.
  • Show the ImageName (by default) without the registry prefix, and split ImageName and ImageTag into two columns.
  • Added the columns IP and NETWORK to the default column set (if they fit)
  • Added support for a few new columns (via --format):
    {{.ImageName}, {{.ImageTag}, {{.Tag}, {{.ImageRegistry}, {{.Registry}, {{.ShortCommand}, {{.LabelKeys}, {{.IP}, {{.User}
  • The {{.User}} column shows the user a container runs as (Config.User). Because this is not part of the cheaper container-list endpoint, dops only queries the (slower) container-inspect endpoint when this column is used.
  • Added options to control the color-output, the used socket, the time-zone and time-format, etc (see ./dops --help)

Getting started

Generic Linux (e.g. Debian/Fedora/...)

  • Download the latest binary from the releases page and put it into your PATH (eg /usr/local/bin)
  • You can also use the following one-liner (afterwards you can use the dops command everywhere):
bash
sudo wget "https://github.com/Mikescher/better-docker-ps/releases/latest/download/dops_linux-amd64-static" -O "/usr/local/bin/dops" && sudo chmod +x "/usr/local/bin/dops"

ArchLinux

  • Alternatively you can use one of the AUR packages (under Arch Linux):
    • https://aur.archlinux.org/packages/dops-bin (installs dops into your PATH)
    • https://aur.archlinux.org/packages/dops-git (installs dops into your PATH)
  • or the homebrew package:
    • brew tap mikescher/tap && brew install dops

Optional steps

  • Alias the docker ps command to dops (see section below)

Building from source

If you want to build dops from source, you need to have Go installed.

bash
git clone https://github.com/Mikescher/better-docker-ps.git
cd better-docker-ps
make build
mv _out/dops "$HOME/.local/bin/"

Screenshots

All (default) columns visible

 

Output on a medium sized terminal

 

Output on a small terminal

 

Usage as drop-in replacement

You can fully replace docker ps by creating a shell function in your .bashrc / .zshrc...

bash
docker() {
  case $1 in
    ps)
      shift
      command dops "$@"
      ;;
    *)
      command docker "$@";;
  esac
}

This will alias every call to docker ps ... with dops ... (be sure to have the dops binary in your PATH).

If you are using the fish-shell you have to create a (similar) function:

fish
function docker
    if test -n "$argv[1]"
        switch $argv[1]
            case ps
                dops $argv[2..-1]
            case '*'
                command docker $argv[1..-1]
        end
    end
end

Changing the output format

By default dops tries to be "intelligent" and find the best output format for your terminal width. The current output formats (= table columns) are defined in the options.go. The first format that fits in your terminal width is used.

But you can also override it by supplying a --format parameter. If you supply more than one --format parameter the first one that fits your terminal is used (same logic as with the default ones...)

Normally only simple columns aka {{.Status}} are supported.
But you can also use the full golang template syntax (e.g. {{ printf "%.15s" .Command }}). In this case it can be useful to specify the column header by prefixing it with a colon (SHORTENED NAME:{{ printf "%.10s" (join .Names ";") }})

The following functions are defined in these templates (plus the default go functions):

  • join: strings.Join
  • array_last: v[-1]
  • array_slice: v[a..b]
  • in_array: v1.contains(v2)
  • json: json.Marshal(v)
  • json_indent: json.MarshalIndent(v, "", " ")
  • json_pretty: json.Indent(v, "", " ")
  • coalesce: v1 ?? v2
  • to_string: fmt.Sprintf("%v", v)
  • deref: *v
  • now: time.Now()
  • uniqid: UUID

Examples:

$ ./dops --format "table {{.ID}}"
$ ./dops --format "table {{.ID}}\\t{{.Names}}\\t{{.State}}"

$ ./dops --format "idlist"

$ ./dops --format "table {{.ID}}\\t{{.Names}}\\t{{.State}}"  --format "table {{.ID}}\\t{{.Names}}" --format "table {{.ID}}"

$ ./dops --format "ID: {{.ID}}; Name: {{.Names}}"

$ ./dops -aq

$ ./dops --sort "IP" --sort-direction "ASC"

$ ./dops --format "table {{.ID}}\\tCMD:{{ printf \"%.15s\" .Command }}"
$ ./dops --format "table {{.ID}}\\tNAME:{{ printf \"%.10s\" (join .Names \";\") }}"

Persistant configuration

You can also configure some/most of the options via a configuration file.
Place a TOML formatted file in $HOME/.config/dops.conf / $XDG_CONFIG_HOME/dops.conf.
( ~/Library/Application Support/dops.conf is also supported under macOS )

The first existing file from the following locations is used:

  • $XDG_CONFIG_HOME/dops.conf (or the platform default, e.g. ~/Library/Application Support/dops.conf under macOS)
  • ~/.config/dops.conf

The following keys are supported:

  • verbose
  • silent
  • timezone
  • timeformat
  • timeformat-header
  • color
  • socket
  • all
  • size
  • filter (= string array)
  • search
  • format (= string array)
  • last
  • latest
  • truncate
  • header (= true / false / simple)
  • sort (= string array)
  • sort-direction (= string array)

Example:

toml
verbose = 0

timezone = "Europe/Berlin"

format = [
   "table {{.ID}}\t{{.Names}}\t{{.State}}\t{{.Status}}",
   "table {{.ID}}\t{{.Names}}\t{{.State}}",
   "table {{.ID}}\t{{.Names}}",
   "table {{.ID}}",
]

header = "simple"

Manual

Output of ./dops --help:

better-docker-ps

Usage:
  dops [OPTIONS]                     List docker container

Options (default):
  -h, --help                         Show this screen.
  --version                          Show version.
  --all , -a                         Show all containers (default shows just running)
  --filter , -f            Filter output based on conditions provided
  --search , -g            Filter output by substring match across all visible columns (case-insensitive)
  --format                      Pretty-print containers using a Go template
  --last , -n                        Show n last created containers (includes all states)
  --latest , -l                      Show the latest created container (includes all states)
  --no-trunc                         Don't truncate output (eg ContainerIDs, Sha256 Image references, commandline)
  --quiet , -q                       Only display container IDs
  --size , -s                        Display total file sizes

Options (extra | do not exist in `docker ps`):
  --silent                           Do not print any output
  --timezone                         Specify the timezone for date outputs
  --color                Enable/Disable terminal color output
  --no-color                         Disable terminal color output
  --socket                 Specify the docker socket location (Default: `auto` - which calls the docker cli to determine the socket)
  --timeformat          Specify the datetime output format (golang syntax)
  --no-header                        Do not print the table header
  --simple-header                    Do not print the lines under the header
  --format                      You can specify multiple formats and the first one that fits your terminal widt will be used
  --sort                        Sort output by a specific column, use the same identifier as in --format, only useful together with table formats 
  --sort-direction         The sort direction, only useful in combination with --sort
  --watch , -w   Automatically refresh output periodically (interval is optional, default: 2s) 

Available --format keys (default):
  {{.ID}}                            Container ID
  {{.Image}}                         Image ID
  {{.Command}}                       Quoted command
  {{.CreatedAt}}                     Time when the container was created.
  {{.RunningFor}}                    Elapsed time since the container was started.
  {{.Ports}}                         Published ports. ([!] differs from docker CLI, these are only the published ports)
  {{.State}}                         Container status
  {{.Status}}                        Container status with details
  {{.Size}}                          Container disk size.
  {{.Names}}                         Container names.
  {{.Labels}}                        All labels assigned to the container.
  {{.Label}}                         [!] Unsupported
  {{.Mounts}}                        Names of the volumes mounted in this container.
  {{.Networks}}                      Names of the networks attached to this container.

Available --format keys (extra | do not exist in `docker ps`):
  {{.ImageName}}                     Image ID (without tag and registry)
  {{.ImageTag}}, {{.Tag}}            Image Tag
  {{.ImageRegistry}}, {{.Registry}}  Image Registry
  {{.ShortCommand}}                  Command without arguments
  {{.LabelKeys}}                     All labels assigned to the container (keys only)
  {{.ShortPublishedPorts}}           Published ports, shorter output than {{.Ports}}
  {{.LongPublishedPorts}}            Published ports, full output with IP
  {{.ExposedPorts}}                  Exposed ports
  {{.PublishedPorts}}                Published ports
  {{.NotPublishedPorts}}             Exposed but not published ports
  {{.PublicPorts}}                   Only the public part of published ports
  {{.IP}}                            Internal IP Address
  {{.User}}                          User the container runs as (queried via container-inspect)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Go

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言