Starting only one service from a compose file with DockerComposeContainer
From the source code of DockerComposeContainer, it appears the answer is no, but only because DockerComposeContainer.runWithCompose
is private.
From the usage of that method in other places such as DockerComposeContainer.createServices
it seems all that would be needed is to expose runWithCompose
and you could have the full docker-compose command set, allowing something like:
new DockerComposeContainer(new File("src/test/resources/compose-test.yml")) .runWithCompose("run -d redis");
(and other docker-compose run
options).
It's a pretty active project in github, so you may get traction on this with an issue submission or better yet a pull request.
The ability to start a subset of the servers was added to Testcontainers 1.11.4 via the addition of the withServices(String... services)
method (#1497). However, this feature was accidentally broken in 1.12.4 and is still broken in the latest 1.13.0 release (#2191).
In a version of the library that works, you can therefore do the following to start up just the single Redis service:
new DockerComposeContainer(new File("src/test/resources/compose-test.yml")) .withServices("redis_1")