Skip to content

Commit

Permalink
feat: add docker compose with docs (paradigmxyz#3496)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Nordbjerg <[email protected]>
  • Loading branch information
paolofacchinetti and onbjerg authored Jul 3, 2023
1 parent 770652a commit da58e39
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 51 deletions.
71 changes: 71 additions & 0 deletions book/installation/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
1 change: 1 addition & 0 deletions etc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jwttoken
12 changes: 1 addition & 11 deletions etc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
To run Reth, Grafana and Prometheus with Docker Compose, refer to the [docker docs](/book/installation/docker.md#using-docker-compose)
95 changes: 95 additions & 0 deletions etc/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 0 additions & 39 deletions etc/docker-monitoring.yml

This file was deleted.

4 changes: 4 additions & 0 deletions etc/generate-jwt.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion etc/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ scrape_configs:
metrics_path: "/"
scrape_interval: 5s
static_configs:
- targets: ['localhost:9001', 'host.docker.internal:9001']
- targets: ['reth:9001']

0 comments on commit da58e39

Please sign in to comment.