Deploy a Graph Node

This tutorial will guide you to run The Graph self-hosted node on your machine via Docker Compose. Docker and Docker Compose are required to run graph node.

Prepare your docker-compose.yaml file

version: '3'
services:
  graph-node:
    image: graphprotocol/graph-node
    ports:
      - '8000:8000'
      - '8001:8001'
      - '8020:8020'
      - '8030:8030'
      - '8040:8040'
    depends_on:
      - ipfs
      - postgres
    extra_hosts:
      - host.docker.internal:host-gateway
    environment:
      postgres_host: postgres
      postgres_user: graph-node
      postgres_pass: let-me-in
      postgres_db: graph-node
      ipfs: 'ipfs:5001'
      ethereum: RPC_URL_TO_YOUR_NODE
      GRAPH_LOG: info
  ipfs:
    image: ipfs/kubo:v0.14.0
    ports:
      - '5001:5001'
    volumes:
      - ./data/ipfs:/data/ipfs
  postgres:
    image: postgres:14
    ports:
      - '5432:5432'
    command:
      [
        "postgres",
        "-cshared_preload_libraries=pg_stat_statements",
        "-cmax_connections=200"
      ]
    environment:
      POSTGRES_USER: YOUR_POSTGRES_USER
      POSTGRES_PASSWORD: YOUR_POSTGRES_PASSWORD
      POSTGRES_DB: YOUR_POSTGRES_DB
      # FIXME: remove this env. var. which we shouldn't need. Introduced by
      # <https://github.com/graphprotocol/graph-node/pull/3511>, maybe as a
      # workaround for https://github.com/docker/for-mac/issues/6270?
      PGDATA: "/var/lib/postgresql/data"
      POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
    volumes:
      - ./data/postgres:/var/lib/postgresql/data

In that:

  • RPC_URL_TO_YOUR_NODE: is RPC URL to your node (it could be your local U2U node or public tracing node). Example: 'solaris:http://host.docker.internal:8545' or 'solaris:https://rpc-mainnet.u2u.xyz' for Solaris mainnet or 'nebulas:https://rpc-nebulas-testnet.u2u.xyz' for Nebulas testnet.

  • POSTGRES_USER: your Postgres database username. Example: graph-node

  • POSTGRES_PASSWORD: Your Postgres database password. Example: let-me-in

  • POSTGRES_DB: your Postgres database database name. Example: graph-node

Once your filled those environment variables, you enter below command to start your graphnode with Docker Compose at the same directory where contains your docker-compose.yaml file:

You will see something similar:

Please take a look at the last line, graphnode has started to sync blocks with the RPC node. Your graphnode now is ready to deploy a subgraph.

Last updated