connect to docker postgresql from remote grafana

Viewed 56

I have a linux virtual machine remotely on the cloud hosted at digitalocean, this machine has grafana installed. Locally I have docker and I launched a postgresql server with the following docker-compose.yml:

version: '3.8'

services:
  
  timescale:
    image: timescale/timescaledb-ha:pg14-latest
    container_name: timescaledb
    ports:
      - "5432:5432"
    volumes:
      - timescale-volume:/home/postgres/pgdata/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
    networks:
      - trade-net
    
networks:
  trade-net:
    external: true

volumes:
  timescale-volume:
    external: true

Upon checking my network with network inspect trade-net I get:

"IPv4Address": "172.22.0.3/16"

I would like to connect via grafana now to my postgresql docker container which has been launched from my local machine, the grafana options are the following ones:

enter image description here

I have tried to fill this with :

Host: 172.22.0.3:5432
Database: postgres
User: postgres Password: password

But the connection is never established.

One thing to note is that my postgresql.conf file has :

listen.addresses = '*'
1 Answers

The IP address from the docker network is available only through your local PC.

To access your container remotely you need your computer's public IP address.

Try running

curl ifconfig.me

It will return your public IP.


You should also check your router's firewall, to make sure it allows connections to port 5432

Related