Setting up a docker node on CentOS from scratch

This guide covers both NANO's Main Network and Beta Network


Prerequisities

Your server is running on x64 architecture, has a SSD of at least 10GB (more is better), and at least 2GB RAM (3GB or 4GB is highly recommended), and at least 3TB of traffic quota per month. You have set up a CentOS 7 VPS already and have access to SSH. I may add another guide on how to achieve this.
"Why CentOS" you ask? It is known for its stability. You can of course use a different Linux disto, if you like.


Installing and starting docker

To install Docker Community Edition ("CE") on CentOS as of june 2018, the command is: sudo yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm and answer the prompt with y
For other platforms and other versions go to the docker Install documentation

To start docker, enter systemctl start docker


Downloading and running the NANO repository

Docker does most of the legwork for you, because the NANO team has put all config files on the DockerHub. So to download and install the repository including all latest commits, enter either sudo docker pull nanocurrency/nano (for MainNet a.k.a. Live Network) or sudo docker pull nanocurrency/nano-beta:latest (for BetaNet)

In theory, you can install both on the same machine, because the ports and folders shouldn't overlap. But in reality, due to a programming inconsistency, they do by default.

To start the node, enter either sudo docker run --name NANO -d -p 7075:7075/udp -p 7075:7075 -p [::1]:7076:7076 -v ~:/root nanocurrency/nano for the MainNet or sudo docker run --name BeNANO -d -p 54000:54000/udp -p 54000:54000 -p [::1]:7076:7076 -v ~:/root nanocurrency/nano-beta:latest for the BetaNet.

Next time you want to start the node daemon, you can use the docker start NANO command for example (capitalization matters).

For more information about the flags in this command, got to the NANO Docker Wiki. The only addition that has been made here was to give the containers a meaningful alias to have more easy access to them.


Additional commands

List all running containers, their ID, uptime and alias

Enter sudo docker ps and the result will look like this: 6a727fd804e3 nanocurrency/nano "/bin/bash /entry.sh" 12 days ago Up 12 days 0.0.0.0:7075->7075/tcp, 0.0.0.0:7075->7075/udp, ::1:7076->7076/tcp NANO

List ALL containers/images, even inactive ones

Enter docker ps -a

Check if the node is working correctly

Enter curl -g -d '{ "action": "block_count" }' '[::1]:7076' and it will show you the current block count. You can compare it with the popular block explorers. Note that several hundred unchecked blocks is fine, because this contains invalid blocks that manipulated nodes send to you. On the first install, the number will be in the millions until the newly downloaded blocks are verified. The initial "bootstrap" as this process is called, should take about 1 to 6 hours depending on the server performance.

Edit the config.json

Make sure that you have a text editor installed. I prefer "nano" over "vi" for usability reasons, so I yum install nano, answer the prompt with y. And from then on, I simply need to type sudo nano ~/RaiBlocksBeta/config.json to access the BetaNet config file

Using CLI commands

sudo docker exec BeNANO /usr/bin/rai_node --wallet_list sudo docker exec BeNANO /usr/bin/rai_node --version

Make a shortcut for RPC calls

For specific commands you can pre-define an alias: alias getpeers='curl -g -d '"'"'{ "action": "peers" }'"'"' '"'"'[::1]:7076'"'"''
For simple dynamic actions enter: rpc() { curl -g -d '{ "action": "'$1'" }' '[::1]:7076'; }, now you can use rpc block_count. Attention: This doesn't work with actions that need additional arguments.
These aliases are not persistent once you closed the SSH window.

Make a shortcut for CLI commands

alias nanocli='sudo docker exec BeNANO /usr/bin/rai_node' From now on, you can simply type e.g. nanocli --version to retrieve the version, or nanocli --debug_block_count to retrieve the block height