In Docker Compose 1.5.1, I'm noticing that docker-compose run sends stderr from the running process to stdout of the process calling run. Is this intended?
This comment states that--
docker-compose prints informational messages to stderr, and container output to the same stream as it was written to in the container (stdout or stderr).
but this isn't what I'm observing.
Yeah, that's not quite accurate - we should document this.
By default, run creates a container with a pseudo-tty attached. This necessarily means that all output goes to stdout. You can disable this with the -T option, which will get you stdout/stderr mapping.
$ docker-compose run web sh -c "echo stdout; >&2 echo stderr" > /dev/null
$ docker-compose run web sh -c "echo stdout; >&2 echo stderr" 2> /dev/null
stdout
stderr
$ docker-compose run -T web sh -c "echo stdout; >&2 echo stderr" > /dev/null
stderr
$ docker-compose run -T web sh -c "echo stdout; >&2 echo stderr" 2> /dev/null
stdout
Great. Thanks so much for the explanation, @aanand. Should this issue be relabeled / left open as a documentation issue?
Yeah, I've reclassified it as a docs issue.
@aanand Hmm, so I tried the -T option with docker-compose run, and I'm seeing non-deterministic behavior. Sometimes stdout is captured, and other times it isn't.
Is this a known issue? Is there known flakiness when capturing stdout with -T? Thanks a lot.
That's not a known issue, no. We've had flakes of that kind in the past though. If you can produce a minimal failing case, please open a new issue for it.
Okay, thanks, @aanand. I'll open a separate issue, but I was able to reproduce with the following:
$ docker-compose run -T web python3 -c "import sys; print(\"err\\n\", file=sys.stderr); print(\"foo\\nfoo\\nfoo\\nfoo\\n\")"
Half the time "err" doesn't print, and 1 out of 8 times or so, the "foo" lines don't print.
Issue grooming: Docs now say:
-T Disable pseudo-tty allocation. By default `docker-compose run`
allocates a TTY.
which I think is what was being discussed. Closing.
Most helpful comment
Yeah, that's not quite accurate - we should document this.
By default,
runcreates a container with a pseudo-tty attached. This necessarily means that all output goes to stdout. You can disable this with the-Toption, which will get you stdout/stderr mapping.