[Bug]: Docker-Compose, LogConsumer & service restart
Module
Core
Testcontainers version
1.17.3
Using the latest Testcontainers version?
Yes
Host OS
Linux
Host Arch
x86
Docker version
Client: Docker Engine - Community
Version: 20.10.18
API version: 1.41
Go version: go1.18.6
Git commit: b40c2f6
Built: Thu Sep 8 23:11:43 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.18
API version: 1.41 (minimum version 1.12)
Go version: go1.18.6
Git commit: e42327a
Built: Thu Sep 8 23:09:30 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
What happened?
I use TestContainers to start Docker Compose and follow logs of services to files. When a service crashes and automatically restarts - which happens a lot on start-up as our test stack is not yet stable -, logs are not followed anymore. Here's a snippet of my code:
DockerComposeContainer<?> environment = new DockerComposeContainer<>(name + "_", composeFiles);
serviceNames.forEach(service -> environment.withLogConsumer(service, outputFrame -> writeLog(service, outputFrame.getBytes())));
whereas:
nameis a simpleString, representing the role of the Docker Compose.composeFilesis a list ofFilepointing to our Docker Compose files - usually, we use a single file there.serviceNamesis a list ofString, representing the services declared in our Docker Compose files we'd like to log output.writeLogis a simple utility method that writes logs in some accessible file, depending on the service name.
Is there something I could do to mitigate the issue - to keep getting logs followed to my files?
Note: I can't simply dump docker logs <service> at the end of my tests, as I follow logs to achieve 2 goals:
- If a test crashes, then I still get the full logs of all my services.
- I have to change output files during execution, so getting logs line by line makes it easy to do.
Relevant log output
No response
Additional Information
No response
Thanks for the issue report. So your set of services is in general resilient and will eventually reach the correct running state, correct?
I would recommend configuring a set of WaitStrategies that allow the DockerComposeContainer to reach the stable state before attaching the LogConsumer. I am quite confident that this will work and make the issue irrelevant.
Thanks for the quick reply! That would be a solution for my personal case. However, I think this case could be extended. As an example, what if people want to test the behavior of a service when it is restarted? They should get all the logs which I think is hard to do as of now.
That is exactly the use case we are looking for. Grab a service from docker-compose and restart it, or even better: stop it, do some checks, start it again.