postgresqldockerdocker-compose

Postgres db in docker-compose errors with auth error every 2-3 seconds


container error

Every time I start my docker-compose on a server I get this error repeating once every 2-3 seconds. I haven't had this problem before (used this for 2-3 days). Once it just appeared out of nowhere and I don't know how to fix it. I tried deleting the folder with database files so it would initialize once again, I tried changing name of the volume, migrating to a postgres:15-alpine version from postgres:16-alpine. It seems like nothing is working. Here's my docker-compose file:

services:
  bot:
    build: .
    env_file:
      - .env
    restart: unless-stopped
    depends_on:
      postgres_db:
        condition: service_healthy

  postgres_db:
    image: postgres:15-alpine
    restart: unless-stopped
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=test1924
      - POSTGRES_DB=discord
    ports:
      - "5432:5432"
    volumes: 
      - ./data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "sh -c 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'"]
      interval: 10s
      timeout: 5s
      retries: 5
  
  pg_admin:
    image: dpage/pgadmin4
    restart: unless-stopped
    environment:
      - PGADMIN_DEFAULT_EMAIL=admin@admin.com
      - PGADMIN_DEFAULT_PASSWORD=root
    ports:
  - "5050:80"

I really don't know why it's not creating a postgres user by default. Any help will be appreciated! Here's the screenshot of roles from pg_admin:

pg_admin


Solution

  • Those messages are due to failed logon attempts by hackers to get into your Postgres database. They try to log on with user 'postgres' and, probably, password 'postgres' since those are used a lot in test databases.

    If you don't need to access the database from outside the docker network, you can remove your port mapping so the container isn't reachable from the Internet.