midnightntwrk / midnightntwrk/midnight-node-docker
Unable to connect from docker midnight node to db-sync-postgres
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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