skip to Main Content

I set up mage-ai and postgresql containers via docker. I was able to successfully create the database during initialization of the container, could verify the existence of it via docker desktop. I wanted to connect to the same db using Dbeaver tool, but i keep getting authentication error. I am not sure what I am doing wrong. I will list relevant files below, to give you more content, and I am hoping for some lead.

Firstly, compose yaml file(local volume paths are simplified, dont mind it):

mage:
  image: mageai/mageai:latest
  command: mage start ${PROJECT_NAME}
  env_file:
    - .env
  build:
    context: .
    dockerfile: Dockerfile
  environment:
    USER_CODE_PATH: /home/src/${PROJECT_NAME}
    POSTGRES_DBNAME: ${POSTGRES_DBNAME}
    POSTGRES_SCHEMA: ${POSTGRES_SCHEMA}
    POSTGRES_USER: ${POSTGRES_USER}
    POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    POSTGRES_HOST: ${POSTGRES_HOST}
    POSTGRES_PORT: ${POSTGRES_PORT}
  ports:
    - 6789:6789
  volumes:
    - C:/docker_volume/:/home/src/
  restart: on-failure:5
postgres:
  image: postgres:14
  restart: on-failure
  container_name: ${PROJECT_NAME}-postgres
  env_file:
    - .env
  environment:
    POSTGRES_DB: ${POSTGRES_DBNAME}
    POSTGRES_USER: ${POSTGRES_USER}
    POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
  ports:
    - "${POSTGRES_PORT}:5432"
  volumes:
    - C:docker_volume:/var/lib/postgresql/data
    - C:init.sql:/docker-entrypoint-initdb.d/init.sql

AS you can see, I am using the .env file to import the variables, but i made use i stay consistent when trying to login, so that shouldnt be the issue.

I also checked the pg_hba.conf file to make sure that postgres allows for connections. It looks like this:

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     md5
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

host all all all scram-sha-256

But still I get this when i try to connect using Dbeaver:

enter image description here

At this point, I dont know what to do, even mighty ChatGPT cant help any further, so I decided to go back to the roots. Thanks in advance

2

Answers


  1. Chosen as BEST ANSWER

    So, turns out I do have a local postgres installed and the port 5432 that i was mapping to the dockers port, was already occupied. I was sure I removed local postgres, but I must've dreamt it. I was able to detect the issue by running the following command in CMD. netstat -aon | findstr :5432

    Based on the output

      TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       11084
      TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       6188
      TCP    [::]:5432              [::]:0                 LISTENING       6188
      TCP    [::]:5432              [::]:0                 LISTENING       11084
    

    I could dive in further and check which processes listen to this port using following commands.

    tasklist | findstr 11084
    tasklist | findstr 6188
    

    As a solution, I simply switched to a port 5433 instead. I could connect to the database running on docker, from local machine.


  2. This only has a chance to work if POSTGRES_PORT is 6789, see Networking in Compose.

        POSTGRES_PORT: ${POSTGRES_PORT}
      ports:
        - 6789:6789
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search