Search code examples
postgresqldockerchainlink

chainlink docker to postgres docker


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.


Solution

  • @ZeusLawyer Thanks. In the meantime I got it working with the below config, if it helps others.

    # to start db instance
    docker run --name postgres -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -p 5432:5432 -d postges:latest
    
    

    For Chainlink instance

    docker run --network=host -p 6688:6688 -v ~/.chainlink-goerli:/chainlink -it --env-file=chainlink.env smartcontract/chainlink:1.5.0-root local n -p /chainlink/password.txt -a /chainlink/apicredentials.txt
    

    DATABASE_URL

    DATABASE_URL=postgresql://root:secret@localhost:5432/root?sslmode=disable