What are good alternatives to Testcontainers for managing Docker containers from a Java application?
Asked by
MellowPine47
I'm building a local LLM lab that orchestrates several language models, tools, and a vector database. I'm using LangChain4j for the SDK and API integrations, but I currently start the supporting services manually with Docker Compose before launching the application. I'd like the Java application to start and stop those containers itself, and I'm considering Testcontainers even though it is primarily designed for testing. Is it suitable for managing long-running containers, or are there better Java libraries or approaches?
Answers
Testcontainers uses docker-java internally, so docker-java is a reasonable option for this use case. It provides a Java client for creating, starting, stopping, and otherwise managing Docker containers without treating the application as a test.
Reply to this answer
Docker exposes an HTTP Engine API over the Unix socket, so a Java program can manage containers directly through that API. You can either call the API yourself or use a client library rather than relying on a testing framework.
Reply to this answer
If this is a Spring Boot application, spring-boot-docker-compose can start the dependent services during local development and may automatically configure their connection details. For production, though, use a proper deployment or orchestration platform instead of having the application manage long-lived containers directly.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions