Skip to content

container/ps: new built-in compact output format - #7301

Open
carlosgrillet wants to merge 1 commit into
docker:masterfrom
carlosgrillet:feat/new-compact-format
Open

carlosgrillet wants to merge 1 commit into
docker:masterfrom
carlosgrillet:feat/new-compact-format

Conversation

@carlosgrillet

Copy link
Copy Markdown

Add a new built-in compact format for docker ps that displays the container ID, name, image, state, and running time in a table.

This enables --format compact and --format=compact

- What I did

Implemented a new built-in format called compact for docker ps that shows container info in handy way.

- Why I did it

I run docker containers all the time, and the problem with the output of the command docker ps is that it's lines are very long, which makes the output hard to read. Quite some time ago I started using this alias

alias dockerls='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.State}}\t{{.RunningFor}}"'

But the thing is that I keep forgeting that when I jump into a server. So I thought, why not baking this into docker? :)

I also thought about terse, brief and short

- How I did it

I created a constant called compactContainerTableFormat in cli/command/formatter/container.go. Then I handled the case for compact in NewContainerFormat and last I realized that I had to add compact to cli/command/formatter/formatter.go constants, and that's it.

Note: compact enables --all containers.

- How to verify it

tests passing
scripts/with-go-mod.sh go test ./cli/command/container -run 'TestContainerListWithCompactFormat'
+ ln -s vendor.mod /repos/docker-cli/go.mod
+ cleanup_paths+=("$link")
+ create_symlink vendor.sum /repos/docker-cli/go.sum
+ local target=vendor.sum
+ local link=/repos/docker-cli/go.sum
+ '[' -e /repos/docker-cli/go.sum ']'
+ set -x
+ ln -s vendor.sum /repos/docker-cli/go.sum
+ cleanup_paths+=("$link")
+ '[' 2 -gt 0 ']'
+ trap 'rm -f "${cleanup_paths[@]}"' EXIT
+ GO111MODULE=on
+ GOTOOLCHAIN=local
+ go test ./cli/command/container -run TestContainerListWithCompactFormat
ok      github.com/docker/cli/cli/command/container     0.005s
+ rm -f /repos/docker-cli/go.mod /repos/docker-cli/go.sum

and I build it and test it locally

./build/docker ps --format compact
CONTAINER ID   NAMES                 IMAGE     STATE     CREATED
85d0120fad9a   affectionate_golick   nginx     running   About an hour ago

- Human readable description for the release notes

New built-in format for `docker ps`. Now with `--format compact` docker ps dipslays the container ID, name, image, state, and running time in a table.

- A picture of a cute animal (not mandatory but encouraged)

4K picture of a cute cat: :3

Add a new built-in compact format for `docker ps` that displays
the container ID, name, image, state, and running time in a table.

This enables `--format compact` and `--format=compact`

Signed-off-by: Carlos Grillet <carlosbeta5000@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant