testcontainers-node icon indicating copy to clipboard operation
testcontainers-node copied to clipboard

Debug option to print log output of compose containers

Open jalaziz opened this issue 2 years ago • 3 comments

Expected Behaviour

When using DEBUG="testcontainers*", DEBUG=testcontainers:containers, or DEBUG=testcontainers:compose we should see the output of containers started via Docker Compose.

Actual Behaviour

Compose build and higher-level logs are printed, but container logs are not. This is particularly annoying when trying to debug why a container is failing to start. The logs will indicate that the container failed to start, but won't print any logs from the container.

Testcontainer Logs ...

Steps to Reproduce

  1. Create a docker compose setup with a container that fails to start
  2. Start docker compose environment with DockerComposeEnvironment(composeFilePath, fileName).up();
  3. Observe the lack of container logs

Environment Information

  • Operating System: Linux
  • Docker Version: 24.0.7
  • Node version: 16
  • Testcontainers version: 10.2.1

jalaziz avatar Dec 06 '23 22:12 jalaziz

Sounds like a great addition, thanks for raising @jalaziz

cristianrgreco avatar Dec 07 '23 16:12 cristianrgreco

+1 for this.

wimdeblauwe avatar May 03 '24 09:05 wimdeblauwe

PR welcome

cristianrgreco avatar May 03 '24 09:05 cristianrgreco

This is already supported

cristianrgreco avatar Jul 18 '24 08:07 cristianrgreco

@cristianrgreco maybe I'm missing something, but where is this supported? Or was it a recent addition?

To clarify, the issue here is with using a docker compose environment.

DEBUG and other logging mechanisms work when running a single container, but they don't seem to work for container logs when running through a compose environment.

jalaziz avatar Jul 23 '24 18:07 jalaziz

Logs from compose itself can be enabled with DEBUG=testcontainers:compose. Logs from the containers upped by compose can be enabled with DEBUG=testcontainers:containers: https://github.com/testcontainers/testcontainers-node/blob/824cd8dbac0615ae00a83d82e8625a108b885ecb/packages/testcontainers/src/docker-compose-environment/docker-compose-environment.ts#L143-L147

cristianrgreco avatar Jul 24 '24 08:07 cristianrgreco

Ahh indeed. I now see the issue we are facing on occasion.

Container logs do work, but only after all containers have started successfully.

The issue we have been facing is that when a container fails to start for some reason and compose fails (due to a wait strategy or a service_healthy condition), no container logs are printed, making it very difficult to debug start up issues.

Maybe the solution is to log container output for any containers that fail to start / become healthy?

jalaziz avatar Jul 24 '24 08:07 jalaziz