Skip to content

Unable to connect from docker midnight node to db-sync-postgres #5

@gilescope

Description

@gilescope

When docker containers communicate with each other, specifying localhost or 0.0.0.0 will not connect.

In case of error

.env file

DB_SYNC_POSTGRES_CONNECTION_STRING="psql://postgres:password123@localhost:5432/cexplorer" # Replace x.x.x.x with IP or host to postgres connection

Run to docker-compose up

midnight-node-testnet-1  | error: Service(Application("Failed to create db-sync main chain follower: Could not connect to database: psql://***:***@localhost:5432/cexplorer; error: error communicating with database: failed to lookup address information: Name or service not known"))

Solution

Add extra_hosts to compose.yml

volumes:
  midnight-data-testnet: {}

services:
  midnight-node-testnet:
    image: ${MIDNIGHT_NODE_IMAGE}
    platform: linux/amd64
    extra_hosts:
      - host.docker.internal:host-gateway
    ports:
      - "9944:9944"
      - "30333:30333"
    env_file:
      - ./.env
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:9933/health" ]
      interval: 2s
    volumes:
      - midnight-data-testnet:/node

Specify host.docker.internal in env file

DB_SYNC_POSTGRES_CONNECTION_STRING="psql://postgres:password123@host.docker.internal:5432/cexplorer" # Replace x.x.x.x with IP or host to postgres connection

Run to docker-compose up

Done!

Raised by @btbf originally here: https://github.com/midnight-ntwrk/midnight-node-docker/issues/4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions