testcontainers / testcontainers/testcontainers-java
[Bug]: Docker-Compose, LogConsumer & service restart
@kiview is already working on this.
Since Sep 28, 2022.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.