Skip to content

Separate STDERR and STDOUT in docker compose output #8098

Closed
@raiyanyahya

Description

@raiyanyahya

Is your feature request related to a problem? Please describe.
Docker compose outputs container stderr output to stdout
Refer to the sample below:
docker-compose.yml :

version: "3.3"
services:
  stderr:
    image: alpine
    command: /bin/ash /log_to_stderr.sh
    volumes:
           - ./log_to_stderr.sh:/log_to_stderr.sh

log_to_stderr.sh:

>&2 echo "log to stderr"
echo "log to stdout"

Running the bash script separately we get the output:

❯ ./log_to_stderr.sh 2> /dev/null
log to stdout

BUT
when running docker-compose we get:

❯ docker-compose up 2> /dev/null
Attaching to composeissue_stderr_1
stderr_1  | log to stderr
stderr_1  | log to stdout
composeissue_stderr_1 exited with code 0

Note:
Just running the image with docker seems to give us the expected behaviour:

❯ docker run --rm -v ${PWD}/log_to_stderr.sh:/log_to_stderr.sh alpine /bin/ash /log_to_stderr.sh 2> /dev/null 
log to stdout

Describe the solution you'd like
Docker compose should use the same output stream as the container.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions