testcontainers / testcontainers/testcontainers-java

[Bug]: Docker-Compose, LogConsumer & service restart

Open
#5,868 3 comments 0 reactions 1 assignee View on GitHub

@kiview is already working on this.

Since Sep 28, 2022.

area/docker-compose type/bug
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:

  • name is a simple String, representing the role of the Docker Compose.
  • composeFiles is a list of File pointing to our Docker Compose files - usually, we use a single file there.
  • serviceNames is a list of String, representing the services declared in our Docker Compose files we'd like to log output.
  • writeLog is 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:

  1. If a test crashes, then I still get the full logs of all my services.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.