From da58e39c26da77fe4e8f8ffdc0c60f49555a28e7 Mon Sep 17 00:00:00 2001 From: Paolo Facchinetti <51409747+paolofacchinetti@users.noreply.github.com> Date: Mon, 3 Jul 2023 15:04:17 +0200 Subject: [PATCH] feat: add docker compose with docs (#3496) Co-authored-by: Oliver Nordbjerg --- book/installation/docker.md | 71 ++++++++++++++++++++++++++ etc/.gitignore | 1 + etc/README.md | 12 +---- etc/docker-compose.yml | 95 +++++++++++++++++++++++++++++++++++ etc/docker-monitoring.yml | 39 -------------- etc/generate-jwt.sh | 4 ++ etc/prometheus/prometheus.yml | 2 +- 7 files changed, 173 insertions(+), 51 deletions(-) create mode 100644 etc/.gitignore create mode 100644 etc/docker-compose.yml delete mode 100644 etc/docker-monitoring.yml create mode 100755 etc/generate-jwt.sh diff --git a/book/installation/docker.md b/book/installation/docker.md index 936e226c6..f216aa0cf 100644 --- a/book/installation/docker.md +++ b/book/installation/docker.md @@ -45,3 +45,74 @@ The build will likely take several minutes. Once it's built, test it with: ```bash docker run reth:local --version ``` + +## Using the Docker image + +There are two ways to use the Docker image: +1. [Using Docker](#using-plain-docker) +2. [Using Docker Compose](#using-docker-compose) + +### Using Plain Docker + +To run Reth with Docker, run: + +```bash +docker run \ + -v rethdata:/root/.local/share/reth/db \ + -d \ + -p 9000:9000 \ + --name reth \ + reth:local \ + node \ + --metrics 0.0.0.0:9000 +``` + +The above command will create a container named `reth` and a named volume called `rethdata` for data persistence. + +It will use the local image `reth:local`. If you want to use the GitHub Container Registry remote image, use `ghcr.io/paradigmxyz/reth` with your preferred tag. + +### Using Docker Compose + +To run Reth with Docker Compose, run the following command from a shell inside the root directory of this repository: + +```bash +./etc/generate-jwt.sh +docker compose -f etc/docker-compose.yml up -d +``` + +To check if Reth is running correctly, run: + +```bash +docker compose logs -f reth +``` + +The default `docker-compose.yml` file will create four containers: + +- Reth +- Prometheus +- Grafana +- Lighthouse + +Grafana will be exposed on `localhost:3000` and accessible via default credentials (username and password is `admin`) + +## Interacting with Reth inside Docker + +To interact with Reth you must first open a shell inside the Reth container by running: + +```bash +docker exec -it reth bash +``` + +**If Reth is running with Docker Compose, replace `reth` with `reth-reth-1` in the above command** + +### Listing the tables + +```bash +reth db stats +``` + +### Viewing some records + +```bash +reth db list --start=1 --len=2 Headers +``` \ No newline at end of file diff --git a/etc/.gitignore b/etc/.gitignore new file mode 100644 index 000000000..9aceb4ea3 --- /dev/null +++ b/etc/.gitignore @@ -0,0 +1 @@ +jwttoken diff --git a/etc/README.md b/etc/README.md index 10df5260b..13315fbe1 100644 --- a/etc/README.md +++ b/etc/README.md @@ -11,14 +11,4 @@ The files in this directory may undergo a lot of changes while reth is unstable, ### Docker Compose -To run Grafana dashboard with example dashboard and pre-configured Prometheus data source pointing at -the locally running Reth instance with metrics exposed on `localhost:9001`: -```sh -docker compose -p reth -f ./etc/docker-monitoring.yml up -``` - -After that, Grafana will be exposed on `localhost:3000` and accessible via default credentials: -``` -username: admin -password: admin -``` \ No newline at end of file +To run Reth, Grafana and Prometheus with Docker Compose, refer to the [docker docs](/book/installation/docker.md#using-docker-compose) \ No newline at end of file diff --git a/etc/docker-compose.yml b/etc/docker-compose.yml new file mode 100644 index 000000000..a19e253f7 --- /dev/null +++ b/etc/docker-compose.yml @@ -0,0 +1,95 @@ +version: '3.9' +name: 'reth' + +services: + reth: + restart: unless-stopped + image: ghcr.io/paradigmxyz/reth + ports: + - '9001:9001' # metrics + - '30303:30303' # eth/66 peering + - '8545:8545' # rpc + volumes: + - rethdata:/root/.local/share/reth/mainnet/db + - rethlogs:/root/rethlogs + - ./jwttoken:/root/jwt:ro + command: > + node + --metrics 0.0.0.0:9001 + --log.persistent + --log.directory /root/rethlogs + --authrpc.addr 0.0.0.0 + --authrpc.port 8551 + --authrpc.jwtsecret /root/jwt/jwt.hex + --http --http.addr 0.0.0.0 --http.port 8545 + --http.api "eth,net" + + lighthouse: + restart: unless-stopped + image: sigp/lighthouse + depends_on: + - reth + ports: + - '5052:5052/tcp' + - '5053:5053/tcp' + - '5054:5054/tcp' # metrics + - '9000:9000/tcp' + - '9000:9000/udp' + volumes: + - lighthousedata:/root/.lighthouse + - ./jwttoken:/root/jwt:ro + command: > + lighthouse bn + --http --http-address 0.0.0.0 + --execution-endpoint http://reth:8551 + --metrics --metrics-address 0.0.0.0 + --execution-jwt /root/jwt/jwt.hex + --checkpoint-sync-url https://mainnet.checkpoint.sigp.io + + prometheus: + restart: unless-stopped + image: prom/prometheus + depends_on: + - reth + ports: + - 9090:9090 + volumes: + - ./prometheus/:/etc/prometheus/ + - prometheusdata:/prometheus + command: + - --config.file=/etc/prometheus/prometheus.yml + - --storage.tsdb.path=/prometheus + + grafana: + restart: unless-stopped + image: grafana/grafana + depends_on: + - reth + - prometheus + ports: + - 3000:3000 + environment: + PROMETHEUS_URL: http://prometheus:9090 + volumes: + - grafanadata:/var/lib/grafana + - ./grafana/datasources:/etc/grafana/provisioning/datasources + - ./grafana/dashboards:/etc/grafana/provisioning_temp/dashboards + # 1. Copy dashboards from temp directory to prevent modifying original host files + # 2. Replace Prometheus datasource placeholder with the actual name + # 3. Run Grafana + entrypoint: > + sh -c "cp -r /etc/grafana/provisioning_temp/dashboards/. /etc/grafana/provisioning/dashboards && + find /etc/grafana/provisioning/dashboards/ -name '*.json' -exec sed -i 's/$${DS_PROMETHEUS}/Prometheus/g' {} \+ && + /run.sh" + +volumes: + rethdata: + driver: local + rethlogs: + driver: local + lighthousedata: + driver: local + prometheusdata: + driver: local + grafanadata: + driver: local \ No newline at end of file diff --git a/etc/docker-monitoring.yml b/etc/docker-monitoring.yml deleted file mode 100644 index d9c439d01..000000000 --- a/etc/docker-monitoring.yml +++ /dev/null @@ -1,39 +0,0 @@ -version: '3' - -services: - prometheus: - image: prom/prometheus - ports: - - 9090:9090 - volumes: - - ./prometheus/:/etc/prometheus/ - - prometheus_data:/prometheus - command: - - --config.file=/etc/prometheus/prometheus.yml - - --storage.tsdb.path=/prometheus - extra_hosts: - - "host.docker.internal:host-gateway" # https://stackoverflow.com/a/43541732/5204678 - - grafana: - image: grafana/grafana - ports: - - 3000:3000 - environment: - PROMETHEUS_URL: http://prometheus:9090 - # 1. Copy dashboards from temp directory to prevent modifying original host files - # 2. Replace Prometheus datasource placeholder with the actual name - # 3. Run Grafana - entrypoint: > - sh -c "cp -r /etc/grafana/provisioning_temp/dashboards/. /etc/grafana/provisioning/dashboards && - find /etc/grafana/provisioning/dashboards/ -name '*.json' -exec sed -i 's/$${DS_PROMETHEUS}/Prometheus/g' {} \+ && - /run.sh" - volumes: - - grafana_data:/var/lib/grafana - - ./grafana/datasources:/etc/grafana/provisioning/datasources - - ./grafana/dashboards:/etc/grafana/provisioning_temp/dashboards - depends_on: - - prometheus - -volumes: - prometheus_data: - grafana_data: diff --git a/etc/generate-jwt.sh b/etc/generate-jwt.sh new file mode 100755 index 000000000..711b5b55d --- /dev/null +++ b/etc/generate-jwt.sh @@ -0,0 +1,4 @@ +# Borrowed from EthStaker's prepare for the merge guide +# See https://github.com/remyroy/ethstaker/blob/main/prepare-for-the-merge.md#configuring-a-jwt-token-file +mkdir -p jwttoken +openssl rand -hex 32 | tr -d "\n" | tee > jwttoken/jwt.hex \ No newline at end of file diff --git a/etc/prometheus/prometheus.yml b/etc/prometheus/prometheus.yml index 6444d4d87..8c578af3a 100644 --- a/etc/prometheus/prometheus.yml +++ b/etc/prometheus/prometheus.yml @@ -3,4 +3,4 @@ scrape_configs: metrics_path: "/" scrape_interval: 5s static_configs: - - targets: ['localhost:9001', 'host.docker.internal:9001'] + - targets: ['reth:9001'] \ No newline at end of file