Docker Community Forums

Share and learn in the Docker community.

Docker run with colorful output


Is there a way to make the docker run command with colorful output?

docker run --rm ubuntu:16.04 ls --color=auto
docker run --rm ubuntu:16.04 bash -c 'TERM=xterm-256color ls --color=auto'
1 Like

Probably not what you were thinking, but…


I think the OP was looking for something more Docker-specific, like

docker run --rm supertest2014/nyan

More usefully, it totally depends on what software is built into the image. If the image in question happens to have GNU coreutils, then ls --color will probably work; but note that it depends on knowing that its output is a tty, which means also using the docker run -t option.

docker run --rm -it ubuntu:16.04 ls --color=auto /

There are also several images built on Alpine or Busybox out there, which may not have such a full-featured /bin/ls (because do you actually need color-enabled ls to run, say, a single-purpose Web service?), or which may even not have a /bin/ls at all.

@patricknw @dmaze Thank you!

I am able to do this by using ‘-t’ option in docker run command such as:

docker run -t --rm ubuntu:16.04 ls --color=auto

That makes sense. You’d need to have it acting as a pseudo-TTY in order for it to allocate terminal resources.

1 Like