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 · 76 comments

Comments

Projects
None yet
@bfirsh
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

This comment has been minimized.

Show comment
Hide comment
@tianon

tianon Aug 7, 2014

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@nathanleclaire

nathanleclaire Aug 8, 2014

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.

Contributor

nathanleclaire commented Aug 8, 2014

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

This comment has been minimized.

Show comment
Hide comment
@cpuguy83

cpuguy83 Aug 8, 2014

Contributor

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

Contributor

cpuguy83 commented Aug 8, 2014

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

@bfirsh

This comment has been minimized.

Show comment
Hide comment
@bfirsh

bfirsh Aug 8, 2014

Contributor

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
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@thaJeztah

thaJeztah Aug 8, 2014

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))
Member

thaJeztah commented Aug 8, 2014

@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

This comment has been minimized.

Show comment
Hide comment
@benjamin-thomas

benjamin-thomas Aug 11, 2014

What's wrong with piping to a pager?

docker ps | less -S

What's wrong with piping to a pager?

docker ps | less -S
@grahamc

This comment has been minimized.

Show comment
Hide comment
@grahamc

grahamc Aug 11, 2014

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

grahamc commented Aug 11, 2014

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

@nathanleclaire

This comment has been minimized.

Show comment
Hide comment
@nathanleclaire

nathanleclaire Aug 11, 2014

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.

Contributor

nathanleclaire commented Aug 11, 2014

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

This comment has been minimized.

Show comment
Hide comment
@thaJeztah

thaJeztah Aug 11, 2014

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.

Member

thaJeztah commented Aug 11, 2014

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

This comment has been minimized.

Show comment
Hide comment
@benjamin-thomas

benjamin-thomas Aug 13, 2014

@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, 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

This comment has been minimized.

Show comment
Hide comment
@nathanleclaire

nathanleclaire Aug 13, 2014

Contributor

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

Contributor

nathanleclaire commented Aug 13, 2014

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

@bfirsh

This comment has been minimized.

Show comment
Hide comment
@bfirsh

bfirsh Aug 13, 2014

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@tripped

tripped 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.

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

This comment has been minimized.

Show comment
Hide comment
@bfirsh

bfirsh Aug 16, 2014

Contributor

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

Contributor

bfirsh commented Aug 16, 2014

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

@ChristianKniep

This comment has been minimized.

Show comment
Hide comment
@ChristianKniep

ChristianKniep Aug 20, 2014

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

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

This comment has been minimized.

Show comment
Hide comment
@jdtimmerman

jdtimmerman Nov 24, 2014

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  

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

This comment has been minimized.

Show comment
Hide comment
@zoechi

zoechi Nov 25, 2014

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@caiguanhao

caiguanhao Jan 9, 2015

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 $@; }

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

This comment has been minimized.

Show comment
Hide comment
@coopernurse

coopernurse Jan 14, 2015

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]'

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

This comment has been minimized.

Show comment
Hide comment
@wpp

wpp Jan 16, 2015

Contributor

Wouldn't it be easier to have something like:

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

and everybody could just alias docker ps.

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

Add dps and dpsa commands to Docker plugin
`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

This comment has been minimized.

Show comment
Hide comment
@justinmayer

justinmayer Jan 16, 2015

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

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

@jpmelos

This comment has been minimized.

Show comment
Hide comment
@jpmelos

jpmelos 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

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

This comment has been minimized.

Show comment
Hide comment
@mhsmith

mhsmith 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.

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.

@t0mk

This comment has been minimized.

Show comment
Hide comment
@t0mk

t0mk Apr 3, 2015

My 5 cents until they make 'docker ps' readable:

https://github.com/t0mk/dosk#dops

t0mk commented Apr 3, 2015

My 5 cents until they make 'docker ps' readable:

https://github.com/t0mk/dosk#dops

@AntouanK

This comment has been minimized.

Show comment
Hide comment
@AntouanK

AntouanK Apr 22, 2015

Are we going to see any update on that?
docker ps is the most common command I think. I hope it's not so hard to give us the option to filter columns to show.
( I'd expect something like that )

Are we going to see any update on that?
docker ps is the most common command I think. I hope it's not so hard to give us the option to filter columns to show.
( I'd expect something like that )

@p4tin

This comment has been minimized.

Show comment
Hide comment

p4tin commented Apr 26, 2015

#dibs

@asabla

This comment has been minimized.

Show comment
Hide comment
@asabla

asabla May 29, 2015

Like @AntouanK said and @wpp already suggested, a columns flag would be prefered for most situations

asabla commented May 29, 2015

Like @AntouanK said and @wpp already suggested, a columns flag would be prefered for most situations

@duglin

This comment has been minimized.

Show comment
Hide comment
@duglin

duglin May 29, 2015

Contributor

I think #10255 should address this.

Contributor

duglin commented May 29, 2015

I think #10255 should address this.

@bfirsh

This comment has been minimized.

Show comment
Hide comment
@bfirsh

bfirsh May 29, 2015

Contributor

@duglin Does this make the default shorter, though? I'd like to keep this open if not.

Contributor

bfirsh commented May 29, 2015

@duglin Does this make the default shorter, though? I'd like to keep this open if not.

@duglin

This comment has been minimized.

Show comment
Hide comment
@duglin

duglin May 29, 2015

Contributor

@bfirsh good point, no it wouldn't change the default. But I'm not sure we can change the default until v2 (if/when that is) because we'd break existing clients if we did.

Contributor

duglin commented May 29, 2015

@bfirsh good point, no it wouldn't change the default. But I'm not sure we can change the default until v2 (if/when that is) because we'd break existing clients if we did.

@berlincount

This comment has been minimized.

Show comment
Hide comment
@berlincount

berlincount May 29, 2015

same here. maybe some intelligent mechanism that selects default columns displayed by applying thresholds to ENV['COLUMNS']?

same here. maybe some intelligent mechanism that selects default columns displayed by applying thresholds to ENV['COLUMNS']?

@jessfraz jessfraz added kind/feature and removed kind/feature UX labels Sep 8, 2015

@parf

This comment has been minimized.

Show comment
Hide comment
@parf

parf Sep 8, 2015

Problem in docker 1.8.1 (fc21)
--format does not know about container names.

docker ps --format "{{.ID}}\t{{.Image}}\t{{.CreatedAt}}\t{{.RunningFor}}\t{{.Status}}\t{{.Name}}" -a
Template parsing error: template: :1:64: executing "" at <.Name>: Name is not a field of struct type *ps.containerContext

So far using:
docker ps -a | perl -ne 'chomp; @cols = split /\s{2,}/, $_; $name=pop @cols; printf "%-28s %-20s %-20s %-30s\n", $name, $cols[1], $cols[3], $cols[4]'

parf commented Sep 8, 2015

Problem in docker 1.8.1 (fc21)
--format does not know about container names.

docker ps --format "{{.ID}}\t{{.Image}}\t{{.CreatedAt}}\t{{.RunningFor}}\t{{.Status}}\t{{.Name}}" -a
Template parsing error: template: :1:64: executing "" at <.Name>: Name is not a field of struct type *ps.containerContext

So far using:
docker ps -a | perl -ne 'chomp; @cols = split /\s{2,}/, $_; $name=pop @cols; printf "%-28s %-20s %-20s %-30s\n", $name, $cols[1], $cols[3], $cols[4]'

@calavera

This comment has been minimized.

Show comment
Hide comment
@GottZ

This comment has been minimized.

Show comment
Hide comment
@GottZ

GottZ Oct 23, 2015

thanks to @caiguanhao for inspiration.

i'm just leaving this here:

IMAGE                                NAMES                     STATUS              PORTS
xxxxx:x.x                            xx_xxxxxxxx_xxxxx         Up About an hour    10.23.123.111:26002->6379/tcp
xxxxxxxxx:x.x                        xx_xxxxxxxx_xxxxxxxxx     Up About an hour    29015/tcp
                                                                                   10.23.123.111:26001->8080/tcp
                                                                                   10.23.123.111:26000->28015/tcp
xxxxxxxx_xx_xxxxxxxx                 xx_xxxxxxxx               Up About an hour    127.0.0.1:8086->8080/tcp
xxxxxx_xx                            xx_xxx_xxx                Up About an hour    127.0.0.1:8082->8888/tcp
xxx_xx                               xx_xxx                    Up About an hour    127.0.0.1:8083->8080/tcp
xxxx/xxxxxxxxx-xxxxxx                xx_xxx_xxxxxxxxx_xxx      Up 2 hours          10.23.123.111:25002->25565/tcp
xxxx/xxxxxxxxx-xxxxxx                xx_xxx_xxxxxxxxx_xxxxxx   Up 2 hours          10.23.123.111:25001->25565/tcp
xxxxxx/xxxxxxxx:xxxxxx               xxx_xxxxxxxx              Up 3 hours          127.0.0.1:8080->8080/tcp
xxxxxxxxxx/xxxxxxx                   xxx_xxxxxxx               Up 3 hours          10.23.123.111:25->25/tcp
                                                                                   10.23.123.111:587->587/tcp
xx_xxx                               xx_xx                     Up 3 hours          10.23.123.112:9987->9987/tcp
                                                                                   10.23.123.112:10011->10011/tcp
                                                                                   10.23.123.112:30033->30033/tcp
                                                                                   10.23.123.112:9987->9987/udp
xxxx.xx/xxxxxxxxx/xxxxxx:x.x.x       xxx_xxxxxx                Up 3 hours          10.42.241.123:22->22/tcp
                                                                                   443/tcp
                                                                                   127.0.0.1:8000->80/tcp
xxxxxx/xxxxxx-xxxxxx:xxxxxx          xxx_xxxxxx_xx_xxxxxx      Up 3 hours
xxxx.xx/xxxxxxxxx/xxxxxxxxxx:x.x-x   xxx_xxxxxx_xxxxxxxx       Up 3 hours          5432/tcp
xxxx.xx/xxxxxxxxx/xxxxx:xxxxxx       xxx_xxxxxx_xxxxx          Up 3 hours          6379/tcp

/etc/profile.d/dps.sh: https://gist.github.com/GottZ/4a6c2af314d73cd8b71d

GottZ commented Oct 23, 2015

thanks to @caiguanhao for inspiration.

i'm just leaving this here:

IMAGE                                NAMES                     STATUS              PORTS
xxxxx:x.x                            xx_xxxxxxxx_xxxxx         Up About an hour    10.23.123.111:26002->6379/tcp
xxxxxxxxx:x.x                        xx_xxxxxxxx_xxxxxxxxx     Up About an hour    29015/tcp
                                                                                   10.23.123.111:26001->8080/tcp
                                                                                   10.23.123.111:26000->28015/tcp
xxxxxxxx_xx_xxxxxxxx                 xx_xxxxxxxx               Up About an hour    127.0.0.1:8086->8080/tcp
xxxxxx_xx                            xx_xxx_xxx                Up About an hour    127.0.0.1:8082->8888/tcp
xxx_xx                               xx_xxx                    Up About an hour    127.0.0.1:8083->8080/tcp
xxxx/xxxxxxxxx-xxxxxx                xx_xxx_xxxxxxxxx_xxx      Up 2 hours          10.23.123.111:25002->25565/tcp
xxxx/xxxxxxxxx-xxxxxx                xx_xxx_xxxxxxxxx_xxxxxx   Up 2 hours          10.23.123.111:25001->25565/tcp
xxxxxx/xxxxxxxx:xxxxxx               xxx_xxxxxxxx              Up 3 hours          127.0.0.1:8080->8080/tcp
xxxxxxxxxx/xxxxxxx                   xxx_xxxxxxx               Up 3 hours          10.23.123.111:25->25/tcp
                                                                                   10.23.123.111:587->587/tcp
xx_xxx                               xx_xx                     Up 3 hours          10.23.123.112:9987->9987/tcp
                                                                                   10.23.123.112:10011->10011/tcp
                                                                                   10.23.123.112:30033->30033/tcp
                                                                                   10.23.123.112:9987->9987/udp
xxxx.xx/xxxxxxxxx/xxxxxx:x.x.x       xxx_xxxxxx                Up 3 hours          10.42.241.123:22->22/tcp
                                                                                   443/tcp
                                                                                   127.0.0.1:8000->80/tcp
xxxxxx/xxxxxx-xxxxxx:xxxxxx          xxx_xxxxxx_xx_xxxxxx      Up 3 hours
xxxx.xx/xxxxxxxxx/xxxxxxxxxx:x.x-x   xxx_xxxxxx_xxxxxxxx       Up 3 hours          5432/tcp
xxxx.xx/xxxxxxxxx/xxxxx:xxxxxx       xxx_xxxxxx_xxxxx          Up 3 hours          6379/tcp

/etc/profile.d/dps.sh: https://gist.github.com/GottZ/4a6c2af314d73cd8b71d

@thaJeztah

This comment has been minimized.

Show comment
Hide comment
@thaJeztah

thaJeztah Oct 24, 2015

Member

Nice @GottZ, thanks for sharing!

Member

thaJeztah commented Oct 24, 2015

Nice @GottZ, thanks for sharing!

@GottZ

This comment has been minimized.

Show comment
Hide comment
@GottZ

GottZ Oct 24, 2015

@thaJeztah i just made each even line bold for better visibility. have fun 😄

GottZ commented Oct 24, 2015

@thaJeztah i just made each even line bold for better visibility. have fun 😄

@danidelvalle

This comment has been minimized.

Show comment
Hide comment
@danidelvalle

danidelvalle Dec 18, 2015

Meanwhile, my approach with awk:

$ alias my_docker_ps="docker ps | awk 'BEGIN{FIELDWIDTHS = \"20 33 23 20 20 70 20\"}{print \$1,\$2,\$5,\$7}'"

$ my_docker_ps         
CONTAINER ID         IMAGE                             STATUS               NAMES
b83fe9a6a06e         kibana                            Up 32 minutes        kibana              
4d78b9cd2bed         elasticsearch                     Up About an hour     evil_feynman        
fbbc40a49569         mattermost/platform               Up 9 weeks           mattermost-dev      
3b4dd9d00305         outcoldman/splunk:latest          Up 9 weeks           boring_yalow           

Meanwhile, my approach with awk:

$ alias my_docker_ps="docker ps | awk 'BEGIN{FIELDWIDTHS = \"20 33 23 20 20 70 20\"}{print \$1,\$2,\$5,\$7}'"

$ my_docker_ps         
CONTAINER ID         IMAGE                             STATUS               NAMES
b83fe9a6a06e         kibana                            Up 32 minutes        kibana              
4d78b9cd2bed         elasticsearch                     Up About an hour     evil_feynman        
fbbc40a49569         mattermost/platform               Up 9 weeks           mattermost-dev      
3b4dd9d00305         outcoldman/splunk:latest          Up 9 weeks           boring_yalow           
@thaJeztah

This comment has been minimized.

Show comment
Hide comment
@thaJeztah

thaJeztah Dec 18, 2015

Member

@danidelvalle why not simply;

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

thaJeztah commented Dec 18, 2015

@danidelvalle why not simply;

docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}"
@ovidiub13

This comment has been minimized.

Show comment
Hide comment
@ovidiub13

ovidiub13 Dec 18, 2015

This has already been committed and released. I don't understand, why is this still open?

This has already been committed and released. I don't understand, why is this still open?

@danidelvalle

This comment has been minimized.

Show comment
Hide comment
@danidelvalle

danidelvalle Dec 18, 2015

@thaJeztah you're right, thanks :)

@thaJeztah you're right, thanks :)

@thaJeztah

This comment has been minimized.

Show comment
Hide comment
Member

thaJeztah commented Dec 18, 2015

@ovidiub13 mainly because of #7477 (comment)

@thomasf

This comment has been minimized.

Show comment
Hide comment
@thomasf

thomasf Jan 11, 2016

Contributor

yeah this is annoying..

I'm usually fine with just truncating the default ps at the terminal colum width:

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

thomasf commented Jan 11, 2016

yeah this is annoying..

I'm usually fine with just truncating the default ps at the terminal colum width:

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

This comment has been minimized.

Show comment
Hide comment
@igr

igr Jan 13, 2016

+1 for --columns=name,id,status,image

igr commented Jan 13, 2016

+1 for --columns=name,id,status,image

@Pithikos

This comment has been minimized.

Show comment
Hide comment
@Pithikos

Pithikos Feb 1, 2016

This issue still exists unfortunately. Anyhow a workaround is to put the below (tested in Ubuntu) in your .bashrc:

CMD_WATCHDOCKER="watch \"docker ps -q | xargs docker inspect --format '{{.Id}} @{{.Config.Image}} @{{.Config.Cmd}} @{{range \\\$p, \\\$conf := .NetworkSettings.Ports}}{{\\\$p}}->{{(index \\\$conf 0).HostPort}}{{end}} @{{.NetworkSettings.IPAddress}}' | column -t -s='@' | cut -c 1-5,64-\""
alias watchdocker='eval $CMD_WATCHDOCKER'

Running watchdocker gives:

4596c3   ruby:2.2.2   [bash]                        172.17.0.82
827ca9   postgres     [postgres]   5432/tcp->5432   172.17.0.72

Pithikos commented Feb 1, 2016

This issue still exists unfortunately. Anyhow a workaround is to put the below (tested in Ubuntu) in your .bashrc:

CMD_WATCHDOCKER="watch \"docker ps -q | xargs docker inspect --format '{{.Id}} @{{.Config.Image}} @{{.Config.Cmd}} @{{range \\\$p, \\\$conf := .NetworkSettings.Ports}}{{\\\$p}}->{{(index \\\$conf 0).HostPort}}{{end}} @{{.NetworkSettings.IPAddress}}' | column -t -s='@' | cut -c 1-5,64-\""
alias watchdocker='eval $CMD_WATCHDOCKER'

Running watchdocker gives:

4596c3   ruby:2.2.2   [bash]                        172.17.0.82
827ca9   postgres     [postgres]   5432/tcp->5432   172.17.0.72
@cpuguy83

This comment has been minimized.

Show comment
Hide comment
@cpuguy83

cpuguy83 Feb 1, 2016

Contributor

@Pithikos docker ps--format '{{ .ID }}\t{{ .Image }}\t{{ .Command }}\t{{ .Ports }}' will give you this without making all those API calls for each container.
Also you can put this into ~/.docker/config.json to make it the default format

Contributor

cpuguy83 commented Feb 1, 2016

@Pithikos docker ps--format '{{ .ID }}\t{{ .Image }}\t{{ .Command }}\t{{ .Ports }}' will give you this without making all those API calls for each container.
Also you can put this into ~/.docker/config.json to make it the default format

@Pithikos

This comment has been minimized.

Show comment
Hide comment
@Pithikos

Pithikos Feb 1, 2016

@cpuguy83 which version does support this? I never managed to get this working, neither at work or home. Would be cool if in the docs it was mentioned which version supports what.

Pithikos commented Feb 1, 2016

@cpuguy83 which version does support this? I never managed to get this working, neither at work or home. Would be cool if in the docs it was mentioned which version supports what.

@cpuguy83

This comment has been minimized.

Show comment
Hide comment
@cpuguy83

cpuguy83 Feb 1, 2016

Contributor

@Pithikos Either 1.8 or 1.9, not sure.

Contributor

cpuguy83 commented Feb 1, 2016

@Pithikos Either 1.8 or 1.9, not sure.

@TheOriginalAlex

This comment has been minimized.

Show comment
Hide comment

#dibs

@sigzegv

This comment has been minimized.

Show comment
Hide comment
@sigzegv

sigzegv Jun 16, 2016

correct usge is with "table" keyword in format string, this will give you nice spaced formatting docker ps -a --format="table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Command}}\t{{.Status}}"

sigzegv commented Jun 16, 2016

correct usge is with "table" keyword in format string, this will give you nice spaced formatting docker ps -a --format="table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Command}}\t{{.Status}}"

@icecrime

This comment has been minimized.

Show comment
Hide comment
@icecrime

icecrime Sep 10, 2016

Contributor

I'm closing this one as it seems that the --format flag for ps is addressing the issue. Thanks all!

Contributor

icecrime commented Sep 10, 2016

I'm closing this one as it seems that the --format flag for ps is addressing the issue. Thanks all!

@icecrime icecrime closed this Sep 10, 2016

@icecrime icecrime added area/cli and removed status/claimed labels Sep 10, 2016

@bfirsh

This comment has been minimized.

Show comment
Hide comment
@bfirsh

bfirsh Sep 12, 2016

Contributor

This issue was perhaps not well named. It still remains that the default for commands should be 80 chars wide. Happy for this to be closed though because it's not that important.

Contributor

bfirsh commented Sep 12, 2016

This issue was perhaps not well named. It still remains that the default for commands should be 80 chars wide. Happy for this to be closed though because it's not that important.

@zx1986

This comment has been minimized.

Show comment
Hide comment
@cmingxu

This comment has been minimized.

Show comment
Hide comment
@cmingxu

cmingxu Oct 22, 2016

how about add option to make result display vertically, like select * from foobar\G in MySQL

cmingxu commented Oct 22, 2016

how about add option to make result display vertically, like select * from foobar\G in MySQL

@joshmedeski

This comment has been minimized.

Show comment
Hide comment
@joshmedeski

joshmedeski Nov 29, 2016

I usually just want to know which containers are running (and for how long).

This does the trick for me:

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

Even better, I wrapped it in a really easy to remember alias:

alias dps='docker ps --format "table {{.Names}}\t{{.Status}}"'

Here's a sample of the output:

NAMES                     STATUS
projectxyz_chrome_1       Up 11 minutes
projectxyz_web_1          Up 11 minutes
projectxyz_app_1          Up 11 minutes
projectxyz_phpmyadmin_1   Up 11 minutes
projectxyz_memcached_1    Up 11 minutes
projectxyz_db_1           Up 11 minutes

You can learn more about the --format command here:
https://docs.docker.com/engine/reference/commandline/ps/

Hope it helps someone 😃

joshmedeski commented Nov 29, 2016

I usually just want to know which containers are running (and for how long).

This does the trick for me:

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

Even better, I wrapped it in a really easy to remember alias:

alias dps='docker ps --format "table {{.Names}}\t{{.Status}}"'

Here's a sample of the output:

NAMES                     STATUS
projectxyz_chrome_1       Up 11 minutes
projectxyz_web_1          Up 11 minutes
projectxyz_app_1          Up 11 minutes
projectxyz_phpmyadmin_1   Up 11 minutes
projectxyz_memcached_1    Up 11 minutes
projectxyz_db_1           Up 11 minutes

You can learn more about the --format command here:
https://docs.docker.com/engine/reference/commandline/ps/

Hope it helps someone 😃

@thaJeztah

This comment has been minimized.

Show comment
Hide comment
@thaJeztah

thaJeztah Nov 29, 2016

Member

@joshmedeski you can also store your preferred formatting in a configuration file, so that it is used as default; https://docs.docker.com/engine/reference/commandline/cli/#/configuration-files

Member

thaJeztah commented Nov 29, 2016

@joshmedeski you can also store your preferred formatting in a configuration file, so that it is used as default; https://docs.docker.com/engine/reference/commandline/cli/#/configuration-files

@andyheath

This comment has been minimized.

Show comment
Hide comment
@andyheath

andyheath Jan 21, 2018

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

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

This comment has been minimized.

Show comment
Hide comment
@danielfaust

danielfaust Jan 26, 2018

#!/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)
#!/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

This comment has been minimized.

Show comment
Hide comment
@mrt123

mrt123 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)

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)

@ain ain referenced this issue Feb 21, 2018

Open

docker.json #33

@gitnik

This comment has been minimized.

Show comment
Hide comment
@gitnik

gitnik Apr 24, 2018

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

gitnik commented Apr 24, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment