Updated for the 8/16/2019 gman snapshot version
This guide is going to walk through setting up docker in linux. You can run this container on windows or MacOS, but I wont be covering those here specifically. This guide is specifically for installing a matrix docker node on linux. This will work the same on hosted or private servers. I’m going to make some assumptions that you are already familiar with node setup and understand the wallet A and wallet B usage and how to stake and all that fun stuff.
Step 1 -Install your favorite flavor of linux and connect using putty/ssh, or follow these commands sitting in front of your linux computer.
https://www.youtube.com/watch?v=63KuNVSdT_g (link to install Ubuntu)
Step 2 -Install Docker.
If you’re using ubuntu it’s as simple as running this command.
If you’re using debian, or another debian based system without the docker.io package, it’s a little more complicated if you aren’t familiar with linux, but you can follow the docker guide here. (ubuntu is easier) https://docs.docker.com/install/linux/docker-ce/debian/
I want to pause to explain the file and directory structure so you understand where you’re putting these files. You will need to pick a directory to store your signAccount.json file, and the keystore and gman directories. This directory can be any directory, but for the sake of this article, I will be using /mnt/data as the example. You will need a completely separate directory for each node that you wish to run. I am using container01 for this example.
These are the only files that you need to worry about creating manually. The other files are part of the container or downloaded separately.
Step 3– Create the directory structure. The -p switch will create any intermediate directories that don’t already exist.
Step 4– Download the required snapshot and organize files.
tar -xzvf chaindata1405031.tar.gz
mv chaindata/* ./
rm -rf chaindata
chmod -R 755 snapdir
Step 5– Create your signAccount.json file (I hate that I’m using nano for this guide. vim > nano)
When you create the json file, the format doesn’t matter as long as you get the text right. This is an example of what it can look like.
“Password”:”Your Secret Password to unlock the wallet”
Hit Ctrl+x to quit nano, click y to save the file, then hit enter to accept the signAccount.json file name.
Step 6- Copy your wallet B file into the /mnt/data/container01/keystore directory. This can be done a couple ways, most commonly being SCP, or just simply copy and paste the contents. Both options work just fine, but you need to name/rename the wallet file to contain ONLY the address of the wallet.
When you download your wallet file, it looks like this
But you need to rename it to this
If you want to create the file rather than use SCP you can just create a new file with nano
(Replace MAN.1jZVR6AR3KYPP8TC4pexoGGbyhQ9 with YOUR wallet address)
If you open the downloaded wallet file (created at wallet.matrix.io) using vim or nano (if on linux) or wordpad (windows) you will see something like this.
ou can copy and paste this info directly into your newly created wallet file with nano using the command above. It is very important that this file be saved in the keystore directory. (i.e.
Step 7- Create and start the docker container.
Lets break down what this is doing to help you understand when you’re creating multiple containers.
sudo docker run —
sudo gives you root access,
docker is the command to use docker, and
run pulls, creates, and runs the container.
sudo docker pull disarmm/matrix would just download the docker image but not create a container.
sudo docker create would create the container and not run it.
sudo docker start would start the container, if its already been created, and then obviously there is a stop counterpart to that. You’d use the run command for the initial setup, but if you had to reboot, you would use
sudo docker start matrix to start your container.
Next we have the
run -d. The
-d flag runs the container detached in the background, so that it doesn’t give you any output and doesn’t start you inside the container.
-e MAN_PORT=50505 switch allows you to create an environment variable and pass it to the container. Here, we are setting the variable MAN_PORT to equal 50505 and then the nodeConfig.sh script I’ve created uses that variable to set the port when starting the node. You would modify this port if you’re starting multiple containers, as they can’t all use the same port number. Port 50505 is not required to communicate with the network, so you can make this port anything you’d like. Note: If you start a container with a unique port like 50501 then your port forwarding rule in your firewall should forward 50501 to the IP of your docker host system. 50501 would be the port publicly exposed.
-p 50505:50505 switch publishes the peer communication port you are using to the host system so that you can use the same IP address for all your containers. The left side of the : is the port the host uses, and the right side is the port in the container. These need to be the same port for it to work correctly. For reasons I don’t want to explain, you can’t publish port 50506 on the host and link it to port 50501 in the container.
The tl;dr here is if
then this command should be
The next portion is
-v /mnt/data/container01:/matrix/chaindata and this pulls in a persistent volume from the host file system and uses it to store the node’s chaindata and a few config files. The path on the left side of the colon: is the host file system
/mnt/data/container01 and can be any directory on the host system that you’d like. I’ve chosen the
/mnt/data path on my system for a few reasons. The path on the right side of the :colon is where it is mounting the persistent volume in the container.
This part should be fairly straight forward,
--name matrix is the switch used to name your container, which is important for keeping track of your multiple nodes. You can use whatever name makes sense to you.
Finally, at the end end of that command is
disarmm/matrix this tells the
run command what docker image you want to use for this container. “disarmm” identifies my account on docker hub, and matrix is the name of the repository where I build my containers.
Now to drive it all home with some more examples…
If you were going to start multiple nodes it would look something like this:
$ sudo docker run -d -e MAN_PORT=50521 -p 50521:50521 -v /mnt/data/container21:/matrix/chaindata --name container21 disarmm/matrix $ sudo docker run -d -e MAN_PORT=50522 -p 50522:50522 -v /mnt/data/container22:/matrix/chaindata --name container22 disarmm/matrix $ sudo docker run -d -e MAN_PORT=50523 -p 50523:50523 -v /mnt/data/container23:/matrix/chaindata --name container23 disarmm/matrix
You can see that I map a unique volume path from the host file system and use the same number for the container name and I use the same number as the last digit in my port designation. This makes it easier to keep track of allocated resources and firewall rules.
That’s all you need to do to start the syncing. You will need to add your wallet file and create your signAccount.json file to actually start mining or validating, but because of the way the container is setup you don’t need your wallet info to start the syncing process. Once you’ve started the container, just let it run while you finish the rest of this config.
Sample output from $ sudo docker ps
You can type
$ sudo docker ps after it starts if you want to make sure it’s running.
$ sudo docker ps -a shows you all the containers, even if they are stopped. If it stops right after you start it, then you did something wrong. You can check the logs by typing
$ sudo docker logs containerName
You will also need to open ports in your firewall for each container you create. You might need to use google to figure out how to open ports in your personal or hosted firewall. You can then check the port status with https://www.yougetsignal.com/tools/open-ports/
If everything is setup correctly with your firewall, it should show open.
Step 8 -Connect to the console to see if you’re syncing or to run other commands as you would with a normal node.
$ sudo docker exec -it matrix bash -this command connects you to the docker container with a shell
# /matrix/gman attach /matrix/chaindata/gman.ipc -this command launches the console
Step 9 -Create additional nodes using a copy of your first. Explained here.
Note: you can add
--restart unless-stopped to the docker run command in step 7 to make it so your containers restart after a reboot, or auto restart if gman crashes. The container up-time or “status” should be watched carefully with the docker ps command. If the container keeps restarting and never stays up more than a few seconds, there is something wrong with your configuration and you need to check what is going wrong with
$ docker logs containerName
This setup can be used to launch multiple nodes on the same system, IF you have the resources to handle multiple nodes. You will need to mount different directories from the host file system in step 7 if you’re going to run multiple nodes. The problem with that right now is that then you end up with multiple copies of the blockchain, which is growing fast. I haven’t quite figured out a better solution for this yet.
So far the best choice for me has been to buy 4 x 4 TB WD Gold Enterprise drives to create a raid 10. This ended up being faster than using my previous SSDs in a raid0 configuration. This would allow for a two drive failure, as long as I don’t lose two drives in the same raid 1 mirror. This also makes it so I have lower clock speed servers handling all the syncing and once a nice is selected for mining, it gets restarted on my i9 node and runs by itself.
Also, here are the links to my github and my docker hub. You can read the scripts and dockerfile that is used to create this container.