1

I have push spring boot image to docker hub it is also dependent on PostgreSQL image. I get error PSQLEXception : The connection attempt failed. When running the pulled spring boot image. Should I also push PostgreSQL image too or is there a way to push booth the images Together.

version: '3.1'
services:
  app:
    container_name: app-springboot-furniture
    image: app-springboot-furniture
    build: ./
    ports:
      - "8090:8090"
    depends_on:
      - postgres
  postgres:
    image: postgres
    restart: always
    ports:
      - "5432:5432"
    volumes:
      - app-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=123
      - POSTGRES_USER=postgres
      - POSTGRES_DB=nextlevel


  pgadmin:
    container_name: pgadmin4_container_furniture
    image: dpage/pgadmin4:5.5
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: secret
      PGADMIN_LISTEN_PORT: 80
    ports:
      - "8080:80"
volumes:
  app-data:
FROM openjdk:11
EXPOSE 8090
ADD target/spring-boot-e-commerce-furniture.jar furniture.jar
ENTRYPOINT ["java","-jar","furniture.jar"]
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:297) ~[postgresql-42.2.14.jar!/:42.2.14]
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.14.jar!/:42.2.14]
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217) ~[postgresql-42.2.14.jar!/:42.2.14]
        at org.postgresql.Driver.makeConnection(Driver.java:458) ~[postgresql-42.2.14.jar!/:42.2.14]
        at org.postgresql.Driver.connect(Driver.java:260) ~[postgresql-42.2.14.jar!/:42.2.14]
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar!/:na]
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar!/:na]
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) ~[HikariCP-3.4.5.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560) ~[HikariCP-3.4.5.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.4.5.jar!/:na]
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.5.jar!/:na]
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.17.Final.jar!/:
5.4.17.Final]
David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Why you add a build inside app service. You are using already built image right? – YJR Sep 25 '22 at 07:57
  • also can you add the application.properties file of the built image? – YJR Sep 25 '22 at 08:00
  • your problem has nothing to do with pushing or pulling images. When your app starts the database may not be started yet. Also the credentials that you use to start postgres should be passed to the spring boot apps as well (and used). – Mihai Sep 25 '22 at 08:28
  • The PostgreSQL image is already on Docker Hub, you don't need to push it. You do need to manually copy the `docker-compose.yml` file to the target system, and it will know to download things as needed; are you doing this? – David Maze Sep 25 '22 at 11:14

0 Answers0