From docker run --help:
-t, --tty Allocate a pseudo-TTY
Very nice. I use that to get color output automatically. The problem is, it also redirects stderr to stdout.
Without -t, stderr isn't redirected, which is what I want:
$ docker run ubuntu ls /aaaaaa
ls: cannot access '/aaaaaa': No such file or directory
$ docker run ubuntu ls /aaaaaa 2> /dev/null
With -t, the error messages are redirected to stdout:
$ docker run -t ubuntu ls /aaaaaa
ls: cannot access '/aaaaaa': No such file or directory
$ docker run -t ubuntu ls /aaaaaa 2> /dev/null
ls: cannot access '/aaaaaa': No such file or directory
$ docker run -t ubuntu ls /aaaaaa > /dev/null
Why is that? Is there a way to still allocate a pseudo-TTY and keep stderr separate?
e.g. I want to run something like this in CI:
docker run ... my-command > out.json
while the logger shows warnings and error messages in color.