beatrice
beatrice

Reputation: 4421

Starting only one service from a compose file with DockerComposeContainer

Is that possible somehow to run only specific services in a Testcontainers DockerComposeContainer?

Using the example in the official documentation, could we start only Redis? For me all the services start all the time (and it doesn't matter whether have I used the withExposedService method or not).

I mean a method like this:

new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
        .composeUpService("redis_1")

Upvotes: 5

Views: 1239

Answers (2)

M. Justin
M. Justin

Reputation: 21152

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")

Upvotes: 1

Eric Woods
Eric Woods

Reputation: 319

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.

Upvotes: 5

Related Questions