Hello,
Using developmentOnly("org.springframework.boot:spring-boot-docker-compose") with SB 3.3.0-M2 (could reproduce with 3.2.4 too), when I'm starting my app, it fails with:
2024-03-21T22:28:18.150-04:00 INFO 94295 --- [ main] .s.b.d.c.l.DockerComposeLifecycleManager : Using Docker Compose file '/Users/anthony/workspaces/anthonydahanne/dev-calendar/docker-compose.yml'
2024-03-21T22:28:18.602-04:00 ERROR 94295 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.boot.docker.compose.core.DockerOutputParseException: Failed to parse docker JSON:
name: dev-calendar
services:
database:
environment:
POSTGRES_DB: mydatabase
POSTGRES_PASSWORD: secret
POSTGRES_USER: myuser
image: postgres:15.2
networks:
default: null
ports:
- mode: ingress
target: 5432
published: "15432"
protocol: tcp
pgadmin:
environment:
PGADMIN_DEFAULT_EMAIL: myuser@domain-name.com
PGADMIN_DEFAULT_PASSWORD: secret
image: dpage/pgadmin4
networks:
default: null
ports:
- mode: ingress
target: 80
published: "8888"
protocol: tcp
networks:
default:
name: dev-calendar_default
at org.springframework.boot.docker.compose.core.DockerJson.deserialize(DockerJson.java:81) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.docker.compose.core.DockerJson.deserialize(DockerJson.java:73) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.docker.compose.core.DockerCliCommand.deserialize(DockerCliCommand.java:77) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.docker.compose.core.DockerCli.run(DockerCli.java:81) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.docker.compose.core.DefaultDockerCompose.hasDefinedServices(DefaultDockerCompose.java:71) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:111) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) ~[spring-boot-docker-compose-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) ~[spring-context-6.1.4.jar:6.1.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) ~[spring-context-6.1.4.jar:6.1.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) ~[spring-context-6.1.4.jar:6.1.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-6.1.4.jar:6.1.4]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:432) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.3.0-M2.jar:3.3.0-M2]
at calendar.CalendarApiApplication.main(CalendarApiApplication.java:10) ~[main/:na]
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'name': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
~~while my docker-compose.yml does NOT start with~~
name: dev-calendar
Digging further, I had a look at what Spring Boot Docker Compose did, and it ran:
docker-compose --file docker-compose.yml --ansi never config --format=json
~~which DOES indeed prepend the docker-compose.yml with:~~
which returns the non json following document:
```name: dev-calendar
services:
database:
environment:
POSTGRES_DB: mydatabase
POSTGRES_PASSWORD: secret
POSTGRES_USER: myuser
image: postgres:15.2
networks:
default: null
ports:
- mode: ingress
target: 5432
published: "15432"
protocol: tcp
pgadmin:
environment:
PGADMIN_DEFAULT_EMAIL: myuser@domain-name.com
PGADMIN_DEFAULT_PASSWORD: secret
image: dpage/pgadmin4
networks:
default: null
ports:
- mode: ingress
target: 80
published: "8888"
protocol: tcp
networks:
default:
name: dev-calendar_default
It used to work, but without touching it nor changing version it stopped working 🧐 - that said I ran `brew upgrade` recently.
docker-compose version
Docker Compose version 2.25.0
Thanks!
**Comment From: anthonydahanne**
well, it appears that `docker-compose` 2.25.0 changed a lot; in particular:
Dependencies upgrade: bump compose-go v2.0.0
After reverting to previous `docker-compose`, version 2.24.7, using this [trick](https://stackoverflow.com/a/7787703/24069) and the file at https://raw.githubusercontent.com/Homebrew/homebrew-core/65be7dffbc1ff28f4435d7b39411c457b3a975fd/Formula/d/docker-compose.rb , it worked again.
Furthermore, I now have proper Json
```json
docker-compose --file docker-compose.yml --ansi never config --format=json
{
"name": "dev-calendar",
"networks": {
"default": {
"name": "dev-calendar_default"
}
},
"services": {
"database": {
"environment": [
"POSTGRES_USER=myuser",
"POSTGRES_DB=mydatabase",
"POSTGRES_PASSWORD=secret"
],
"image": "postgres:15.2",
"networks": {
"default": null
},
"ports": [
{
"mode": "ingress",
"protocol": "tcp",
"published": "15432",
"target": 5432
}
]
},
"pgadmin": {
"environment": {
"PGADMIN_DEFAULT_EMAIL": "myuser@domain-name.com",
"PGADMIN_DEFAULT_PASSWORD": "secret"
},
"image": "dpage/pgadmin4",
"networks": {
"default": null
},
"ports": [
{
"mode": "ingress",
"protocol": "tcp",
"published": "8888",
"target": 80
}
]
}
}
}
Comment From: mhalbritter
Thanks for the report. We have to add support for docker compose 2.25.0.
Comment From: mhalbritter
Looks like a bug in Docker Compose. Let's see what the Docker Compose team says.
Comment From: wilkinsona
I saw someone else with this problem on Mastodon from where I learned that it should be fixed by this PR.
Comment From: mhalbritter
How did I overlook that in my search ?? Thanks Andy, i've closed my issue as a dupe. The PR is already merged, so we need to wait for the next docker compose release. Nothing we can do here.
If you're affected, the workaround is to not use Docker Compose 2.25.0. 2.24.0 works fine.
Comment From: mhalbritter
Docker Compose 2.26.0 has been released, which should fix that bug.
Comment From: anthonydahanne
I confirm! I just tested it out, it is fixed!
Comment From: ENate
@anthonydahanne I have docker 26.0 but still facing this issue. Is that your docker version, too?
Comment From: mhalbritter
The docker version doesn't matter. Run docker compose version to see your Docker Compose version. If it says v2.25.0, you're still using the bugged version.
Comment From: martin-tk
I had this issue on Kubuntu 22.04.4 LTS.
For me it turned out that I had docker-compose-plugin installed. This seems to make spring boot use docker's compose subcommand instead of executing docker-compose command directly (which is generally ok, except in this case).
After uninstalling docker-compose-plugin and downloading docker-compose 2.26.0 my SpringBoot app is able to start and services defined in compose.yml start fine.
Comment From: ENate
Thanks @mhalbritter - will check. It seems the v2.26.0 is not yet available on the Ubuntu apt package manager.
Comment From: matterwin
Yes installing docker-compose-linux-x86_64 on my Ubuntu worked solved my "Failed to parse docker JSON" problem for my Spring-Boot 3 application