Smath Cadet
Smath Cadet

Reputation: 21

FATAL: no pg_hba.conf entry for host "172.21.144.1", user "smath", database "customer", no encryption

I need your help please. I am new to spring boot and Iam learning from a course about microservices and spring cloud. I have a basic app and setting up a database on docker with postgres.

I'm trying to connect my spring boot app to my postgresql database running on docker and this is the error I get:

FATAL: no pg_hba.conf entry for host "172.21.144.1", user "smath", database "customer", no encryption

It's looks like an encryption error but i dont know how to solve this issue

Here is my applicaton.yml file

server:
  port: 8080
spring:
  application:
    name: customer
  datasource:
    username: 'smath'
    url: jdbc:postgresql://postgres:5432/customer
    password: 'smath'
    jpa:
      properties:
        hibernate:
          dialect: org.hibernate.dialect.PostgreSQLDialect
          format_sql: 'true'
      hibernate:
        ddl-auto: update
      show-sql: 'true'

and my pg_hba.conf file looks like this

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    customer        smath           172.21.144.1            md5

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             0.0.0.0/0               scram-sha-256
# host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256

plus this is my docker-compose file

services:
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_USER: smath
      POSTGRES_PASSWORD: smath
      PGDATA: /data/postgres
    volumes:
      - postgres:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
      - pgadmin:/var/lib/pgadmin

    ports:
      - "5050:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge

volumes:
  postgres:
  pgadmin:

I will appreciate your help

Upvotes: 1

Views: 2985

Answers (1)

Smath Cadet
Smath Cadet

Reputation: 21

I Found a solution. It was a conflict between my local installed postgres and the docker installed version. I just stop the service of the local one and everything work fine.

Upvotes: 1

Related Questions