Forest in Docker 🌲 ❤️ 🐋
Prerequisites
- Docker engine installed and running. Forest containers are confirmed to run on
the following engines:
- Docker Engine (Community) on Linux,
- Docker for macOS
- Docker on Windows Subsystem for Linux 2(WSL2)
Native images are available for the following platform/architecture(s):
linux/arm64linux/amd64
The images will work out-of-the box on both Intel processors and macOS with M1 / M2.
Tags
For the list of all available tags please refer to the Forest packages.
Currently, the following tags are produced:
latest- latest stable release,latest-fat- latest stable release with necessary downloadable files preloaded,edge- latest development build of themainbranch,edge-fat- latest development build of themainbranch with necessary downloadable files preloaded,date-digeste.g.,2023-02-17-5f27a62- all builds that landed on themainbranch,date-digest-fate.g.,2023-02-17-5f27a62-fat- all builds that landed on themainbranch with necessary downloadable files preloaded,- release tags, available from
v0.7.0orv0.7.0-fatonwards.
Security recommendations
- We strongly recommend running the docker daemon in rootless mode
(installation instructions),
or running the daemon-less docker alternative
podman(installation instructions) with non-root user and putalias docker = podman(or manually replace thedockercommands withpodmanin below instructions)
Performance recommendations
- We recommend lowering the swappiness kernel parameter on Linux to 1-10 for
long running forest node by doing
sudo sysctl -w vm.swappiness=[n].
Example usages
List available flags and/or commands
# daemon
docker run --init -it --rm ghcr.io/chainsafe/forest:latest --help
# cli
docker run --init -it --rm --entrypoint forest-cli ghcr.io/chainsafe/forest:latest --help
# tool
docker run --init -it --rm --entrypoint forest-tool ghcr.io/chainsafe/forest:latest --help
# wallet tool
docker run --init -it --rm --entrypoint forest-wallet ghcr.io/chainsafe/forest:latest --help
Also see the CLI documentation for more details about commands and their usage.
Run a Forest node with custom environment variables
docker run --init -it --rm --name forest --env <key>=<value> ghcr.io/chainsafe/forest:latest --chain calibnet --auto-download-snapshot
Check Forest environment variables documentation for more details.
Create a Forest node running calibration network. Then list all connected peers.
Interactive mode:
docker run --init -it --rm --name forest ghcr.io/chainsafe/forest:latest --chain calibnet --auto-download-snapshot
Non-interactive mode
docker run --init --name forest ghcr.io/chainsafe/forest:latest --chain calibnet --auto-download-snapshot
watchtower is a great tool for keeping the forest image up-to-date, automagically, check instructions.
Then, in another terminal:
docker exec forest forest-cli net peers
Sample output:
12D3KooWAh4qiT3ZRZgctVJ8AWwRva9AncjMRVBSkFwNjTx3EpEr, [/ip4/10.0.2.215/tcp/1347, /ip4/52.12.185.166/tcp/1347]
12D3KooWMY4VdMsdbFwkHv9HxX2jZsUdCcWFX5F5VGzBPZkdxyVr, [/ip4/162.219.87.149/tcp/30141, /ip4/162.219.87.149/tcp/30141/p2p/12D3KooWMY4VdMsdbFwkHv9HxX2jZsUdCcWFX5F5VGzBPZkdxyVr]
12D3KooWFWUqE9jgXvcKHWieYs9nhyp6NF4ftwLGAHm4sCv73jjK, [/dns4/bootstrap-3.calibration.fildev.network/tcp/1347]
Make the node reachable by other peers
By default, Forest listens on random ports, and the default Docker bridge network
publishes none of them. Such a node can still connect to other peers, but no
peer can connect to it, and it advertises only its container address (e.g.
172.17.0.2), which can't be dialed from outside. Such a node doesn't show up
in network measurements either.
To make the node reachable, listen on fixed ports for both TCP and QUIC, and open both TCP and UDP on that port in the host's firewall. If the host is behind a NAT router, also forward TCP and UDP on that port from the router to the host's LAN address. Alternatively, with host networking and UPnP enabled on the router, Forest requests the mapping itself, but this doesn't work with every router.
The examples below reuse the container name forest, so remove any container
started earlier (docker rm -f forest). Its data is removed with it, unless it
is stored in a volume, see shared volume.
On Linux, host networking is the most reliable option, as the node then sees the host's addresses directly:
docker run --init -it --rm --network host --name forest ghcr.io/chainsafe/forest:latest \
--chain calibnet --auto-download-snapshot \
--p2p-listen-address /ip4/0.0.0.0/tcp/34000 \
--p2p-listen-address /ip4/0.0.0.0/udp/34000/quic-v1
Rootless podman supports this too. With rootless Docker older than Engine
v29.5, --network host still uses a separate network namespace, so use the
bridge network setup below instead.
If the public IP is assigned to one of the host's interfaces,
docker exec forest forest-cli net listen includes it. Behind a NAT router, it
shows only local addresses, so use forest-cli net reachability or the check
from a different machine described below.
With the bridge network, publish the same port number on the host as inside the container, for both protocols:
docker run --init -it --rm -p 34000:34000/tcp -p 34000:34000/udp --name forest ghcr.io/chainsafe/forest:latest \
--chain calibnet --auto-download-snapshot \
--p2p-listen-address /ip4/0.0.0.0/tcp/34000 \
--p2p-listen-address /ip4/0.0.0.0/udp/34000/quic-v1
In that case, the node only advertises its public address after other peers
confirm that it is reachable. docker exec forest forest-cli net reachability
then reports Public together with that address.
Either way, the reliable check is to connect to the node from a different machine, see network reachability.
Use a shared volume to utilize across different Forest images
Create the volume
docker volume create forest-data
Now, whenever you create a new Forest container, attach the volume to where the
data is stored /root/.local/share/forest.
docker run --init -it --rm \
--ulimit nofile=8192 \
--volume forest-data:/root/.local/share/forest \
--name forest ghcr.io/chainsafe/forest:latest --chain calibnet
--auto-download-snapshot
Export the calibnet snapshot to the host machine
Assuming you have forest container already running, run:
docker exec forest forest-cli --chain calibnet snapshot export
Sample output:
Export completed. Snapshot located at forest_snapshot_calibnet_2023-02-17_height_308891.car
Copy the snapshot to the host
docker cp forest:/home/forest/forest_snapshot_calibnet_2023-02-17_height_308891.car .