E
E
Egor Irvin2022-02-09 09:39:54
PostgreSQL
Egor Irvin, 2022-02-09 09:39:54

How to fix hostname for postgres in docker-compose?

Hello. When I run the application, I get the error:

Error:springboot-postgresql | org.postgresql.util.PSQLException:
Connection to localhost:5432 refused. Check that the hostname and port
are correct and that the postmaster is accepting TCP/IP connections.

As I understand it, the application is hammered on localhost: 5432.
And for my application in the container, the container with the database should definitely not be on the localhost.
How to fisk?
dockerfile:
FROM openjdk:11
    RUN mkdir -p /home/tst
    WORKDIR /home/test
    COPY . /home/test
    EXPOSE 8080
    ENTRYPOINT ["java", "-jar", "/home/test/hybridclient.jar"]

Dockerfile.postgres:

FROM postgres:12
    EXPOSE 5432


docker-compose:

version: '3.1'
    services:
      app:
        container_name: springboot-postgresql
        image: springboot-app
        build: ./
        ports:
          - "9000:9000"
        depends_on:
          - postgresqldb
      postgresqldb:
        image: postgres
        build:
          context: ./
          dockerfile: Dockerfile.postgres
        ports:
          - "5432:5432"
        environment:
          - PGDATA=/var/lib/postgresql/data
          - POSTGRES_PASSWORD=111111
          - POSTGRES_USER=usrdb

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2022-02-09
@AsphaltHero_0

Your application should knock on postgresqldb , this is the name of the container with the base

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question