(Notes) Notes (2020)

Dockerizing Masternodes

1. Last minute changing.

Warning! Finally I have replaced /tmp/ directory in each my docker images to /root/ because something going wrong with /tmp directory. So, you need to rebuild images by the same way:


# sudo docker build -f digiwage.dockerfile -t alexev275/digiwage .

FROM alexev275/digiwage:latest
COPY digiwage-startup.sh /startup.sh
COPY digiwage.conf   /root/digiwage-tmp.conf
RUN chmod 777 /startup.sh

And, of course, you need to modify startup.sh files by the same way:


...
set -eux -o pipefail
...


sed -i "s/{{RPC_PASSWORD}}/$RPC_PASSWORD/g" /root/digiwage-tmp.conf
sed -i "s/{{RPC_ALLOW_IP}}/$RPC_ALLOW_IP/g" /root/digiwage-tmp.conf
sed -i "s/{{RPC_CONNECT_IP}}/$RPC_CONNECT_IP/g" /root/digiwage-tmp.conf
sed -i "s/{{RPC_PORT}}/$RPC_PORT/g" /root/digiwage-tmp.conf
sed -i "s/{{EXTERNAL_IP}}/$EXTERNAL_IP/g" /root/digiwage-tmp.conf
sed -i "s/{{MASTERNODE_PRIV_KEY}}/$MASTERNODE_PRIV_KEY/g" /root/digiwage-tmp.conf
sed -i "s/{{TX_INDEX}}/$TX_INDEX/g" /root/digiwage-tmp.conf
sed -i "s/{{SEED_NODE}}/$SEED_NODE/g" /root/digiwage-tmp.conf
sed -i "s/{{PORT}}/$PORT/g" /root/digiwage-tmp.conf

cat /root/digiwage-tmp.conf
cp /root/digiwage-tmp.conf /root/.digiwage/digiwage.conf

ulimit -m unlimited
ulimit -v unlimited
ulimit -n 65536


cat /root/.digiwage/digiwage.conf
exec digiwaged -conf=/root/.digiwage/digiwage.conf -reindex -forcestart

2. Build coinbase [download from docker hub]


   1:  FROM ubuntu:xenial
   2:   
   3:  RUN apt-get update && \
   4:      apt-get -y upgrade && \
   5:      apt-get -y install \
   6:        apt-utils \
   7:        git \
   8:        libwww-perl \
   9:        build-essential \
  10:        libtool \
  11:        automake \
  12:        autotools-dev \
  13:        autoconf \
  14:        pkg-config \
  15:        libssl-dev \
  16:        libgmp3-dev \
  17:        libevent-dev \
  18:        bsdmainutils \
  19:        libdb++-dev \
  20:        libboost-all-dev \
  21:        libqrencode-dev \
  22:        libminiupnpc-dev \
  23:        libcurl4-openssl-dev \
  24:        libdb-dev \
  25:        libdb++-dev \
  26:        unzip \
  27:        curl \
  28:        wget \
  29:        aptitude \
  30:        nano \
  31:        zip

This docker creaiting by simplest way. Than need only docker login -u alexev275 -p and docker push alexev275/coinbase


3. Build coinbase-boost [download from docker hub]

As start point Ubuntu 16.04 contains boost 1.58, but most of software use more fresh version.



I have produced this image in this way compile boost 1.66.0 from source on ubuntu 16.04 as start coinbase image interactively - docker run -it alexev275/coinbase



After installation I have received boost 1.66, but dpkg -s libboost-dev | grep 'Version' still show 1.58.



Then I have commited transaction and push this docker to docker hub.



4. Biuld genesisx [download from docker hub]

genesis-build


   1:  #!/bin/bash
   2:  # must be prepared genesisx.conf, startup.sh, block.sh
   3:  sudo docker  build -f genesisx1.dockerfile -t alexev275/genesisx .

dockerfile


   1:  FROM alexev275/coinbase
   2:   
   3:  ## Enviroment Variables For Propper Functioning
   4:  ENV DEBIAN_FRONTEND=noninteractive
   5:  ENV RPC_USER=
   6:  ENV RPC_PASSWORD=
   7:  ENV RPC_PORT=
   8:   
   9:  ## Set Work Directory to root
  10:  WORKDIR /root
  11:   
  12:  ## Clone from github
  13:  RUN git clone https://github.com/genesis-x/genesis-x/ genesisx
  14:   
  15:  ## Change Working Directory - Pre Build
  16:  WORKDIR /root/genesisx
  17:   
  18:  # Perform wallet build
  19:  RUN chmod 777 share/*sh
  20:  RUN chmod 777 src/leveldb/build*
  21:  RUN bash ./autogen.sh && \
  22:          ./configure --with-incompatible-bdb && \
  23:          make -j 6 && \
  24:          strip src/genesisxd && \
  25:          make install
  26:   
  27:  ## Set working directory
  28:  WORKDIR /root
  29:   
  30:  ## Remove source folder
  31:  RUN rm -rf giantcoin
  32:   
  33:  ## Copy files to build system ready for execution
  34:   
  35:  COPY genesisx.conf /tmp/genesisx.conf
  36:  COPY startup.sh /
  37:  COPY block.sh /
  38:  RUN chmod 777 /block.sh
  39:  RUN chmod 777 /startup.sh
  40:   
  41:   
  42:  ## Make wallet datadirectory
  43:  RUN mkdir /root/.genesisx
  44:   
  45:  VOLUME /root/share
  46:  ## Set Startup Command
  47:  CMD ["/startup.sh"]

genesisx.conf


   1:  blocknotify=/block.sh %s
   2:  dbcache=64
   3:  maxmempool=128
   4:  maxconnections=8
   5:  par=1
   6:  rpcthreads=1
   7:  rpcuser=insane
   8:  rpcpassword={{RPC_PASSWORD}}
   9:  rpcallowip={{RPC_ALLOW_IP}}
  10:  rpcconnect={{RPC_CONNECT_IP}}
  11:  rpcport={{RPC_PORT}}
  12:  port={{PORT}}
  13:  externalip={{EXTERNAL_IP}}
  14:  server=1
  15:  listen=1
  16:  daemon=0
  17:  logtimestamps=1
  18:  txindex={{TX_INDEX}}
  19:  maxconnections=8
  20:  mnconflock=1
  21:  masternode=1
  22:  masternodeaddr={{EXTERNAL_IP}}:5555
  23:  masternodeprivkey={{MASTERNODE_PRIV_KEY}}
  24:  stake=0
  25:  staking=0

block.sh


   1:  #!/bin/bash
   2:  clear
   3:   
   4:  if [ -z $CONTAINER_ID ]; then
   5:  echo "ContainerID Not Set"
   6:  fi
   7:   
   8:  DATE=$(date)
   9:  BLOCK=$1
  10:  CONTAINERID=$CONTAINER_ID
  11:  BALANCE=$(genesisx-cli getbalance)
  12:  BLOCKS=$(genesisx-cli  getblockcount)
  13:  BLOCKHASH=$(genesisx-cli  getbestblockhash)
  14:  CONNCOUNT=$(genesisx-cli  getconnectioncount)
  15:  DIFF=$(genesisx-cli  getdifficulty)
  16:  BALANCE=$(genesisx-cli  getbalance)
  17:   
  18:  PUBKEY=$(genesisx-cli masternode status | grep pubkey | sed 's/"pubkey" : //g' | sed 's/,//g' | sed 's/["]//g' | sed 's/     //g' | sed 's/ //g' )
  19:  SERVICE=$(genesisx-cli masternode status | grep service | sed 's/"service" : //g' | sed 's/,//g' | sed 's/["]//g' | sed 's/ //g')
  20:  STATUS=$(genesisx-cli masternode status | grep status  | sed 's/"status" : //g' | sed 's/,//g' | sed 's/["]//g' | sed 's/ /-/g' | sed 's/----//g' | sed 's/ //g' )
  21:   
  22:  DISKSTATUS=$(df / | grep overlay | sed 's/ /-/g' | sed 's/--/-/g' | sed 's/-----/-/g' | sed 's/[/]//g' )
  23:  LOADAVG=$(cat /proc/loadavg | sed 's/ /-/g' | sed 's/[/]//g')
  24:  UPTIME=$(cat /proc/uptime | sed 's/ /-/g')
  25:   
  26:  TOTALMEM=$(cat /proc/meminfo | grep MemTotal: | sed 's/MemTotal://g' | sed 's/ kB//g' | sed 's/ //g')
  27:  FREEMEM=$(cat /proc/meminfo | grep MemFree: | sed 's/MemFree://g' | sed 's/ kB//g' | sed 's/ //g')
  28:  AVAILMEM=$(cat /proc/meminfo | grep MemAvailable: | sed 's/MemAvailable://g' | sed 's/ kB//g' | sed 's/ //g')
  29:   
  30:  echo "";
  31:  echo "At " $DATE
  32:  echo "A new block with hash " $BLOCK
  33:  echo "was detected, the current block height is " $BLOCKS
  34:  echo "the wallet balance is " $BALANCE
  35:  echo "Container = " $CONTAINERID
  36:  echo "BlockHash = " $BLOCKHASH
  37:  echo "Connection Count = " $CONNCOUNT
  38:  echo "Diff = " $DIFF
  39:  echo "Balance = " $BALANCE

startup.sh


   1:  #!/bin/bash
  -->  set -eux -o pipefail
   2:  if [ -z $RPC_PASSWORD ]; then
   3:    echo "Need to set env RPC_PASSWORD"
   4:    exit 1
   5:  fi
   6:   
   7:  if [ -z $EXTERNAL_IP ]; then
   8:    echo "Need to set env EXTERNAL_IP"
   9:    exit 1
  10:  fi
  11:   
  12:  if [ -z $MASTERNODE_PRIV_KEY ]; then
  13:    echo "Need to set env MASTERNODE_PRIV_KEY"
  14:    exit 1
  15:  fi
  16:   
  17:   
  18:  if [ -z $TX_INDEX ]; then
  19:    echo "Need to set env TX_INDEX"
  20:    exit 1
  21:  fi
  22:   
  23:  if [ -z $SEED_NODE ]; then
  24:    echo "Need to set env SEED_NODE"
  25:    exit 1
  26:  fi
  27:   
  28:  if [ -z $PORT ]; then
  29:    PORT=10255
  30:  fi
  31:   
  32:  if [ -z $RPC_PORT ]; then
  33:    RPC_PORT=10257
  34:  fi
  35:   
  36:  if [ -z $RPC_ALLOW_IP ]; then
  37:    RPC_ALLOW_IP=127.0.0.1
  38:  fi
  39:   
  40:  if [ -z $RPC_CONNECT_IP ]; then
  41:    RPC_CONNECT_IP=127.0.0.1
  42:  fi
  43:   
  44:  sed -i "s/{{RPC_PASSWORD}}/$RPC_PASSWORD/g" /tmp/genesisx.conf
  45:  sed -i "s/{{RPC_ALLOW_IP}}/$RPC_ALLOW_IP/g" /tmp/genesisx.conf
  46:  sed -i "s/{{RPC_CONNECT_IP}}/$RPC_CONNECT_IP/g" /tmp/genesisx.conf
  47:  sed -i "s/{{RPC_PORT}}/$RPC_PORT/g" /tmp/genesisx.conf
  48:  sed -i "s/{{EXTERNAL_IP}}/$EXTERNAL_IP/g" /tmp/genesisx.conf
  49:  sed -i "s/{{MASTERNODE_PRIV_KEY}}/$MASTERNODE_PRIV_KEY/g" /tmp/genesisx.conf
  50:  sed -i "s/{{TX_INDEX}}/$TX_INDEX/g" /tmp/genesisx.conf
  51:  sed -i "s/{{SEED_NODE}}/$SEED_NODE/g" /tmp/genesisx.conf
  52:  sed -i "s/{{PORT}}/$PORT/g" /tmp/genesisx.conf
  53:   
  54:  cp /tmp/genesisx.conf /root/.genesisx/genesisx.conf
  55:   
  56:  ulimit -m unlimited
  57:  ulimit -v unlimited
  58:  ulimit -n 65536
  59:  exec genesisxd -conf=/root/.genesisx/genesisx.conf

5. Build digiwage [download from docker hub]

similar as above

6. Build kalkulus [download from docker hub]

similar as above

7. Build giant [download from docker hub]

similar as above

8. Build unigrid [download from docker hub]

similar as above

Unigrid is not possible to assemble from source code. I have created unigrid docker by the same way.


   1:  ## Use Base Template
   2:  FROM alexev275/coinbase
   3:   
   4:  ## Enviroment Variables For Propper Functioning
   5:  ENV DEBIAN_FRONTEND=noninteractive
   6:  ENV RPC_USER=
   7:  ENV RPC_PASSWORD=
   8:  ENV RPC_PORT=
   9:  ENV BOOST_ROOT=
  10:   
  11:  ## Set Work Directory to root
  12:  WORKDIR /root
  13:   
  14:  #download outside of container
  15:  #curl -OL https://github.com/unigrid-project/daemon/releases/download/2.0.1/unigrid-2.0.1-x86_64-linux-gnu.tar.gz
  16:   
  17:  ## Copy files to build system ready for execution
  18:  COPY unigrid.conf /tmp/unigrid.conf
  19:  COPY startup.sh /
  20:  COPY block.sh /
  21:  RUN chmod 777 /block.sh
  22:  RUN chmod 777 /startup.sh
  23:   
  24:  ## Make wallet datadirectory
  25:  RUN mkdir /root/.unigrid
  26:   
  27:  # Optional Copy blockchain.zip
  28:  #COPY bootstrap.zip /root/.unigrid
  29:   
  30:  VOLUME /root/share
  31:   
  32:  ## Set Startup Command
  33:  CMD ["/startup.sh"]

9. How to start this dockers

docker run -it --name fffff429-4ef2-4f3c-a6f5-35253453456b --expose=26969 -e RPC_PASSWORD=rpcpassword123456 -e EXTERNAL_IP=268.119.134.247 -e MASTERNODE_PRIV_KEY=7eK9Fviqs5VM1ZYeaLgsT8p5cBiBbQvzMygfwWpWSFRjSUDRfH4 -e TX_INDEX=1 -e SEED_NODE='95.168.179.73' -e CONTAINER_ID=fffff429-4ef2-4f3c-a6f5-35253453456b -p 268.119.134.247:12455:12455 genesisx

or

docker run -d -it --name fffff429-4ef2-4f3c-a6f5-35253453456b --expose=26969 -e RPC_PASSWORD=rpcpassword123456 -e EXTERNAL_IP=268.119.134.247 -e MASTERNODE_PRIV_KEY=7eK9Fviqs5VM1ZYeaLgsT8p5cBiBbQvzMygfwWpWSFRjSUDRfH4 -e TX_INDEX=1 -e SEED_NODE='95.168.179.73' -e CONTAINER_ID=fffff429-4ef2-4f3c-a6f5-35253453456b -p 268.119.134.247:12455:12455 10.1.12.1:5000/genesisx


or even more usable

sudo docker run -it \
--name digiwage.$(date +%Y-%m-%d-%H.%M.%S) \
--expose='46003' \
-e RPC_PASSWORD=$(xxd -l 32 -c 32 -p /dev/urandom) \
-e EXTERNAL_IP='157.XX.XX.85' \
-e MASTERNODE_PRIV_KEY='123456qrknGeLLEqnUgRBPtrBxQ3o5VBp4bkRy4fHN3ZpzURHdkr' \
-e TX_INDEX='1' \
-e SEED_NODE='95.168.179.73' \
-e PORT='46003' \
-e RPC_ALLOW_IP='127.0.0.1' \
-e RPC_CONNECT_IP='127.0.0.1' \
-p '157.XX.XX.85:46003:46003' \
alexev275/digiwage:latest

10. How to connect to working container and check masternode.

There are two way to connect (1) to bash command interpreter or (2) with one bash command.


# sudo docker ps 
# sudo docker exec -it 543622d2d019 bash
# sudo docker exec -it 543622d2d019 digiwage-cli getinfo
# sudo docker exec -it 543622d2d019 tail -n 100 .digiwage/debug.log


11. Allow exposed port in docker host.

# sudo ufw status verbose
# sudo ufw allow 46003/udp
# sudo ufw allow 46003/tcp






Comments ( )
Link to this page: //www.vb-net.com/DockerizingMasternodes/Index.htm
< THANKS ME>