-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Unable to use Docker Compose support when mixing dedicated and shared services #40139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Instead of putting all the services in a single common.yml
catalog.yml
orders.yml
Now, in the application.properties file I configured which file to use as follows:
Now, the problem is, that the first spring-boot app (say order-service) that I started works as expected. But when I start the second application (say catalog-service) I see the following message due to which the required services are not being started.
|
Another option would be to keep the services in one file, use Docker Compose profiles, and modify your
This behavior is mentioned in the documentation:
There is some discussion on why we chose to implement things this way in #38398. You can set An additional mode like the one suggested in #39749, where |
Do you mean to say, if I create a single file
And then specify in the application.properties of Catalog service and Order service |
@sach429 that is correct. |
@bclozel I don't think it's working that way. Let me clarify how I am running my applications. I have two spring boot apps and I am running them directly from IntelliJ one after another. For eg. this is my setup and my intention is to have Catalog and Order have their own separate DBs but share the same Redis server Catalog:
Order:
I am running Catalog first, followed by Order. When I start Order, it detects the already running postgres container and eventually created two It does not matter if I merge the two compose files into one and refer to the same file in two Projects. I believe the profiles value is being passed as a flag when starting the docker services. So it's executing |
@sach429 Sorry I missed the |
@bclozel I am not sure if it's a bug because I don't fully understand if the way it is working now is by design or not My requirement is simple - Two Spring Boot apps and each talking to it's own DB. When I run the apps one after another - App1 starts it creates DB container#1 and thereby one This causes an issue in code which expects one Is there a way that when App2 starts it ignores DB Container#1. I don't think profile helps here and reading the documentation it seems like the use of profile is to prevent certain services from being started rather than ignoring already running containers. Essentially what I need is App2 to ignore connecting to DB container#1. The feature to ignore is available to certain extent but it's not practical in this case. The documentation states that we can specify a label like below
But, it's not useful here, because there's no way to tell that only App2 should ignore, Since both are spring boot apps, either both of them will ignore or none of them. |
Why don't you use two separate Docker Compose files for that? sivaprasadreddy had the problem that it's currently not possible to use the Docker Compose support if you have two services with a separate database for each one AND a shared component (rabbitmq in that example). But if your usecase doesn't involve a shared component, it should be possible. |
I looked into the original problem a bit and tried:
|
What could work is: Run {
"name": "sb-40139",
"networks": {
"default": {
"name": "sb-40139_default",
"ipam": {}
}
},
"services": {
"order-db": {
"profiles": [
"order"
],
"command": null,
"entrypoint": null,
"environment": {
"POSTGRES_DB": "mydatabase",
"POSTGRES_PASSWORD": "secret",
"POSTGRES_USER": "myuser"
},
"image": "postgres:17",
"networks": {
"default": null
},
"ports": [
{
"mode": "ingress",
"target": 5432,
"protocol": "tcp"
}
]
},
"redis": {
"command": null,
"entrypoint": null,
"image": "redis:7",
"networks": {
"default": null
},
"ports": [
{
"mode": "ingress",
"target": 6379,
"protocol": "tcp"
}
]
}
}
} Then run // ...
{
"Command": "\"docker-entrypoint.s…\"",
"CreatedAt": "2024-12-09 13:53:46 +0100 CET",
"ExitCode": 0,
"Health": "",
"ID": "eae6fa2df78e",
"Image": "postgres:17",
"Labels": "...",
"LocalVolumes": "1",
"Mounts": "577790079dbe43…",
"Name": "sb-40139-order-db-1",
"Names": "sb-40139-order-db-1",
"Networks": "sb-40139_default",
"Ports": "0.0.0.0:32812->5432/tcp, :::32812->5432/tcp",
"Project": "sb-40139",
"Publishers": [
{
"URL": "0.0.0.0",
"TargetPort": 5432,
"PublishedPort": 32812,
"Protocol": "tcp"
},
{
"URL": "::",
"TargetPort": 5432,
"PublishedPort": 32812,
"Protocol": "tcp"
}
],
"RunningFor": "8 minutes ago",
"Service": "order-db",
"Size": "0B",
"State": "running",
"Status": "Up 8 minutes"
}
// ... Now we can look in the config from above (under the This way, when specifying e.g. |
I also filed an issue on Docker compose side: docker/compose#12361 |
Thank you for looking into it. My use case is described in detail here . I am using two docker compose files and there's a common service. But I believe it doesn't matter if there's a common service or not. As long as two spring boot apps are using a common type of service which will create same type of |
Couldn't an easier solution be achieved using labels instead. For eg. you could apply label |
@sach429 this looks like supporting profiles in docker ps through custom labels. I think docker/compose#12361 is much more promis in because this means support for the entire docker compose ecosystem. |
Update on Docker Compose side: They redirected me to docker/compose#11737, and using |
|
I have a microservices-based mono-repo with multiple spring-boot applications. I would like to use Spring Boot Docker Compose support to start the dependent services. There are few services (ex: db) that are specific to each service and there are some services (ex: RabbitMQ) shared by multiple services.
All the microservices dependencies are defined in a single
compose.yml
fil. If I start any one microservice it starts all the services defined in the compose.yml file, which is ok for me.But the problem is, when I have multiple databases defined for different services, Flyway initialization fails.
Is there a way to configure at the microservice level (using
spring.docker.compose.*
properties) to take only certain services into account?The text was updated successfully, but these errors were encountered: