Skip to content

Docker Network

KevinOneLedger edited this page Dec 1, 2020 · 10 revisions

Setup

Usage

Ubuntu

Install Docker

  1. Get convenience script from the official docker site and run it with sudo priveleges.
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
  1. Add your user to the 'docker' group in order to run as non-root user.
$ sudo usermod -aG docker your-user
  1. Log out and re-log in for the step above to take effect.

Install Docker Compose

  1. Upgrade apt sources.
$ sudo apt-get upgrade
  1. Download Docker Compose v1.27.4
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  1. Change mode of the binary to executable.
$ sudo chmod +x /usr/local/bin/docker-compose

Install Python Dependencies

  1. Install pip for python 2.7XX
$ sudo apt install python-pip
  1. Install python yaml package
$ pip install pyyaml

Clone Protocol Source Code

  1. Install git if you haven't already.
$ sudo apt install git
  1. Create a new directory to store your source code.
$ mkdir ~/go
  1. Clone Protocol repository.
$ git clone https://github.com/Oneledger/protocol.git
  1. Create directories to map as your shared volumes and export as environment variables.
$ mkdir -p -- ~/oldata/docker ~/oldata/docker/bin
$ export DOCKERPATH=~/oldata/docker
$ export DOCKERBIN=~/oldata/docker/bin
$ export PROTOCOLPATH=~/go/protocol

Build Docker Image

  1. Navigate to default folder in the protocol source code.
cd ~/go/protocol/DOCKER-network/default
  1. Build docker image.
docker build -t olprotocol .

MacOS

Install HomeBrew

If HomeBrew is already installed, please skip this step

  • Install using official script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Check result:
brew -v

Some version info should come out after this command.

Install Docker

Here CASK is needed, we need to install desktop version to handle macOS's permission request. After installed, we can use the cli version comes with desktop version.

brew install cask docker

After this is done, open docker desktop from launchpad, it will take some time to start.

Once it shows docker is running, try:

docker ps

If there is no error, docker is installed and working fine.

Install Docker Compose

brew install docker-compose

After it's installed, try:

docker-compose -v

There should be some version info come out.

Install Python Dependencies

macOS comes with python2

  1. Install pip for python 2.7XX
sudo -H python -m ensurepip
  1. Install python yaml package
$ pip install pyyaml

Clone Protocol Source Code

  • Install git if you haven't already.
brew install git

And follow the rest part in Ubuntu section: Clone Protocol Source Code

Windows

Install Docker Desktop

  1. Visit Docker's official website to download Docker Desktop: https://docs.docker.com/docker-for-windows/install/ (Keep in mind you will need a specific version of Windows 10 or higher)
  2. Once you have followed all the installation steps, you will be prompted to restart.
  3. After you have resarted, the docker deamon will attempt to start, then will prompt you to upgrade WSL2(Windows Subsystem for Linux). Follow the link provided and follow the steps.
  4. Once WSL2 has been updated, the docker daemon will start.

Install Python Dependencies

  1. Install python 2.7 for Windows: https://www.python.org/download/releases/2.7/
  2. Install python module pyyaml
  3. Note - In powershell the default command is py, if you have other versions of python installed on your machine use the command py -2 to specify python 2.7

Clone Protocol Source Code

  1. Install Git for Windows: https://git-scm.com/download/win
    • If you are going to use the portable version remember to add the git binary path to your PATH environment variable.
  2. Follow the instructions from Ubuntu section: Clone Protocol Source Code (Remember to create appropriate directories and environment variables in Windows)

Description

In order to use the Oneledger docker network you will have to use the python command line interface application located in the protocol repository:

.../protocol/DOCKER-network/dockernet

This application allows a developer to build and run a local blockchain network with custom specifications.

General expected flow of commands:

  1. Initialize docker compose files (init)
  2. Start Network (start)
  3. Rebuild binaries an restart network (update) - Can be done multiple times
  4. Stop and remove containers and networks (stop)

usage: dockernet [-h] {init,start,update,stop,run} ...

positional arguments:
  {init,start,update,stop,run}
                        sub-command help
    init                generate docker compose files
    start               start network with generated docker compose files
    update              stop containers, rebuild binaries and start back up
    stop                stop and remove all containers and networks
    run                 run command inside container

optional arguments:
  -h, --help            show this help message and exit

Commands

  1. Initialize - init

usage: dockernet init [-h] [--validators VALIDATORS]
                      [--nonvalidators NONVALIDATORS] [--loglevel LOGLEVEL]
                      [--total_funds TOTAL_FUNDS]
                      [--maturity_time MATURITY_TIME]
                      [--deleg_rewards_maturity_time DELEG_REWARDS_MATURITY_TIME]
                      [--rewards_interval REWARDS_INTERVAL]
                      [--funding_deadline FUNDING_DEADLINE]
                      [--voting_deadline VOTING_DEADLINE]
                      [--timeout_commit TIMEOUT_COMMIT] [--docker]
                      [--subnet SUBNET] [--empty_blocks] [--eth_rpc ETH_RPC]
                      [--deploy_smart_contracts] [--eth_pk ETH_PK] [--default]
                      [--image IMAGE] [--protocol_path PROTOCOL_PATH]
                      [--docker_path DOCKER_PATH] [--docker_bin DOCKER_BIN]
optional arguments:
  -h, --help            show this help message and exit
  --validators VALIDATORS
                        number of validator nodes
  --nonvalidators NONVALIDATORS
                        number of non validator nodes
  --loglevel LOGLEVEL   level of logging for each node
  --total_funds TOTAL_FUNDS
                        initial funds for the network
  --maturity_time MATURITY_TIME
                        staking maturity time in blocks
  --deleg_rewards_maturity_time DELEG_REWARDS_MATURITY_TIME
                        delegation rewards maturity in blocks
  --rewards_interval REWARDS_INTERVAL
                        number of reward blocks stored in one record
  --funding_deadline FUNDING_DEADLINE
                        governance proposal funding deadline in blocks
  --voting_deadline VOTING_DEADLINE
                        governance proposal voting deadline in blocks
  --timeout_commit TIMEOUT_COMMIT
                        time between each block creation in (ms)
  --docker              docker flag used by olfullnode init
  --subnet SUBNET       subnet of all node IP addresses
  --empty_blocks        create empty blocks
  --eth_rpc ETH_RPC     smart contract url
  --deploy_smart_contracts
                        deploy ethereum smart contract
  --eth_pk ETH_PK       ethereum test private key
  --default             use default docker compose files
  --image IMAGE         name of docker image
  --protocol_path PROTOCOL_PATH
                        protocol source code path (env variable used if not specified)
  --docker_path DOCKER_PATH
                        docker shared volume for nodes (env variable used if not specified)
  --docker_bin DOCKER_BIN
                        path for protocol executables (env variable used if not specified)
  1. Start - start

usage: dockernet start [-h] [--docker_path DOCKER_PATH]
                       [--docker_bin DOCKER_BIN] [--deploy_smart_contracts]
optional arguments:
  -h, --help            show this help message and exit
  --docker_path DOCKER_PATH
                        docker shared volume for nodes (env variable used if not specified)
  --docker_bin DOCKER_BIN
                        path for protocol executables (env variable used if not specified)
  --deploy_smart_contracts
                        wait for smart contract to be deployed before starting nodes
                        (argument is only necessary if it was specified in the init command)
  1. Update - update

usage: dockernet update [-h] [--genesis]
optional arguments:
  -h, --help  show this help message and exit
  --genesis   clean node data and start from genesis stored in $DOCKERPATH
  1. Stop - stop

usage: dockernet stop [-h] [--clean]
optional arguments:
  -h, --help  show this help message and exit
  --clean     clean node data
  1. Run - run

usage: dockernet run [-h] container cmd
.
positional arguments:
  container   container to execute command in
  cmd         command to be executed in container
.
optional arguments:
  -h, --help  show this help message and exit
Clone this wiki locally