Context
We are currently migrating our GitHub Actions CI pipeline from GitHub-hosted runners to self-hosted runners that run as pods inside our Kubernetes infrastructure.
We use spring-boot-docker-compose
(introduced in Spring Boot 3.1) as part of our pipeline to
manage application containers.
However, our environment is a Docker-in-Docker (DinD) setup. This means the services launched by
docker-compose
are not accessible via localhost
, but only through the Docker bridge IP (
172.17.0.1
, for example).
Currently, spring-boot-docker-compose
assumes services are reachable on localhost
, and has no
mechanism to distinguish between:
- Docker on local VM (e.g., Docker Desktop or normal Docker engine)
- Docker-in-Docker (common in CI/CD or Kubernetes runners)
This leads to connection issues in pipelines when services are not reachable via localhost
.
Proposal
We propose that spring-boot-docker-compose
supports a new Spring Boot property to explicitly
define the service host IP that Spring Boot should use when accessing the container from outside.
For example:
spring:
docker:
compose:
host: 172.17.0.1
This would let users explicitly tell Spring Boot what host to use when generating dynamic service URLs, particularly in CI/CD environments where assumptions about localhost do not hold.
This approach allows the property to be overridden using:
- Spring profiles (e.g., application-ci.yaml)
- Environment variables (e.g., SPRING_DOCKER_COMPOSE_HOST=172.17.0.1)
- Command line arguments (e.g., --spring.docker.compose.host=172.17.0.1)
Benefits - Works seamlessly in Docker-in-Docker environments. - Avoids hardcoding workaround logic in build scripts or dynamic property sources. - Keeps docker-compose.yml clean and environment-agnostic. - Improves compatibility with pipelines that use Spring Boot Docker Compose support.
Thank you for considering this improvement.
Comment From: philwebb
We already have some logic in DockerHost
that looks at various options when trying to determine the host to connect to. I wonder if those would work for you?
Comment From: julien92
Thanks for the reply. I didn’t notice that the property
spring.docker.compose.host=my.custom.docker.host already exists.
This completely solves my problem. It’s probably a fairly common need, so it might be helpful if this option was made more visible in the Spring Boot Docker Compose documentation.