midnightntwrk / midnightntwrk/midnight-node-docker

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

Open
#5 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

BACKLOG midnight-node-docker public
Dominant language
Shell
Stars
34
Forks
21
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect compose.yml and the .env connection string described in the issue, starting with how the midnight-node-testnet service resolves the PostgreSQL host. Apply the documented host configuration and verify with docker-compose up that the node connects to cexplorer without the database lookup error.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose
Domain
devops, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.