skip to Main Content

I have a docker container running postgresql connected to another container (webmapping server) on an ubuntu host. I would like to connect to my database from outside the host (another machine on the same network).

I’m able to connect to the database from the host (PGadmin), from the other container but not from outside the host (through public IP)
error screenshot on PGadmin

how should I fix this ?

many thanks, Thomas

3

Answers


  1. Chosen as BEST ANSWER

    I Solved it by myself : I had to specify 0.0.0.0:5432:5432 to make it reachable from any IP, public or local.

    Many thanks to Hans for helping


  2. You need to map port 5432 on the container to a port on the host and connect through that.

    Let’s say you want to use port 55432 on the host. Then you’d add the parameter -r 55432:5432 to your docker run command and then connect to port 55432 on your docker host machine.

    You also need to allow incoming connections on port 55432 on your host machine’s firewall to be able to connect from outside the host.

    Login or Signup to reply.
  3. Using pgcl utilities in host:
    Public IP address: xx.xx.xx.xx
    pgcli -h xx.xx.xx.xx -p 5432 or 5416(user defined) -U postgres

    Server: PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1)
    Version: 3.5.0
    Home: http://pgcli.com
    postgres@10:postgres>

    ———–+——-+———-+————+————+——————-+
    | Name | Owner | Encoding | Collate | Ctype | Access privileges |
    |———–+——-+———-+————+—-|
    | postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | |
    | template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres |

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search