testcontainers / testcontainers/testcontainers-java
Improve logging when withReuse() is specified and a container cannot be reused.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
I would like to see a warning logged everytime a container is started withReuse(true) and the hash does not match.
Ideally the warning should contain details of the existing running containers, their container ids and mismatched hashes.
And if possible it would be REALLY helpful to have some details about why the hash didn't match. I realize from reading the code that this isn't possible currently given that the hash is computed from the CreateContainerCmd but maybe some comparisions would be performed of the InspectContainerResponse post container start, as compared to the existing containers.. It would probably make sense to log this level of detail at DEBUG or TRACE levels.
Right now we are facing issues where it's very easy to trigger new containers to be created when the intent was to reuse an existing container, and it's very easy to miss this happening in the logs unless you are paying special attention to it.
And once you've spotted it, it's very hard to troubleshoot why a new container was created vs an existing one being reused.
Sometimes it's some init-data that was updated so the files hash has changed, othertimes, it's something more subtle like a host bind path having a trailing / but otherwise being exactly the same.. This last issue has other implications, which probably warrants it's own ticket, but at the moment it's hard to gather all the evidence easily.. hence this ticket.
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.
Research direction
Start by tracing withReuse(true) through the container reuse path, then inspect how the CreateContainerCmd hash is compared with existing running containers. Review the available InspectContainerResponse details and logging points. Done means a reuse mismatch emits a warning with container IDs and hashes, with deeper comparison details at DEBUG or TRACE when available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- observability, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100