Skip to content
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

Docker Compose support doesn't work with Docker Compose 2.25.0 #40060

Closed
anthonydahanne opened this issue Mar 22, 2024 · 12 comments
Closed

Docker Compose support doesn't work with Docker Compose 2.25.0 #40060

anthonydahanne opened this issue Mar 22, 2024 · 12 comments
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@anthonydahanne
Copy link
Contributor

anthonydahanne commented Mar 22, 2024

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:

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!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 22, 2024
@anthonydahanne
Copy link
Contributor Author

well, it appears that docker-compose 2.25.0 changed a lot; in particular:

[Update](https://docs.docker.com/compose/release-notes/#update)

    Dependencies upgrade: bump compose-go v2.0.0

After reverting to previous docker-compose, version 2.24.7, using this trick 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

 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
        }
      ]
    }
  }
}

@mhalbritter
Copy link
Contributor

Thanks for the report. We have to add support for docker compose 2.25.0.

@mhalbritter mhalbritter added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 22, 2024
@mhalbritter mhalbritter added this to the 3.3.x milestone Mar 22, 2024
@mhalbritter mhalbritter changed the title org.springframework.boot.docker.compose.core.DockerOutputParseException: Failed to parse docker JSON - Unrecognized token 'name' Docker Compose support doesn't work with Docker Compose 2.25.0 Mar 22, 2024
@mhalbritter
Copy link
Contributor

Looks like a bug in Docker Compose. Let's see what the Docker Compose team says.

@wilkinsona
Copy link
Member

I saw someone else with this problem on Mastodon from where I learned that it should be fixed by this PR.

@mhalbritter
Copy link
Contributor

mhalbritter commented Mar 22, 2024

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.

@mhalbritter mhalbritter closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2024
@mhalbritter mhalbritter added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed type: bug A general bug labels Mar 22, 2024
@mhalbritter mhalbritter removed this from the 3.3.x milestone Mar 22, 2024
@bclozel bclozel pinned this issue Mar 23, 2024
@mhalbritter
Copy link
Contributor

Docker Compose 2.26.0 has been released, which should fix that bug.

@anthonydahanne
Copy link
Contributor Author

I confirm! I just tested it out, it is fixed!

@ENate
Copy link

ENate commented Mar 25, 2024

@anthonydahanne I have docker 26.0 but still facing this issue. Is that your docker version, too?

@mhalbritter
Copy link
Contributor

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.

@martin-tk
Copy link

martin-tk commented Mar 26, 2024

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.

@ENate
Copy link

ENate commented Mar 26, 2024

Thanks @mhalbritter - will check. It seems the v2.26.0 is not yet available on the Ubuntu apt package manager.

@matterwin
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

7 participants