r/docker • • Jan 19 '19

Lets make "docker ps" human readable: docker-pretty-ps

Hey guys, long time reader first time poster.

I’ve been using docker for years, but cannot stand the “docker ps” output. I use a 13” monitor primarily and have bad eyesight. Shrinking my terminals font size to 8pt so I can fit everything on one line sucks... so I made docker-pretty-ps. Instead of going wide, lets go long. I also thought you might want to search through your containers, rather that dump them all to the screen, so i added that too.

The tool uses only built in python libraries, so it should install on any platform that's running Docker + Python.

docker-pretty-ps also has a handful of other CLI utilities to help you manage that docker ps data as well. This is my first published project so let me know your thoughts/ complaints and definitely bugs!

More info over at https://github.com/politeauthority/docker-pretty-ps

Or you can just install with

pip install docker-pretty-ps

Screenshot Regular Usage: https://imgur.com/zgcKx3H

Screenshot of SLIM mode: https://imgur.com/AR1N0R9

Project/ Source: https://github.com/politeauthority/docker-pretty-ps

TLDR: Let's make "docker ps " readable!

Edit: grammar

Edit2: Adding screenshots of --slim (s) mode

253 Upvotes

32 comments sorted by

14

u/littlebluebrown Jan 19 '19

Thanks for sharing. The screenshots look nice! You think this can be done with bash and some piping?

17

u/politeauthority Jan 19 '19

Yeah, this could probably done more simply then what I've put together. I'm not a bash long beard yet, and really like putting CLI tools together with python if the situation allows me to. I totally understand a lot of devops situations don't have room to install python.. and pip and THEN this silly thing. I think my target audience may be more developers than hard-core devops or SRE, but I wanted to share anyways :) Thanks for the feed back!

7

u/PinBot1138 Jan 19 '19

To be fair, Docker Compose requires Python.

6

u/[deleted] Jan 19 '19

Python is almost always installed on most Linux system. What you could do, for fun, is to provide a docker container with you binary in it. You know, if you can docker ps, you probably can docker run --rm pretty-ps ? Food for thought.

2

u/DoubleHooray Jan 19 '19

You’d have to install the docker CLI into the container or switch to the the python docker SDK. Either way, you’d have to mount the docker daemon socket /var/run/docker.sock

1

u/svvac Jan 20 '19

No need for a CLI. The docker socket is an HTTP endpoint IIRC. Mount the socket, then it's just curl+jq to retrieve the data and something to print it nicely like bash if you're into that. Otherwise, python has everything built in to query a HTTP socket and display stuff to the console.

1

u/DoubleHooray Jan 20 '19

Correct, it’s an HTTP endpoint. You can surely write your own REST interface; I try to stay out of the business of keeping up with API changes when I don’t have to.

1

u/svvac Jan 21 '19

The API should be about as stable as the CLI, if not more, but I get why one would like to avoid messing with it.

4

u/omg_drd4_bbq Jan 19 '19

You could try using Grumpy to compile to Go, then you can distribute binaries.

24

u/0bel1sk Jan 19 '19

Can just use the go template function already built in, I didn't color the container names, I leave that as an exercise for the reader :)

docker ps --format '{{.Names}}\n\tContainer ID: {{.ID}}\n\tCommand: {{.Command}}\n\tImage: {{.Image}}\n\tCreatedAt: {{.CreatedAt}}\n\tStatus: {{.Status}}'

keen_matsumoto

Container ID: 2fb04210730a

Command: "sleep 9999"

Image: alpine

CreatedAt: 2019-01-19 11:20:51 -0500 EST

Status: Up 4 seconds

vigilant_jepsen

Container ID: a45fc1973b6e

Command: "sleep 9999"

Image: alpine

CreatedAt: 2019-01-19 11:20:49 -0500 EST

Status: Up 6 seconds

10

u/verenion Jan 19 '19

Looks pretty cool. The only issue I would have is that we simple run lots of containers. Having each one on a single line is pretty useful, even if it’s ugly!

Should be useful for smaller host though!

15

u/politeauthority Jan 19 '19

I hear ya! With docker-pretty-ps you can do docker-pretty-ps --slim and have all containers report on a single line. If that's not enough info for ya, you can add docker-pretty-ps -s -i=cp That will give you all containers, with their (c)reation date, and (p)orts. The -i flag lets you select any data point docker-ps would give you, but at your choosing. For a full list of the -i flags and everything else, checkout the github README.

Thanks for the input!

5

u/moebaca Jan 19 '19

Nice work dude! It looks great. How long did it take you to develop it to this mature state?

Edit. Also a little grammatical error I noticed in the README:

always shrinking my terminal output just to see what docker ps is trying saying... 

Should say something like:

always shrinking my terminal output just to see what docker ps is trying to say... 

4

u/politeauthority Jan 19 '19

Thanks! Grammer/ spelling are not my strong points! I'll patch those up next chance I get.

TBH "mature" state is probably not exactly where this is, but I felt ready to share. I've been working on it on and off for a few months though probably. If you see something to fix or improve I'd love input from anyone!

5

u/verenion Jan 19 '19

Awesome, will defo check it out then!

36

u/snotsnot Jan 19 '19 edited Jan 19 '19

I pretty much switched to ctop. Looks nice though!

Edit: alias ctop='docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock quay.io/vektorlab/ctop:latest'

3

u/cardonator Jan 19 '19

Heh did exactly the same.

2

u/keithters Jan 20 '19

It’s really the simplest and most useful.

4

u/Ariquitaun Jan 19 '19

Very nice.

4

u/sm0kingm4n Jan 19 '19

I am going to install this. Thanks

1

u/SomeRedPanda Jan 19 '19

I still prefer ps. This seems like it would get really messy once you get a few more containers running. Standard way is more compact.

8

u/politeauthority Jan 19 '19

Here's a screen shot of -s or --slim.

https://imgur.com/AR1N0R9

I don't expect everyone to love it though. Thanks for the feedback!

3

u/zzopq Jan 19 '19

Agree. Appreciate author's work though.

IMO Docker team should add output like this to docker ps. It may look like docker ps --pretty or so

7

u/politeauthority Jan 19 '19

I thought for years any day that would come... And one day I just got tired of waiting. Thus this project.

I whole heatedly agree with ya!

2

u/mcpolandc Jan 19 '19

Really nice! I will have to give this a try

2

u/solrac214 Jan 20 '19

Similar behavior has been built into docker for a long time. It’s just not well documented. https://container42.com/2016/03/27/docker-quicktip-7-psformat/

2

u/acro5piano Jan 20 '19

I installed it. Really nice tool!

1

u/r00t_4orce Jan 21 '19 edited Jan 21 '19

Like many others have said - It's nicer to format and get the info right from Docker.

I too am not necessarily a fan of installing something to get better output etc.

However, if you are someone interested in installing something and want great looking output - plus - additional features, take a look at:

DRY

Also has the ability to be run via container:

alias dry='docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock moncho/dry'

0

u/[deleted] Jan 19 '19

[deleted]

3

u/politeauthority Jan 19 '19

Thanks! Hope it saves you some eye strain!