Debug option to print log output of compose containers
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
- Create a docker compose setup with a container that fails to start
- Start docker compose environment with
DockerComposeEnvironment(composeFilePath, fileName).up(); - Observe the lack of container logs
Environment Information
- Operating System: Linux
- Docker Version: 24.0.7
- Node version: 16
- Testcontainers version: 10.2.1
Sounds like a great addition, thanks for raising @jalaziz
+1 for this.
PR welcome
This is already supported
@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.
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
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?