Running BNB Smart Chain GETH on Docker
-
Running BNB Smart Chain Node in a Docker Container
Description
This document describes the process of configuring and running a BNB Smart Chain node (geth) using the docker container image from the official git repository.Prerequisites
Server/Computer with at least 300GB+ of free disk space for testnet node
Docker
Official Docker ImageIntroduction to Docker
Docker is a tool that makes it easier for developers to create and deliver applications in containers. Containers allow developers to put an application with all of its requirements, such as libraries and other dependencies and deploy it as a single image. When running the application the user doesn’t need to know all the requirements to run a specific application, because it is all bundled together in this image. Basically when you are inside of a container you feel like you are in a completely different host, it feels like a Virtual Machine but it is actually not. Each container shares the kernel within the host OS, allowing you to run multiple Docker containers on the same host.
https://www.docker.com/Introduction to BSC Node
A node is basically a blockchain software that runs on the computer/server, when this software is started it will make a copy of the entire blockchain to your local machine and it will broadcast its data to the blockchain network helping it by serving the network with data.Why run your own node?
Not for RewardsNodes that are not validators do not receive any reward because they are not validating blocks.
Trust and Privacy
Running your own node enables you to use BNB Smart Chain in a private, self-sufficient and trustless manner. You don't need to trust the network because you can verify the data yourself with your client.Potential Better Performance
You have the control to decide what hardware specification you will build you own node on. This way you can potentially get better performance.
No limits and More data
When using public Nodes, specially for Dapps, the nodes have limits on the amount of calls you can make to the node. Also not all data is provided with public nodes, if you run your own node you can expose to yourself all the data from the blockchain, and be able to monitor things such as the transactions mem pool.Docker Installation
https://docs.docker.com/get-docker/Desktop Users:
https://docs.docker.com/get-docker/Ubuntu Linux:
https://docs.docker.com/engine/install/ubuntu/Post install:
Start docker during boot up:
systemctl enable docker.service
systemctl enable containerd.serviceAdd user "ubuntu" to group docker so the user has privileges to run docker commands:
sudo usermod -aG docker $USER
Login: tsh ssh ubuntu@172.21.42.10
Download Docker Container
Instructions: https://github.com/bnb-chain/bsc/pkgs/container/bsc
docker pull ghcr.io/bnb-chain/bsc:1.1.18_hfImportant commands:
List images available on your Docker host.$ docker images
List running containers
$ docker ps
List stopped containers
$ docker ps -a
Check container logs
$ docker logs containerName or ContainerID
Show container details
$ docker inspect containerName or ContainerID
Shell access container
$ docker exec -it containerName bashNode configuration
Download Testnet or Mainnet config filesReference: https://docs.bnbchain.org/docs/validator/fullnode
Create Directories
mkdir -p ~/bsc/config
mkdir -p ~/bsc/nodeif you are not running as root open permissions to node directory, this will permit that docker container create data under the node folder
chmod 777 ~/bsc/node
cd ~/bsc/config
wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep testnet |cut -d" -f4)
unzip testnet.zip
cd ~/bscPS: Don’t need to write genesis state
Start Container$ docker run (options) imageName
Example:
$ docker run -d --name bsccontainer01 -v ~/bsc/node:/bsc/node -v ~/bsc/config:/bsc/config ghcr.io/bnb-chain/bsc:1.1.18_hfOptions
-d -> Detached from the screen. It will run the container in the background.
–name -> name of the container
-v -> For volume, in our case we are going to be binding our local disk to certain directories inside of the container-v ~/bsc/node:/bsc/nod -> Local ~/bsc/node will be mounted on /bsc/node in the container
~/bsc/config:/bsc/config -> Local ~/bsc/config directory will be mounted on /bsc/config in the containerCheck if container is running
$ docker ps
If it is running you can check the logs/output of the startup command
$ docker logs bsccontainer01
Check blockchain data logs
docker exec -it bsccontainer01 tail -f node/bsc.logConnect to local Javascript interface using IPC and check synchronization status
docker exec -it bsccontainer01 geth attach ipc:node/geth.ipceth.syncing
How to shell into the Container:
$ docker exec -it bsccontainer01 bashHow to expose HTTP Json RPC?
Stop/start container
$ docker stop bsccontainer01$ docker start bsccontainer01
Remove container
$ docker rm bsccontainer01Edit config.toml
-> HTTPHost = "0.0.0.0"Run container with exposing RPC port to host
$ docker run -d --name bsccontainer01 -p 8575:8575 -v ~/bsc/node:/bsc/node -v ~/bsc/config:/bsc/config ghcr.io/bnb-chain/bsc:1.1.18_hfNote: By default testnet configuration runs http json-rpc server on port 8575.
-p 8575:8575 -> we are exposing port 8575 to the host that is running docker and it will map with port 8575 that is open in the container.
After we run this you will be able to reach the http json rpc on port 8575 of the host such as follows:
$ geth attach http://HOST_IP:8575How to make changes in the configuration or set geth flags?
In order to pass custom changes (flag) to geth you can just need to add the flags to the end of the docker run command as follows:
Stop container
$ docker stop bsccontainer01Remove container
$ docker rm bsccontainer01Run container with desired flags. The following example shows how to enable websocket and expose the websocket port.
$ docker run -d --name bsccontainer01 -p 3335:3335 -p 8575:8575 -v ~/bsc/node:/bsc/node -v ~/bsc/config:/bsc/config ghcr.io/bnb-chain/bsc:1.1.18_hf --ws.port 3335 --ws.addr 0.0.0.0 --ws --ws.api eth,net,web3 --ws.origins "*"Test connection
./geth attach ws://172.21.42.10:3335
Docker Compose
Docker compose will help maintain the configuration of the docker, it will make it easier to start and shutdown your containers.
“Docker run is entirely command line based, while docker-compose reads configuration data from a YAML file”
Add the following to a docker-compose.yml file:
Vi docker-compose.yml
version: '3.6'
services:
bscnode:
image: ghcr.io/bnb-chain/bsc:1.1.18_hf
command: --ws.port 3335 --ws.addr 0.0.0.0 --ws --ws.api eth,net,web3 --ws.origins "*"
restart: unless-stopped
container_name: bsccontainer01
ports:
- 8575:8575
- 3335:3335
volumes:
- ~/bsc/node:/bsc/node
- ~/bsc/config:/bsc/configStop Old Container and Remove
docker stop bsccontainer01
docker rm bsccontainer01Using Docker compose to control your container.
Start
$ docker compose up -dStop (this will remove the container)
$ docker compose downExtra Resources:
https://confluence.toolsfdg.net/display/Technology/BNB+Smart+Chain+Docker+Runbook