Satya Narayana
Satya Narayana

Reputation: 452

Hyperledger Iroha not connecting to postgres database?

I am trying to deploy Hyperledger Iroha in Docker environment for running a single instance as per the guidelines given in 5.3.1 section at

https://iroha.readthedocs.io/en/latest/guides/deployment.html#running-single-instance 

However, I am getting below error.

NOTE: IROHA_POSTGRES_HOST should match 'host' option in config file
wait-for-it.sh: waiting 30 seconds for 127.0.0.1:5432
wait-for-it.sh: timeout occurred after waiting 30 seconds for 127.0.0.1:5432
[2019-01-02 11:33:20.406202853][th:80][info] MAIN start
[2019-01-02 11:33:20.406373949][th:80][info] MAIN config initialized
[2019-01-02 11:33:20.407157701][th:80][info] IROHAD created
[2019-01-02 11:33:20.407215609][th:80][info] StorageImpl:initConnection Start st
[2019-01-02 11:33:20.407363960][th:80][info] StorageImpl:initConnection block st
terminate called after throwing an instance of 'soci::soci_error'
  what():  Cannot establish connection to the database.
could not connect to server: Connection refused
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?

But I tested whether postgres server is running in my system or not using psql command. I am able to connect to postgres server from command prompt using psql command.

The iroha config file contents are as follows.

{ 
  "block_storage_path":"/tmp/block_store",
  "torii_port" : 50051,
  "internal_port" : 10001,
  "pg_opt" : "host=127.0.0.1 port=5432 user=postgres password=abc123",
  "max_proposal_size" : 10,
  "proposal_delay" : 5000,
  "vote_delay" : 5000,
  "mst_enable" : false
}

And the command i used for running iroha daemon is as follows.

iroha$ sudo docker run --name iroha2 -p 50051:50051 -v /home/user/iroha/example:/opt/iroha_data -v blockstore:/tmp/block_store -e IROHA_POSTGRES_HOST='127.0.0.1' -e POSTGRES_PORT='5432' -e POSTGRES_PASSWORD='abc123' -e POSTGRES_USER='postgres' -e KEY=node0 --network=iroha-network hyperledger/iroha:latest

Upvotes: 0

Views: 670

Answers (1)

Dima Savva
Dima Savva

Reputation: 66

Please note that you are trying to run Iroha node inside docker container, thus inside docker network. Postgres instance running on host machine will not be reachable from docker container. I suggest you running two docker containers: Postgres and Iroha. They will be in the same network, thus they will see each other.

In the link that you provided above, there are instructions for that.

docker run --name some-postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-p 5432:5432 \
--network=iroha-network \
-d postgres:9.5
And do not forget to change postgres host in your config file

Upvotes: 3

Related Questions