Not able to use postgres and drone

Hey
I’m trying to use drone with separate DB (postgres), and it is running on my machine, not in compose.

But i’m not able to connect on postgres, I’m receiving another error, as you can see:

Creating network "drone-ci_default" with the default driver
Creating drone-ci_drone-server_1 ... done
Creating drone-ci_drone-agent_1  ... done
Attaching to drone-ci_drone-server_1, drone-ci_drone-agent_1
drone-server_1  | time="2018-08-02T21:17:00Z" level=info msg="database ping failed. retry in 1s"
drone-agent_1   | {"time":"2018-08-02T21:17:00Z","level":"debug","message":"request next execution"}
drone-agent_1   | INFO: 2018/08/02 21:17:00 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 172.20.0.2:9000: getsockopt: connection refused"; Reconnecting to {drone-server:9000 <nil>}
drone-agent_1   | 2018/08/02 21:17:00 grpc error: done(): code: Unavailable: rpc error: code = Unavailable desc = grpc: the connection is unavailable
drone-server_1  | time="2018-08-02T21:17:01Z" level=info msg="database ping failed. retry in 1s"
drone-agent_1   | INFO: 2018/08/02 21:17:01 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 172.20.0.2:9000: getsockopt: connection refused"; Reconnecting to {drone-server:9000 <nil>}
drone-agent_1   | 2018/08/02 21:17:01 grpc error: done(): code: Unavailable: rpc error: code = Unavailable desc = grpc: the connection is unavailable
drone-server_1  | time="2018-08-02T21:17:02Z" level=info msg="database ping failed. retry in 1s"
drone-agent_1   | 2018/08/02 21:17:02 grpc error: done(): code: Unavailable: rpc error: code = Unavailable desc = grpc: the connection is unavailable

The point is, once I remove the postgres configuration, its working perfectly with sqLite.

My drone configuration:

version: '3'

services:
  drone-server:
    image: drone/drone:0.8.6

    ports:
      - 8000:8000
      - 9000
    volumes:
      - /var/lib/drone:/var/lib/drone/
    restart: always
    environment:
      - DRONE_OPEN=true
      - DRONE_ADMIN=WellMafra
      - DRONE_HOST=${DRONE_HOST}
      - DRONE_GITHUB=true
      - DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT}
      - DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET}
      - DRONE_SECRET=${DRONE_SECRET}
      - DRONE_DATABASE_DRIVER=${DB_DRIVER}
      - DRONE_DATABASE_DATASOURCE=${DB_DRIVER}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}?sslmode=disable
      - DRONE_DEBUG=true
      - DRONE_DEBUG_PRETTY=true

  drone-agent:
    image: drone/agent:0.8.6

    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=drone-server:9000
      - DRONE_SECRET=${DRONE_SECRET}

Partial .env file:

DB_DRIVER=postgres
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=drone
DB_USERNAME=wellington
DB_PASSWORD=wellington

127.0.0.1 is not a valid address because Drone is running inside of an isolated container network and postgres is going to be running on a different network. If you are using docker-compose to run your postgres container, you should use the contianer name as the hostname. There is a good primer on docker-compose networking here https://docs.docker.com/compose/networking/

Thanks bradrydzewski for replying. You helped me!

Here is my steps to make it work:

It worked!

Thanks