today i was struggling to understand what was going on with my ~simple application, that was printing some JSONs on the screen. seemingly all good when testing, when i ran it in an actual environment, it turned out that there's something off with new lines formatting. after quite some digging i realized the problem was due to me calling it via docker
. to simplify it a bit, let's say all it did was echo x
on the screen, i.e.:
$ echo x | hexdump -C 00000000 78 0a |x.| 00000002
but then:
$ docker run -it --rm debian:12 echo x | hexdump -C 00000000 78 0d 0a |x..| 00000003
who ordered the \r\n
instead of \n
?!
to make it harder to spot, it all worked fine when printing on the screen – it was only causing issues when pipe-ing, e.g. docker … echo x | grep …
, as EOLs were not interpreted correctly there…
after more digging it turned out, that the problem was -t
flag (i.e. enable terminal). after removing it:
$ docker run -i --rm debian:12 echo x | hexdump -C 00000000 78 0a |x.| 00000002
my problem went away.
up until now i always added -t
every time i needed interactive input (-i
). today i learned that it's more nuanced…