I think in this case, you can use Test Containers.
Long story short. More details are in the documentation.
You can create easily docker compose which is based on compose-test.yml
public static DockerComposeContainer environment =
new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
.withExposedService("redis_1", REDIS_PORT)
.withExposedService("elasticsearch_1", ELASTICSEARCH_PORT);
compose-test.yml
looks like:
redis:
image: redis
elasticsearch:
image: elasticsearch
Here is the link to documentation:
https://www.testcontainers.org/usage/docker_compose.html