Docker Container Logging during Testing

Dear Docker Community,

I’m currently working on a project that involves multiple services (some distributed across a cluster like Elasticsearch) running inside Docker containers. The whole system can be started through a docker-compose file with custom setup if required. To validate these services against specific requirements, I’ve set up a separate test project.

We’ve developed a comprehensive test suite to ensure the system functions as expected. However, one challenge remains: collecting logs from individual or multiple Docker services for a given test case. Ideally, I’d like to save the logs generated during each test run in the corresponding test results.

Upon researching common testing frameworks and practices, I identified similar scenarios:

  • Before running a test, reset the service’s logs
  • After completing a test, collect the logs

I’ve explored various possible solutions, including:

  • Using Docker Testcontainers: While this approach is promising, it requires custom-built services and integrating them, which seems overly complex.
  • Resetting all containers to clear their logs: This method is impractical due to the significant time it takes, given the large number of different services involved.
  • Truncating logs: Stopping a container, truncating its logs, and then restarting it works but can be slow.
  • Rotating logs: Could this be achieved through Docker or by utilizing a central log service?

I’m confident that others have encountered similar issues in the past. I would greatly appreciate any suggestions or ideas on how to address this problem.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.