title: Why does docker pseudo-tty mangle output when piped to other command?
body: <p>Why does pseudo-tty option in docker modify output when docker output is piped to other commands?</p>
  
  <p>Docker uses <code>CRLF</code> line endings when run with <code>-t</code> option. So here's my 2 commands with <code>CR</code> added to other one to make their outputs identical.</p>
  
  <pre><code>❯ docker run --rm -ti bash bash -c "echo -n $'\n\n\n'" | od -c
  0000000  \r  \n  \r  \n  \r  \n
  
  ❯ docker run --rm bash bash -c "echo -n $'\r\n\r\n\r\n'" | od -c
  0000000  \r  \n  \r  \n  \r  \n
  </code></pre>
  
  <p>Both commands piped to while read -loop (I'd expect both outputs to be identical)</p>
  
  <pre><code>❯ while read -r out; do echo A; done &lt; &lt;(docker run --rm -ti bash bash -c "echo -n $'\n\n\n'")
  A
   A
    A
  
  ❯ while read -r out; do echo A; done &lt; &lt;(docker run --rm bash bash -c "echo -n $'\r\n\r\n\r\n'")
  A
  A
  A
  </code></pre>
  
  <p>Why does this happen? Why does pseudo-tty break output? Shouldn't it only tell docker that input is terminal device?</p>
  
  <p>Of course not using <code>-it</code> for non-interactive scripts is a valid solution for this, but doesn't answer 'why'.</p>