Skip to content

Logging output and newlines #114

@andyneff

Description

@andyneff

There seems to have been and issue with newlines being translated by tty "magic" in the past.

In the past, having a tty on docker compose caused the error. But more recently, not having a tty causes the issue.

First tackled on 90f743f, it stated sources such as:

  1. docker outputs to standard out with added carriage return character moby/moby#8513
  2. https://unix.stackexchange.com/a/242814/332869
  3. https://superuser.com/q/1326853/352118

Testing

A simple method to cause the issue is:

docker run -it --rm ubuntu:latest bash -c 'echo {\"a\":5}' | jq

If the error does not occur, you will see

{
  "a": 5
}

However, if it does occur you will see

{
   "a": 5
         }

The problem is able to be reproduced in windows, but only when using WSL as part of the experiment:

No error

Powershell: docker run -it --rm ubuntu:latest bash -c "echo -e '{\"a`":\n5}'" | jq
Command prompt: docker run -it --rm ubuntu:latest bash -c "echo '{"\""a"\"":5}'" | "c:\ProgramData\chocolatey\bin\jq.exe"
mingw: winpty bash; docker run -it --rm ubuntu:latest bash -c echo\ '{\"a\":5}' | jq
(Same results when using MS Terminal)

Error

WSL/Linux: docker run -it --rm ubuntu:latest bash -c echo\ '{\"a\":5}' | jq

Notes

It seems to have something to do with tty settings -opost or -onlcr sometimes, but the pattern is not clear, and sometimes doesn't involve them at all afaik. It's hard to tell for sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions