ory / dockertest

Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.
https://www.ory.sh/?utm_source=github&utm_medium=banner&utm_campaign=dockertest
Apache License 2.0
4.1k stars 243 forks source link

stderr does not appear in docker logs of container started with dockertest #529

Closed pjh closed 1 week ago

pjh commented 1 week ago

Preflight checklist

Ory Network Project

No response

Describe the bug

Containers started with dockertest do not correctly capture output written to stderr. Running docker logs against the container only shows output written to stdout, not to stderr. When the same container is started using the docker CLI, stderr is shown in the docker logs output as expected.

I searched the dockertest package documentation and the code pretty thoroughly for mentions of stderr, stdout etc. but I couldn't find any configurations to change that would affect this behavior.

Reproducing the bug

See https://github.com/ory/dockertest/compare/v3...pjh:dockertest:demo-stderr for the code changes needed to reproduce this issue.

To observe the non-dockertest behavior, run:

  1. docker buildx build . -t stderr
  2. CONTAINER=$(docker run -d stderr:latest)
  3. docker logs $CONTAINER

The output contains both stderr and stdout:

error to stderr
output to stdout

To observe the docketest behavior, run:

  1. go test -C internal/pjh/ -v

The output contains stdout but not stderr:

docker logs for container b48fd6fd140ac27cbfc1ccc49f669246c05974ed717b7dcbc1d6c7d559e72e02:
output to stdout

=== RUN   TestSomething
--- PASS: TestSomething (0.00s)
PASS
ok      github.com/ory/dockertest/v3/internal/pjh       2.856s

Relevant log output

No response

Relevant configuration

No response

Version

github.com/ory/dockertest/v3 v3.11.0

On which operating system are you observing this issue?

None

In which environment are you deploying?

None

Additional Context

No response

pjh commented 1 week ago

I also looked through https://pkg.go.dev/github.com/docker/docker/client and https://github.com/moby/moby/tree/master/client for "stderr" but didn't see any obvious places to adjust this. But surely there must be a way, since the docker CLI also uses that library and results in the expected behavior. Right?

pjh commented 1 week ago

Nevermind 🤦 I didn't realize that the docker logs command emits the container's stdout to stdout and the container's stderr to stderr, I thought everything just went to stdout where the command is run. After using dockertest I was only reading the stdout from a docker logs command.