FIX docker ps (List containers) uses screen width, should use window width #30050

Closed
allanlaal opened this Issue Jan 11, 2017 · 3 comments

Projects

None yet

3 participants

@allanlaal

Description:

when using docker ps on a terminal window that is less than screen width, the output does not look pretty

How to reproduce:

  1. open up a terminal (tested on mate-terminal on Ubuntu Mate 16.04 LTS)
  2. make the terminal windows width less than the screen (half even)
  3. run command: docker ps

Expected result

output is formatted so each container is on 1 row:

CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                       NAMES
091ed00a9226        webdevops/php-apache:centos-7   "/opt/docker/bin/entr"   12 days ago         Up 20 seconds       80/tcp, 443/tcp, 9000/tcp   ps.c.xxxxxxxxx.www.2016-12-29
bee109752240        mysql:5.6.34                    "docker-entrypoint.sh"   12 days ago         Up 34 seconds       3306/tcp                    ps.c.xxxxxxxxx.db.2016-12-29
d2d217622de8        webdevops/php-apache:centos-7   "/opt/docker/bin/entr"   8 weeks ago         Up 6 seconds        80/tcp, 443/tcp, 9000/tcp   infra.ais.core.www.2016-11-08
bb422c0b9bf3        mysql:5.5.53        

Actual result:

output is formatted as if the terminal windows width is the same as the screens:

CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                       NAMES
0912200a22f6        webdevops/php-apache:centos-7   "/opt/docker/bin/entr"   12 days ago         Up 20 seconds       80/tcp, 443/tcp, 9000/tcp   ps.c.xxxxxxxxx.
www.2016-12-29
bee109752240        mysql:5.6.34                    "docker-entrypoint.sh"   12 days ago         Up 34 seconds       3306/tcp                    ps.c.xxxxxxxxx.
db.2016-12-29
d2d217622de8        webdevops/php-apache:centos-7   "/opt/docker/bin/entr"   8 weeks ago         Up 6 seconds        80/tcp, 443/tcp, 9000/tcp   infra.ais.core.
www.2016-11-08     
bb422c0b9bf3        mysql:5.5.53                    "docker-entrypoint.sh"   8 weeks ago         Up 6 seconds        3306/tcp                    infra.ais.core.
db.2016-11-13
@thaJeztah
Member
thaJeztah commented Jan 11, 2017 edited

I don't think this is possible; it's the terminal wrapping the output, and the same is true for any command. For example; running this in a 80-character wide terminal;

$ mkdir -p test && cd test
$ touch somelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnam
esomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelon
gnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongname
$ ls -la
total 8
drwxr-xr-x 2 root root 4096 Jan 11 11:38 .
drwxr-xr-x 1 root root 4096 Jan 11 11:37 ..
-rw-r--r-- 1 root root    0 Jan 11 11:38 somelongnamesomelongnamesomelongnamesom
elongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnam
esomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelon
gnamesomelongname

When resizing the terminal; the output is re-wrapped;

$ ls -la
total 8
drwxr-xr-x 2 root root 4096 Jan 11 11:38 .
drwxr-xr-x 1 root root 4096 Jan 11 11:37 ..
-rw-r--r-- 1 root root    0 Jan 11 11:38 somelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomel
ongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongnamesomelongname

Truncating the output would be possible but result in information getting lost to the user, and truncating at the terminal width (and monitor for change in width) would mean that the docker CLI would have to keep running (i.e. not terminate after the command was executed).

Note that you can disable wrapping in the terminal using;

tput rmam
$ tput rmam
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS  S
1c3b06698809        mysql:5.7.16        "docker-entrypoint..."   About an hour ago   Up About9

And re-enable with

tput smam
$ tput smam
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS   
              PORTS               NAMES
1c3b06698809        mysql:5.7.16        "docker-entrypoint..."   About an hour ago   Up About
 an hour    3306/tcp            repro-8119
@cpuguy83
Contributor

There are things that can be done (see the ps command), like collapsing certain columns or removing whitespace between columns.

Ultimately though, I personally don't need several of the columns, so I just specify a custom format in ~/.docker/config.json.
See http://container42.com/2016/03/27/docker-quicktip-7-psformat/

@thaJeztah
Member

I'm closing this issue because this is not something we can address, but hope the hints above are helpful for you; feel free to comment though after I closed

@thaJeztah thaJeztah closed this Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment