Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default "docker ps" output is too wide #7477

Closed
bfirsh opened this issue Aug 7, 2014 · 101 comments
Closed

Default "docker ps" output is too wide #7477

bfirsh opened this issue Aug 7, 2014 · 101 comments
Labels
area/cli exp/beginner kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny

Comments

@bfirsh
Copy link
Contributor

bfirsh commented Aug 7, 2014

screenshot 2014-08-07 16 27 38

Output from docker ps is very hard to read on 80 character wide terminals.

/bin/ps does a pretty good job of wrapping output on narrow terminals (e.g. putting important information first, command last and truncating it). I wonder if we can do better.

@tianon
Copy link
Member

tianon commented Aug 7, 2014

So much love and many +1s. I use 80x24 terminals (much to the chagrin of
my colleagues) and this one has been a minor irritant for me for quite some
time.

@nathanleclaire
Copy link
Contributor

I have to say this often gets me as well.

Any ideas for a solution? Having a smaller version on narrower terminals sounds nice.

@cpuguy83
Copy link
Member

cpuguy83 commented Aug 8, 2014

Well, ID doesn't really need to be there.

@bfirsh
Copy link
Contributor Author

bfirsh commented Aug 8, 2014

How about this:

NAME               IMAGE              STATUS      PORTS             COMMAND
prickly_perlman    ubuntu:14.04       Up 15s      8000->8000/tcp    sleep 30000

Explanation:

  • no ID because containers always have names
  • no created, you can inspect for that
  • it seems pretty useful to know an overview of all of the ports that are open, but maybe this could be dropped?
  • command can be truncated to width of terminal, like /bin/ps

@thaJeztah
Copy link
Member

@bfirsh 👍 with these notes;

  • Please, don't drop ports, to me they are quite useful to quickly see what ports are connected to what container. Having to inspect each container is cumbersome
  • What to do with --no-trunc, now that container-id is no longer visible? Many examples exist that rely on this feature to purge stopped containers
  • What will be the (default) sort order? Date created (not logical, since that column is no longer visible)? Alphabetically on container name?
  • For future improvement; allow specifying which columns to show and sort on (e.g. --columns=a,f,g --sort=a,e
  • For future improvement; make the columns to show and sort on configurable in a configuration-file
  • For future improvement; allow setting default filter options (do/do not show stopped containers by default (-a))

@benjamin-thomas
Copy link

What's wrong with piping to a pager?

docker ps | less -S

@grahamc
Copy link

grahamc commented Aug 11, 2014

@benjamin-thomas or docker ps detecting a TTY and piping to less -S by default?

@nathanleclaire
Copy link
Contributor

Nice trick @benjamin-thomas , I will definitely use that in the future. One consideration is that does leave off information I care about, most importantly, container names. Whereas in my usecase I don't usually care as much about e.g. CREATED and STATUS.

@thaJeztah
Copy link
Member

IMO the use case may vary among users, for me, STATUS is important to get a quick check if my containers are still running nicely or made a 'whoopsie'.

I'm not really sure if this should become a large re-implementation of ps output, or to start with making it a bit cleaner by default and building upon that, making it more configurable by adding options to specify columns to show, sort order and filtering.

@benjamin-thomas
Copy link

@nathanleclaire, just use your arrow keys once you're inside less, you have access to the whole content. Or did I misunderstand you?

@grahamc why not, personally I prefer tools not to do those things automatically. One could always define a shell alias for this IMO if that's needed.

@thaJeztah specifying the column names with switches makes sense to me, like the system ps command /bin/ps -o pid,ruser=RealUser -o comm=Command.

@nathanleclaire
Copy link
Contributor

@benjamin-thomas Oh, I hadn't even realized that. Nice! I like this solution a lot.

@bfirsh
Copy link
Contributor Author

bfirsh commented Aug 13, 2014

@benjamin-thomas /bin/ps does this automatically. If you want to disable it, you can pipe it through cat or whatever.

@tripped
Copy link

tripped commented Aug 15, 2014

Related to the width of docker ps output: is it really necessary to treat every possible chain of linkages to a given container as a new name for that container? E.g., if I have five containers named A, B, C, D, and E, and A links to B, B links to C, and so on, then E will have five different names: E, D/E, C/D/E, B/C/D/E, and A/B/C/D/E.

Then if B also links to, say, D, E gets even MORE names: B/D/E and A/B/D/E. One run of the system I'm working on starts seventeen containers -- which, all together, owing to 31 dependency relationships, have three hundred and eighty-seven names. No matter how wide I make my terminal windows, the output of docker ps is unreadable without a pager. Does it really make sense for the number of names to be worse than quadratic in the number of containers? It would at least be nice if there were a way to disable this pedantic level of enumeration.

@bfirsh
Copy link
Contributor Author

bfirsh commented Aug 16, 2014

@MrAccident 👍 docker ps should only show the primary name, not all names for that container

@ChristianKniep
Copy link

Salut, it was bothering me as well and I just added a '--short' option to docker. keeping the complete port-column.
https://github.com/ChristianKniep/docker/tree/7477-short_ps

$ docker run --name fd1 -d -p 80 -p 22 -p 53 fedora sleep 600
af6599f9b1178b237f6c2524f14cada45a46b234168e5270b99b16d1ce0be295
$ docker run --name fd2 --link fd1:fd1  -d -p 80 -p 22 -p 53 fedora sleep 600
ec2b2afc72dae7e62b197dc5adbcdeb548435ac495b8c935c728eb7aff658004
$ docker run --name fd3 --link fd2:fd2  --link fd1:fd1  -d -p 80 -p 22 -p 53 fedora sleep 600
ac57921063cc6afbe1cf715872dc33df45147ef1f464859c0912261b88e6bb4b
$ docker ps
CONTAINER ID        IMAGE                       COMMAND             CREATED             STATUS              PORTS                                                                 NAMES
ac57921063cc        fedora:latest   sleep 600           3 seconds ago       Up 2 seconds        0.0.0.0:49159->22/tcp, 0.0.0.0:49160->53/tcp, 0.0.0.0:49161->80/tcp   fd3                               
ec2b2afc72da        fedora:latest   sleep 600           11 seconds ago      Up 10 seconds       0.0.0.0:49156->22/tcp, 0.0.0.0:49157->53/tcp, 0.0.0.0:49158->80/tcp   fd2,fd3/fd2                       
af6599f9b117        fedora:latest   sleep 600           31 seconds ago      Up 30 seconds       0.0.0.0:49153->22/tcp, 0.0.0.0:49154->53/tcp, 0.0.0.0:49155->80/tcp   fd1,fd2/fd1,fd3/fd1,fd3/fd2/fd1                    
$ ./docker-1.1.2-dev ps -S
CONTAINER ID        IMAGE                       PORTS                                                                 NAMES
ac57921063cc        fedora:latest   0.0.0.0:49159->22/tcp, 0.0.0.0:49160->53/tcp, 0.0.0.0:49161->80/tcp   fd3                               
ec2b2afc72da        fedora:latest   0.0.0.0:49156->22/tcp, 0.0.0.0:49157->53/tcp, 0.0.0.0:49158->80/tcp   fd2,fd3/fd2                       
af6599f9b117        fedora:latest   0.0.0.0:49153->22/tcp, 0.0.0.0:49154->53/tcp, 0.0.0.0:49155->80/tcp   fd1,fd2/fd1,fd3/fd1,fd3/fd2/fd1             
$ ./docker-1.1.2-dev ps -h

Usage: docker ps [OPTIONS]

List containers

  -a, --all=false       Show all containers. Only running containers are shown by default.
  --before=""           Show only container created before Id or Name, include non-running ones.
  -f, --filter=[]       Provide filter values. Valid filters:
                          exited=<int> - containers with exit code of <int>
  -l, --latest=false    Show only the latest created container, include non-running ones.
  -n=-1                 Show n last created containers, include non-running ones.
  --no-trunc=false      Don't truncate output
  -q, --quiet=false     Only display numeric IDs
  -S, --short=false     Skip command created and status
  -s, --size=false      Display sizes
  --since=""            Show only containers created since Id or Name, include non-running ones.
$

Since I am a newbe to go, I guess my code could be... optimized...
But amazing how easy it is to change the code, as a yearlong python guy. I like it!

EDIT: Maybe one could fetch the size of the terminal and kick out columns to shorten the lines...

EDIT2: I shorten the NAMES and added a count(CHILDREN), even though it is a little bit misleading, because it counts fd3->fd2->fd1 as well.

$ ~/bin/docker-1.1.2-dev ps -S
CONTAINER ID        IMAGE                       PORTS                                                                 NAME                #CHILDREN
9b382826657c        fedora:latest   0.0.0.0:49168->22/tcp, 0.0.0.0:49169->53/tcp, 0.0.0.0:49170->80/tcp   fd3                 0
93f5a7b13d8b        fedora:latest   0.0.0.0:49165->22/tcp, 0.0.0.0:49166->53/tcp, 0.0.0.0:49167->80/tcp   fd2                 1
4c6f3564612c        fedora:latest   0.0.0.0:49162->80/tcp, 0.0.0.0:49163->22/tcp, 0.0.0.0:49164->53/tcp   fd1                 3

EDIT3: Now I extract the correct name

$ ./docker-1.1.2-dev ps -S
CONTAINER ID        IMAGE                       PORTS                                                                 NAME                #LINKS
71d9d03bba50        fedora:latest   0.0.0.0:49177->22/tcp, 0.0.0.0:49178->53/tcp, 0.0.0.0:49179->80/tcp   fd3                 0
cf67008f418f        fedora:latest   0.0.0.0:49174->22/tcp, 0.0.0.0:49175->53/tcp, 0.0.0.0:49176->80/tcp   fd2                 1
5549c65007b5        fedora:latest   0.0.0.0:49171->22/tcp, 0.0.0.0:49172->53/tcp, 0.0.0.0:49173->80/tcp   fd1                 3

@jdtimmerman
Copy link

I feel that the ports definition and the verbosity of the times are a big part of the width of the docker ps output. I think abbreviating the times and making the ports definitions wrap over lines would save a lot of space (in addition to allowing me to select/hide columns).

CONTAINER ID     IMAGE                 COMMAND                CREATED     STATUS              PORTS                            NAMES
8a2e6a22ae1f     me/abc-data:latest    "/bin/sh -c bash"      6 sec       Exited (0) 6 sec                                     app-without-ports
749ed051fb73     me/webserver:latest   "/opt/server/run.sh"   4 days      Up 4 days           0.0.0.0:8080->8080/tcp,          my-webserver
                                                                                              192.168.1.1:9990->9990/tcp      
2eb3c43af24f     me/app:latest         "/opt/container-star   8 days      Up 8 days           0.0.0.0:1234->1234/tcp,          some-other-app
                                                                                              0.0.0.0:4567->4567/tcp, 
                                                                                              0.0.0.0:50000->50000/tcp, 
                                                                                              0.0.0.0:50000->50000/udp  

@zoechi
Copy link
Contributor

zoechi commented Nov 25, 2014

What about allowing to provide a template for example by setting an environment variable DOCKER_PS_FORMAT with columname:width:modifier,columname:width:modifier, ...
where modifier might allow additional settings like no-trunc, full (for example for container id) or short for CREATED where ~1h could be a short form for About an hour ago.

@caiguanhao
Copy link

I wrote this bash/zsh function in my ~/.bashrc to better display output of docker ps, you can hide or re-order the columns:

dps()  {
  docker ps $@ | awk '
  NR==1{
    FIRSTLINEWIDTH=length($0)
    IDPOS=index($0,"CONTAINER ID");
    IMAGEPOS=index($0,"IMAGE");
    COMMANDPOS=index($0,"COMMAND");
    CREATEDPOS=index($0,"CREATED");
    STATUSPOS=index($0,"STATUS");
    PORTSPOS=index($0,"PORTS");
    NAMESPOS=index($0,"NAMES");
    UPDATECOL();
  }
  function UPDATECOL () {
    ID=substr($0,IDPOS,IMAGEPOS-IDPOS-1);
    IMAGE=substr($0,IMAGEPOS,COMMANDPOS-IMAGEPOS-1);
    COMMAND=substr($0,COMMANDPOS,CREATEDPOS-COMMANDPOS-1);
    CREATED=substr($0,CREATEDPOS,STATUSPOS-CREATEDPOS-1);
    STATUS=substr($0,STATUSPOS,PORTSPOS-STATUSPOS-1);
    PORTS=substr($0,PORTSPOS,NAMESPOS-PORTSPOS-1);
    NAMES=substr($0, NAMESPOS);
  }
  function PRINT () {
    print ID NAMES IMAGE STATUS CREATED COMMAND PORTS;
  }
  NR==2{
    NAMES=sprintf("%s%*s",NAMES,length($0)-FIRSTLINEWIDTH,"");
    PRINT();
  }
  NR>1{
    UPDATECOL();
    PRINT();
  }' | less -FSX;
}
dpsa() { dps -a $@; }

@bfirsh bfirsh added the UX label Jan 12, 2015
@coopernurse
Copy link

Workaround hack. Modify which $cols[x] you want to keep as desired.

docker ps | perl -ne '@cols = split /\s{2,}/, $_; printf "%30s %20s %20s\n", $cols[1], $cols[3], $cols[4]'

@wpp
Copy link
Contributor

wpp commented Jan 16, 2015

Wouldn't it be easier to have something like:

$ docker ps --columns=name,id,status,image

and everybody could just alias docker ps.

justinmayer added a commit to justinmayer/tackle that referenced this issue Jan 16, 2015
`dps`:  Show an abridged list of *running* Docker containers
`dpsa`: Show an abridged list of *all* Docker containers

Assumes terminal column width of 120.

Credit goes to:
moby/moby#7477 (comment)
@justinmayer
Copy link

Thanks, @caiguanhao. Clever interim solution. Added it as a Tackle plugin for the fish shell.

@jpmelos
Copy link

jpmelos commented Feb 13, 2015

Guys, just made a small improvement on @caiguanhao's code to be able to choose which columns to show. When you have a container that exposes many ports (like the Consul service, which exposes 5 or 6 ports and can make even a 300-characters-wide screen overflow), it's nice to have a command to show every column except those ports, and then another one that shows only the name of the containers and its ports (I added these options as new commands by default):

jpmelos/dotfiles@457a9c6

@mhsmith
Copy link

mhsmith commented Feb 15, 2015

One simple change that would help a little is to reduce the spacing between the CONTAINER ID and IMAGE columns. The other columns are all separated by 3 spaces, but these two are separated by 8.

@jessfraz jessfraz added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny labels Feb 28, 2015
@andyheath
Copy link

In the spirit of saving keystrokes here is the small bash script I wrote to take a list of arguments, construct the go template string and execute the docker ps command so as to give immediate display of whatever columns are wanted in whatever order. Putting configuration in a file is not dynamic enough - I find that having one set of columns one moment and different set a moment later is pretty useful. Script is here, hope its useful to someone. Cheers -andy

@danielfaust
Copy link

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import subprocess

show_all = False
fields = [
  "Names",
  "Command",
  "Image",
  "CreatedAt",
  "Status",
]

cmd = ['docker', 'ps']
if show_all:
  cmd += ['-a']
cmd += ['--format', '\t'.join([('{{ .'+field+' }}') for field in fields])]
response = subprocess.check_output(cmd)

dataset = [fields]
dataset_widths = [0] * len(fields)
for idx, line in enumerate(response.split('\n')[:-1]):
  fieldvalues = line.decode('utf-8').replace(u"\u2026", u"_").split('\t')
  dataset.append(fieldvalues)
  for jdx, fieldvalue in enumerate(fieldvalues):
    if dataset_widths[jdx] < len(fieldvalue):
      dataset_widths[jdx] = len(fieldvalue)

for idx, items in enumerate(dataset):
  output_line = ['{:>3d}'.format(idx)]
  for jdx, item in enumerate(items):
    output_line.append(('{:'+str(dataset_widths[jdx])+'s}').format(item))
  print '   '.join(output_line)

@mrt123
Copy link

mrt123 commented Feb 21, 2018

put this in your ~/.docker/config.json
{ "psFormat": "table {{.Names}}\\t{{.Image}}\\t{{.RunningFor}} ago\\t{{.Status}}\\t{{.Command}}", "imagesFormat": "table {{.Repository}}\\t{{.Tag}}\\t{{.ID}}\\t{{.Size}}" }

And modify to your liking. For me the problem was always long image name (since it contained my personal repository name for my custom images)

@gitnik
Copy link

gitnik commented Apr 24, 2018

everyone who is looking for a better docker ps should check this out:
https://github.com/moncho/dry

@boussou
Copy link

boussou commented Sep 22, 2019

Workaround hack. Modify which $cols[x] you want to keep as desired.

docker ps | perl -ne '@cols = split /\s{2,}/, $_; printf "%30s %20s %20s\n", $cols[1], $cols[3], $cols[4]'

Thanks.

This was all that I needed:
docker ps | perl -ne '@cols = split /\s{2,}/, $_; printf "%30s %20s %20s", $cols[1], $cols[4], $cols[6]'

giving IMAGE STATUS NAMES
in well aligned columuns

EDIT

it it better to create a bash alias with something like this:

docker ps --format="table {{.Image}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}"

Notice the "table" format

@nagracks
Copy link

Workaround hack. Modify which $cols[x] you want to keep as desired.

docker ps | perl -ne '@cols = split /\s{2,}/, $_; printf "%30s %20s %20s\n", $cols[1], $cols[3], $cols[4]'

That's awesome, thnx

@thaJeztah
Copy link
Member

@nagracks if you want that format as default, I'd recommend using the --format approach (which can be stored in your ~/.docker/config.json configuration file)

@jsejcksn
Copy link

jsejcksn commented Dec 4, 2019

If I modify my .docker/config.json file with something custom like this:

"imagesFormat": "table {{.ID}}  {{.Repository}}\t{{.Tag}}  {{.CreatedSince}}  {{.Size}}",
"psFormat": "table {{.ID}}  {{.Names}}\t{{.Image}}  {{.Command}}  {{.Status}}",

How can I then use the docker ps command to view the default format? I tried docker ps --format "", but it still used the config.

@thaJeztah
Copy link
Member

Using docker ps --format=table should give the default table format

@MythicManiac
Copy link

I would really appreciate if there was a less-verbose version of the output available by default, without having to remember what the table formatting syntax is or what the variable names are in the formatting context. Even if the default would be kept as it is, a flag for a pre-formatted less verbose version would be useful.

As to what information could be reduced from a less verbose version, here's my two cents:

  • Name and ID for most uses serve the same purpose, and such one could be eliminated.
  • Creation datetime is probably something you'd be fine with being omitted from the less verbose output
  • I'd also personally be fine with omitting ports from the less verbose output

In my use case I usually just want to look up the name of the container I'll be running some other commands against (e.g. on a remote server node), and having the output be wrapped across multiple lines makes it difficult to find out the exact name of the container I'm interested in.

I'm somewhat disappointed the "approved" solution here is "just configure an alias with --format parameter", as if you would always be running these commands in environments where you have your alias defined, or remember the formatting syntax and context variables

@bfirsh
Copy link
Contributor Author

bfirsh commented Jul 18, 2020

I still run into this issue daily, FWIW. My current output of docker ps -a is 180 characters wide -- more than half of my 27" 4K screen!

CONTAINER ID        IMAGE                                          COMMAND                 CREATED             STATUS                    PORTS               NAMES
994be99dddd1        nvidia/cuda:10.2-devel-ubuntu18.04             "bash"                  4 days ago          Exited (0) 4 days ago                         eager_tesla
30796cc3db32        nvidia/cuda:10.2-devel-ubuntu18.04             "bash"                  4 days ago          Exited (127) 4 days ago                       laughing_maxwell
ed5f20c1cff3        gcr.io/deeplearning-platform-release/tf2-gpu   "/entrypoint.sh bash"   4 days ago          Exited (0) 3 days ago                         distracted_ardinghelli
0bb06e992ef4        gcr.io/deeplearning-platform-release/tf2-gpu   "/entrypoint.sh bash"   4 days ago          Exited (0) 4 days ago                         bold_brahmagupta

The average user shouldn't be expected to alias their docker ps command just to make it readable on a reasonably sized terminal. Maybe it doesn't have to be as small as 80 characters, but it certainly shouldn't be 180 characters.

I'm tempted to open a pull request as a strawman. 😏

@saevarb
Copy link

saevarb commented Jan 27, 2021

I cannot for the life of me fathom that this issue is 7 years old now and nothing has been done about it. docker ps is hands down the most common command I use during development and having to parse the stupidly long output from ps, then stumbling upon this issue, is yet another thing that makes me want to give up on technology and move to the wilderness.

@thaJeztah
Copy link
Member

thaJeztah commented Jan 27, 2021

nothing has been done about it

Various changes have been made; see the discussion above;

Use the --format flag to specify what information you want to be shown, e.g.;

$ docker ps --format "table {{ .ID }}\t{{.Names}}\t{{.Status}}"

CONTAINER ID   NAMES                             STATUS
c1ddaacec4b1   foo.2.otc3vwejh16cvgtttm0uzmvmv   Up 2 days
073997fd8e95   foo.1.p9vr6bb44vsnmzbphbkptam9m   Up 2 days
c4bd87d6b496   foo.5.5lzhyu8ncnncbxufsrtsnmwd0   Up 2 days
8b534ba4b653   foo.3.t4en4k5gu16pbnu5pjz72n3im   Up 2 days
924bbaef36ba   foo.4.vxx38l4ma1byk8j9kd4xvcqbe   Up 2 days

Or specify your custom format in the ~/.docker/config.json file to use it as a default;

{
  "psFormat": "table {{ .ID }}\\t{{ .Names }}\t{{ .Status }}"
}

Docker 20.10 in addition reduces the space between columns / minimal column width (docker/cli#2699). Default output now looks like (~122 characters wide);

$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED      STATUS      PORTS     NAMES
c1ddaacec4b1   nginx:alpine   "/docker-entrypoint.…"   2 days ago   Up 2 days   80/tcp    foo.2.otc3vwejh16cvgtttm0uzmvmv
073997fd8e95   nginx:alpine   "/docker-entrypoint.…"   2 days ago   Up 2 days   80/tcp    foo.1.p9vr6bb44vsnmzbphbkptam9m
c4bd87d6b496   nginx:alpine   "/docker-entrypoint.…"   2 days ago   Up 2 days   80/tcp    foo.5.5lzhyu8ncnncbxufsrtsnmwd0
8b534ba4b653   nginx:alpine   "/docker-entrypoint.…"   2 days ago   Up 2 days   80/tcp    foo.3.t4en4k5gu16pbnu5pjz72n3im
924bbaef36ba   nginx:alpine   "/docker-entrypoint.…"   2 days ago   Up 2 days   80/tcp    foo.4.vxx38l4ma1byk8j9kd4xvcqbe

There never will be a one-size-fits-all selection of columns as different users / use-cases need different information, which is why it's made configurable.

@oscar230
Copy link

oscar230 commented Oct 8, 2021

What's wrong with piping to a pager?

docker ps | less -S

Awesome, thanks. Made an alias for this and added it to my ~/.bashrc.
The alias is alias dpss='docker ps | less -S'.

@lxnn
Copy link

lxnn commented Jan 22, 2022

Would it be possible to have an option to wrap the table?

Kind of like this (same output as in bfirsh's last comment):

    CONTAINER ID        IMAGE                                          COMMAND                 
 0  994be99dddd1        nvidia/cuda:10.2-devel-ubuntu18.04             "bash"                  
 1  30796cc3db32        nvidia/cuda:10.2-devel-ubuntu18.04             "bash"                  
 2  ed5f20c1cff3        gcr.io/deeplearning-platform-release/tf2-gpu   "/entrypoint.sh bash"   
 3  0bb06e992ef4        gcr.io/deeplearning-platform-release/tf2-gpu   "/entrypoint.sh bash"   

    CREATED             STATUS                    PORTS               NAMES
 0  4 days ago          Exited (0) 4 days ago                         eager_tesla
 1  4 days ago          Exited (127) 4 days ago                       laughing_maxwell
 2  4 days ago          Exited (0) 3 days ago                         distracted_ardinghelli
 3  4 days ago          Exited (0) 4 days ago                         bold_brahmagupta

This is how they display data-frames that are too wide to fit within the width of the terminal in Python's Pandas library.

I tried to achieve something like this using --format and other command line tools, but it's beyond me.

@gitautas
Copy link

Would it be possible to have an option to wrap the table?

Kind of like this (same output as in bfirsh's last comment):

    CONTAINER ID        IMAGE                                          COMMAND                 
 0  994be99dddd1        nvidia/cuda:10.2-devel-ubuntu18.04             "bash"                  
 1  30796cc3db32        nvidia/cuda:10.2-devel-ubuntu18.04             "bash"                  
 2  ed5f20c1cff3        gcr.io/deeplearning-platform-release/tf2-gpu   "/entrypoint.sh bash"   
 3  0bb06e992ef4        gcr.io/deeplearning-platform-release/tf2-gpu   "/entrypoint.sh bash"   

    CREATED             STATUS                    PORTS               NAMES
 0  4 days ago          Exited (0) 4 days ago                         eager_tesla
 1  4 days ago          Exited (127) 4 days ago                       laughing_maxwell
 2  4 days ago          Exited (0) 3 days ago                         distracted_ardinghelli
 3  4 days ago          Exited (0) 4 days ago                         bold_brahmagupta

This is how they display data-frames that are too wide to fit within the width of the terminal in Python's Pandas library.

I tried to achieve something like this using --format and other command line tools, but it's beyond me.

This would be useful for me as well, any resolution would be incredibly welcome.

@DreadDragoon
Copy link

DreadDragoon commented Jan 24, 2022

I feel that the ports definition and the verbosity of the times are a big part of the width of the docker ps output. I think abbreviating the times and making the ports definitions wrap over lines would save a lot of space (in addition to allowing me to select/hide columns).

CONTAINER ID     IMAGE                 COMMAND                CREATED     STATUS              PORTS                            NAMES
8a2e6a22ae1f     me/abc-data:latest    "/bin/sh -c bash"      6 sec       Exited (0) 6 sec                                     app-without-ports
749ed051fb73     me/webserver:latest   "/opt/server/run.sh"   4 days      Up 4 days           0.0.0.0:8080->8080/tcp,          my-webserver
                                                                                              192.168.1.1:9990->9990/tcp      
2eb3c43af24f     me/app:latest         "/opt/container-star   8 days      Up 8 days           0.0.0.0:1234->1234/tcp,          some-other-app
                                                                                              0.0.0.0:4567->4567/tcp, 
                                                                                              0.0.0.0:50000->50000/tcp, 
                                                                                              0.0.0.0:50000->50000/udp  

^This.

If we could have the option tell it to add a CR after each var in the array, vs just having them spew out on one line, that'd be amazing.

@Mikescher
Copy link

Mikescher commented Oct 10, 2022

If we could have the option tell it to add a CR after each var in the array, vs just having them spew out on one line, that'd be amazing.

Actually a good idea, I took the liberty and implemented it into an kinda-alternative docker-ps tool. (I created a bash function to drop-in replace docker ps with the better formatted version..)
If you still feel the pain of the docker-ps output (I do. Currently I have some containers that get wrapped into 4 lines -.-), feel free to use it :)

@boussou
Copy link

boussou commented Oct 10, 2022

Nice !

I like the way it displays ports & IP

installed ;-)

@jadrovski
Copy link

Bash script to output docker ps in narrow mode with ports wrapping
https://github.com/jadrovski/narrow-docker-ps

@jasonmp85
Copy link

Neat: the utter unusability of this has almost made it to a decade!

@GottZ
Copy link

GottZ commented Apr 27, 2023

indeed.. not only did it make it almost to a decade, previous solutions got lost along the way too!

here mine in plain awk from 8 years ago with wrapping ports.. still using it to this day:

#7477 (comment)

@aquirdTurtle
Copy link

The default output of docker ps on one of my systems is over 200 columns wide. Very painful that the devs seem to think this is acceptable behavior.

@thomasf
Copy link
Contributor

thomasf commented Sep 4, 2023

When I don't need all the data I use a bash function that just cut's off the output at the current terminal width which is fine most of the times for a quick check. The alias could of course also contain any custom format if you want to shorten it before cutting it off.

dps ()
{
    docker ps | cut -c-$(tput cols)
}

@boussou
Copy link

boussou commented Sep 4, 2023

When I don't need all the data

Less effective than the following (taken from previous comments)

docker ps --format="table {{.Image}}\t{{.Ports}}\t{{.Status}}\t{{.Names}}" 

so as a function

dps() {

# http://mando.github.io/2016/02/05/docker-ps-formatting.html

        docker ps --format="table {{.Image}}\t{{.Ports}}\t{{.Status}}\t{{.Names}}" $@
#        docker ps --format="table {{.Image}}\t{{.Status}}\t{{.Names}}" $@
	#docker ps --format="table {{.Image}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}" $@
}

@thaJeztah
Copy link
Member

You can configure your preferred format in ~/.docker/config.json if you don't want to use an alias; #7477 (comment)

@jasonmp85
Copy link

jasonmp85 commented Sep 4, 2023 via email

@turbotimon
Copy link

turbotimon commented Feb 23, 2024

I appreciate this long running discussion, this topic also bumps me from the beginning of using Docker (like many others it seems).

Yes, the --format option may solve some of the problems. However, as there is no format command to specify max field length, the initial problem of very white lines therefore remains. In my case for example: docker ps -a --format "table {{ .ID }}\t{{.Names}}\t{{.Image}}\t{{.Status}}"

CONTAINER ID   NAMES                                  IMAGE                                                                                                                            STATUS
546899e78e1e   services-redis-1                       redis:latest                                                                                                                     Exited (0) 2 months ago
3eb2727e93b8   hardcore_hodgkin                       vsc-project-xyz-5581627750211c75baca9d4a3e298e24d5bccfbbecc4ea967f7eabdb7a93de19-features-uid   Exited (255) 2 weeks ago

Is there an inbuilt solution for that (without piping to e.g. awk, less)? I would like to see an generall option like --max-field-length=20 or a format command to abbreviate after a certain length.

@xucian
Copy link

xucian commented Feb 27, 2024

so no progress for 10y?

would some really important people indirectly lose money if this gets implemented? otherwise I can't explain it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli exp/beginner kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny
Projects
None yet
Development

No branches or pull requests