0

I have already googled this and searched in stack-overflow. I have this simple docker-compose setup

version: '3.8'
services:
  db:
    image: postgres:15-bullseye
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=combiner
    ports:
      - '5432:5432'
    volumes:
      - db_data:/var/lib/postgresql/data
volumes:
  db_data:
    driver: local

It starts up just fine and I can see the log in the container.

PostgreSQL Database directory appears to contain a database; Skipping initialization
2022-11-06T12:49:06.168906100Z 
2022-11-06T12:49:06.198469600Z 2022-11-06 12:49:06.198 UTC [1] LOG:  starting PostgreSQL 15.0 (Debian 15.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-11-06T12:49:06.198585700Z 2022-11-06 12:49:06.198 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-11-06T12:49:06.198631000Z 2022-11-06 12:49:06.198 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-11-06T12:49:06.203216100Z 2022-11-06 12:49:06.203 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-11-06T12:49:06.209822300Z 2022-11-06 12:49:06.209 UTC [27] LOG:  database system was shut down at 2022-11-06 12:49:05 UTC
2022-11-06T12:49:06.216866300Z 2022-11-06 12:49:06.216 UTC [1] LOG:  database system is ready to accept connections

But I cannot connect to the database from outside the container. I try to use Intellij's database tool and it get a password authentication error. Intellij fail to login

I am of course running docker-compose on the same computer that I run Intellij on and of course I am giving the correct pasword and user. I should not have to edit the pg_hba.conf file in the container to allow access from outside the container.

Any idea what is going wrong here?

ola
  • 129
  • 1
  • 10
  • make sure no other postgres is running in or outside docker – erik258 Nov 06 '22 at 13:27
  • 4
    `PostgreSQL Database directory appears to contain a database; Skipping initialization` <= which means that it kept all existing dbs and users, completely ignoring the user and password you have set in your service environment. If you don't care about that existing data, you can start from scrach. The [following answer](/questions/59838692/mysql-root-password-is-set-but-getting-access-denied-for-user-rootlocalhost/59839180#59839180) is for mysql but you are having the exact same problem from your description. – Zeitounator Nov 06 '22 at 13:59
  • @Zeitounator. Sorry for long feedback time. The answer you linked to seem similar, but the volume I am using was created by docker compose for this database and I have removed the voulme a few times. That did not change the behavior – ola Nov 12 '22 at 10:00
  • 1
    @erik258, Turns out you were right. I had an old postgres installation running on my laptop and listening on port 5432. It surprises me that Docker could also listen to port 5432 without any error message – ola Nov 12 '22 at 11:37

0 Answers0