javapostgresqlspring-bootdocker

No Docker Compose file found in directory '/.'


I am using JIB for building my java docker image and pushing it into my repository.

problem:

  1. when I pull the image and try to run the container from that image, it shows no docker compose file found in the directory.
  2. container in the docker desktop is preventing from starting ( status: restarting)

I am adding images of my docker-compose.yml file and docker log:

java.lang.IllegalStateException: No Docker Compose file found in directory '/.'
at org.springframework.util.Assert.state(Assert.java:97) ~[spring-core-6.0.11.jar:6.0.11]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.getComposeFile(DockerComposeLifecycleManager.java:140) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:108) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.2.jar:3.1.2]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:416) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.2.jar:3.1.2]
at com.amigoes.fullstack.FullstackApplication.main(FullstackApplication.java:18) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.1.2.jar:3.1.2]

this is docker file:

 services:
  db:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: 123456789
      PGDATA: /data/postgres
    volumes:
      - db:/data/postgres
    ports:
      - "5433:5432"
    networks:
      - db
    restart: unless-stopped
  fullstack-api:
    container_name: fullstack-api
    image: ahmadmujtaba200210/fullstack
    environment:
      SPRING_DATASOURCE_URL: "jdbc:postgresql://db:5432/customer"
    ports:
      - "8088:8080"
    networks:
      - db
    depends_on:
      - db
    restart: unless-stopped

networks:
  db:
    driver: bridge

volumes:
  db:

My application.yml file:

server:
    error:
        include-message: always
    port: 8080
spring:
    datasource:
        url: jdbc:postgresql://localhost:5433/customer
        driver-class-name: org.postgresql.Driver
        password: 123456789
        username: postgres
    jpa:
        hibernate:
            ddl-auto: none
        properties:
            hibernate:
                dialect: org.hibernate.dialect.PostgreSQLDialect
                format_sql: true
                show_sql: true
    main:
        web-application-type: servlet
    docker:
        compose:
            file: ./docker-compose.yaml

docker desktop showing status of containers

found something interesting hope so yo may see some helping in solving my this problem as I am new to docker.

vulnerbility

my docker file is there but still my code is not running. I am using Spring boot, docker, postgres and Jib

I have tried with every file naming format given on google or spring guidlines:

  1. ./docker/compose.yml (moved compose file in separate folder)
  2. ./docker-compose.yaml
  3. ./docker-compose.yml

Solution

  • Try running the Docker Compose setup without embedding it inside a Spring Boot app. Typically, you’d use Docker Compose to start your services from the host machine.

    Use docker-compose up to bring up your services and check for any errors.

    Ensure your application is waiting for the database to be fully ready before trying to connect. If your application starts before the database is ready, it might crash and restart continuously. There are tools like wait-for-it and dockerize that help with this.

    Here's what you can do:

    Remove Docker Compose Dependencies: In your pom.xml or build.gradle, look for a dependency related to spring-boot-docker-compose and remove it.

    Remove Configuration: In your Spring Boot application.yml or application.properties, look for any configuration property related to Docker Compose, like spring.docker.compose.file, and remove it.

    Check Your Main Application Class: In FullstackApplication.java (or wherever your main Spring Boot application class is), ensure you don't have any Docker Compose related beans or configurations. Remove any you find.

    Rebuild & Restart: Once you've made these changes, rebuild your Spring Boot application and restart the Docker Compose setup.

    Check Logs: Once you've restarted, check the logs of the fullstack-api container again to make sure the error is resolved.

    Remember, when you're using Docker Compose outside of your Spring Boot application, you don't want any Docker Compose related logic inside your Spring Boot application. The two should operate independently.