Custom Docker PS Output

If you are like me and running a whole bunch of docker containers doing various network things, the docker ps output can get pretty cluttered and almost impossible to dig through. Here's how to tame that output into something slightly more manageable.

The Root Command:

The base that we begin to build off is this:

docker ps --format

Configuration Options:

Identifier Description
.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 Exposed ports.
.State Container status (for example; "created", "running", "exited").
.Status Container status with details about duration and health-status.
.Size Container disk size.
.Names Container names.
.Labels All labels assigned to the container.
.Label Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts Names of the volumes mounted in this container.
.Networks Names of the networks attached to this container.

Here's an example that I use on my servers and a good place to get started:

docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.RunningFor}}\t{{.Image}}\t{{.ID}}'

A brief explanation to the formatting section:

  • The table option will organize the output into a table format trying to persist the columns as best as they can.
  • \t signifies a <TAB> character. If you want a new line use \n

There's lots of other options, including full-on scripts like this, that can customize that experience further.

‘docker ps’ output formatting: list only names of running containers
docker ps --format “table {{.Names}}” output NAMES in first row: root@docker-2gb-blr1-01:~# docker ps --format “table {{.Names}}” NAMES enr osticket osticket_db ... docker inspect --format ’{{.Na…