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

stderr merged into stdout when using a tty #25542

Closed
bamarni opened this issue Aug 9, 2016 · 6 comments
Closed

stderr merged into stdout when using a tty #25542

bamarni opened this issue Aug 9, 2016 · 6 comments

Comments

@bamarni
Copy link
Contributor

bamarni commented Aug 9, 2016

Output of docker version:

Client:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Sat Jul 30 03:04:21 UTC 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 23:54:00 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 12
 Running: 0
 Paused: 0
 Stopped: 12
Images: 211
Server Version: 1.12.0
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 317
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 4.4.16-boot2docker
Operating System: Boot2Docker 1.12.0 (TCL 7.2); HEAD : e030bab - Fri Jul 29 00:29:14 UTC 2016
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 492.3 MiB
Name: dev
ID: C5GS:YWWS:SOBV:I73L:HHNI:M76S:RXXE:LJ3V:3EEU:UHGY:VSWH:KDNC
Docker Root Dir: /mnt/sda1/var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 13
 Goroutines: 24
 System Time: 2016-08-09T16:45:17.684558238Z
 EventsListeners: 0
Username: bamarni
Registry: https://index.docker.io/v1/
Labels:
 provider=virtualbox
Insecure Registries:
 127.0.0.0/8

Steps to reproduce the issue:

  1. docker run -t --rm debian:jessie bash -c "echo stdout && echo stderr >&2" 2>/dev/null

Describe the results you received:

stdout
stderr

Describe the results you expected:

I expected to only see stdout, but stderr seems to be merged with it, because of the tty option?

@cpuguy83
Copy link
Member

cpuguy83 commented Aug 9, 2016

Yes, the tty multiplexes stdout and stderr onto a single stream.

This is the normal behavior of a tty.

@cpuguy83 cpuguy83 closed this as completed Aug 9, 2016
@bamarni
Copy link
Contributor Author

bamarni commented Aug 9, 2016

Thanks for the quick reply. Even though this is the normal behaviour of a tty, I reported it mostly because it felt like an unexpected behaviour of docker. Especially when using cli tools in development environment, it is sometimes useful to distinguish between stdout and stderr, but depending on the -t option docker will either merge stderr into stdout or keep them separate.

Then I don't know if / how this behaviour could be changed in docker, maybe having 2 separate ttys?

@cpuguy83
Copy link
Member

cpuguy83 commented Aug 9, 2016

@bamarni The solution would really be to not include -t unless you need it... and unless you are going to be physically behind a keyboard typing into a terminal you probably don't need a tty.

@bamarni
Copy link
Contributor Author

bamarni commented Aug 9, 2016

In development environment I always add the -t flag because I'm using helper scripts, for example here (https://github.com/bamarni/dotfiles/blob/master/bin/php-bin).

When running this script indeed I won't always need to type something, nor need the ssh agent forwarding, but it happens often. It'd really be time consuming to type the minimal docker command required just to run a cli tool in development, that's why I opted for full-featured helper scripts.

@dnephin
Copy link
Member

dnephin commented Aug 9, 2016

How about this:

tty=""
if [ -t 1 ] ; then
  tty="-t"
fi

docker run -i $tty --rm  ...

(http://stackoverflow.com/questions/911168/how-to-detect-if-my-shell-script-is-running-through-a-pipe)

@bamarni
Copy link
Contributor Author

bamarni commented Aug 9, 2016

Thanks @dnephin, very interesting idea. I'll give it a shot and post here again if I find some edge cases, hopefully not 😺

xy2i added a commit to xy2i/sudo-rs that referenced this issue Aug 13, 2023
Docker merges stderr into stdout when `--tty` is set [1].

This was the only test I found with this case.

[1]: moby/moby#25542
xy2i added a commit to xy2i/sudo-rs that referenced this issue Aug 13, 2023
Docker merges stderr into stdout when `--tty` is set [1].

This was the only test I found with this case.

[1]: moby/moby#25542
xy2i added a commit to xy2i/sudo-rs that referenced this issue Aug 13, 2023
Docker merges stderr into stdout when `--tty` is set [1].

This was the only test I found with this case.

[1]: moby/moby#25542
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants