I am trying to connect chainlink to the postgres db and for the same I am running both of them as docker images.
I start the postgres docker as:
$ docker run --name some-postgres -e POSTGRES_PASSWORD=secret -p 5432:5432 -d postgres
This starts the postgres successfully.
However if I try to connect chainlink (as per the chainlink doc) using the below .env
file
ROOT=/chainlink
LOG_LEVEL=debug
ETH_CHAIN_ID=5
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
ALLOW_ORIGINS=*
ETH_URL=wss://eth-goerli.g.alchemy.com/v2/<API KEY>
DATABASE_URL=postgresql://some-postgres:secret@postgres:5432/postgres?sslmode=disable
I am trying to connect to the "some-postgres" instance with the password as "secret" and still it throws the error
Cannot boot Chainlink: opening db: failed to open db: failed to connect to `host=postgres user=some-postgres database=postgres`: hostname resolving error (lookup postgres on 192.168.1.1:53: read udp 172.17.0.3:47766->192.168.1.1:53: i/o timeout) err=Cannot boot Chainlink: opening db: failed to open db: failed to connect to `host=postgres user=some-postgres database=postgres`: hostname resolving error (lookup postgres on 192.168.1.1:53: read udp 172.17.0.3:47766->192.168.1.1:53: i/o timeout) errVerbose=opening db: failed to open db: failed to connect to `host=postgres user=some-postgres database=postgres`: hostname resolving error (lookup postgres on 192.168.1.1:53: read udp 172.17.0.3:47766->192.168.1.1:53: i/o timeout)
Cannot boot Chainlink
I don’t know why it does not connect chainlink docker to postgres docker.
2
Answers
@ZeusLawyer Thanks. In the meantime I got it working with the below config, if it helps others.
For Chainlink instance
DATABASE_URL
I think your
DATABASE_URL
env var is not composed correctly?As per the Chainlink Docs you referenced, the DB connection string should follow this format:
"DATABASE_URL=postgresql://$USERNAME:$PASSWORD@$SERVER:$PORT/$DATABASE"
I think you’ve put
user-postgres
as your username when it may actually be the server name?the Postgres database user name and password can be set directly in your DATABASE_URL connection string and then you may not need to pass it in your
docker run
command.But first be sure you know the username and password (refer to these docs) and the Postgres docker documentation.
Then fill in your connection string carefully using the format provided in the docs.