12

I am using Airflow through Docker-compose. The same docker-compose.yml has an image of Postgres as well. The config looks like below -

  postgres:
    image: postgres:13
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: airflow
      POSTGRES_PASSWORD: airflow
      POSTGRES_DB: airflow
    volumes:
      - postgres-db-volume:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "airflow"]
      interval: 5s
      retries: 5
    restart: always

This works fine for Airflow and I am also able to access the DAG on the UI.

But I want to access the dockerized Postgres instance from an outside SQL client application like Dbeaver. But I am not able to do that.

IP Address

Postgres Setting

Can someone please help me to resolve this?

Note: I already have a separate Postgres instance running on my local.

Prof.Plague
  • 649
  • 10
  • 20
sandeep
  • 3,061
  • 11
  • 35
  • 54
  • Maybe try localhost instead of 172.x – The Fool Dec 20 '21 at 16:06
  • localhost is not working too. – sandeep Dec 20 '21 at 16:13
  • Are you not able to connect on 0.0.0.0:5432 ? If ports are conflicting you can map any other port to 5432 from `ports` in `postgres` service. – Jashwant Dec 20 '21 at 17:07
  • I have this problem too. In addition, I can not add ports `5432:5432` to `yaml` file as you did. it returns an error that `this address is already in use` but I don't have any other thing that using this port. – Prof.Plague Jun 03 '22 at 07:59

2 Answers2

9

You should put 'localhost' instead of '172.25.0.2' and ensure there is no port '5432' already used in your system by using lsof -i:5432 | grep 'LISTEN'.

I prefer to use another port. see screenshot below

enter image description here

A.Y. Wicaksono
  • 161
  • 1
  • 10
5

After trying several times, as @Jashwant mentioned, this port(5432) was occupied. Note that it is possible that this port not be shown in lsof -i -P command.

So I used another port and instead of 5432:5432, I used 6543:5432 and it solved the problem.

Prof.Plague
  • 649
  • 10
  • 20