0

I have this YAML file

  version: '2'
services:
  app:
    image: 'docker-spring-boot-postgres:latest'
    ports:
      - "8085:8085"
    build:
      context: C:\Users\Grigor_Martirosyan\IdeaProjects\docker\src\main\docker\Dockerfile
    container_name: app
    depends_on:
      - db
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/testdb
      - SPRING_DATASOURCE_USERNAME=postgres
      - SPRING_DATASOURCE_PASSWORD=admin
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update

  db:
    image: 'postgres:13.1-alpine'
    container_name: db
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=admin

the app says connection error

org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"

I tried to change connection details but still gives that error, it just changed, before it gave like TCP/IP error .but now that error.

Now it gives this error

Caused by: 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.

7
  • When you set $SPRING_DATASOURCE_URL, use the Compose service name db as the host name part of the URL. In Docker localhost usually means "the current container", not another container or the containing host. Also see Networking in Compose in the Docker documentation. Commented Mar 22, 2022 at 14:37
  • stackoverflow.com/users/10008173/david-maze so my localhost testdb can't be dockerized? Commented Mar 22, 2022 at 14:58
  • stackoverflow.com/users/10008173/david-maze do i need to instal postgre on docker? Commented Mar 22, 2022 at 15:34
  • The Compose file already has a PostgreSQL database, but its localhost is a different localhost from the application container's localhost or your host system's localhost. Commented Mar 22, 2022 at 15:47
  • stackoverflow.com/users/10008173/david-maze I mean if your spring boot application has Postgres database deployed on AWS , then do need to compose it or not? Commented Mar 22, 2022 at 15:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.