Skip to content

Running Amity Using Docker

Michael Herwig edited this page Nov 15, 2018 · 4 revisions

Running Amity Using Docker

TLDR; Install

First we need to install docker and docker-compose. Note install scripts are taken from docker.com. If you run in any problems please checkout their instructions or text us on discord. Please click your corresponding host operating system to see install instructions.

CentOS
sudo yum install -y               \
    yum-utils                     \
    device-mapper-persistent-data \
    lvm2
sudo yum-config-manager --add-repo                           \
    https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-compose
sudo usermod -aG docker $USER
Debian
sudo apt-get update
sudo apt-get install             \
     apt-transport-https         \
     ca-certificates             \
     curl                        \
     gnupg2                      \
     software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository                                       \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs)                                         \
   stable"
sudo apt-get update
sudo apt-get install docker-ce docker-compose
sudo usermod -aG docker $USER
Fedora
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install docker-ce docker-compose
sudo systemctl start docker
sudo usermod -aG docker $USER
Ubuntu
sudo apt update
sudo apt-get install -y        \
    apt-transport-https        \
    ca-certificates            \
    curl                       \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce docker-compose
sudo usermod -aG docker $USER
MacOS
  1. Download the installer.

  2. Double-click Docker.dmg to open the installer, then drag Moby the whale to the Applications folder.

  3. Double-click Docker.app in the Applications folder to start Docker. (In the example below, the Applications folder is in “grid” view mode.)

Windows
  1. Download the installer.

  2. Double-click Docker for Windows Installer.exe to run the installer.

  3. Follow the install wizard to accept the license, authorize the installer, and proceed with the install.

    You are asked to authorize Docker.app with your system password during the install process. Privileged access is needed to install networking components, links to the Docker apps, and manage the Hyper-V VMs.

  4. Click Finish on the setup complete dialog to launch Docker.

  5. Start Docker for Windows

Setup

Once docker is installed we can work with it using a terminal. On Linux and MacOS you can search for the application terminal and run it. On Windows right click the windows icon in your taskbar and select Windows PowerShell.

Now lets verify docker is up and running by executing the following commands in the terminal.

docker -v
docker-compose -v
docker run --rm -it hello-world
Show expected output
> docker -v
Docker version 18.06.1-ce, build e68fc7a
> docker-compose -v
docker-compose version 1.22.0, build f46880fe
> docker run --rm -it hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
Known problems on linux

Note on Linux you may get a permission error similar to

    docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

. If so you may did not add yourself to the docker group (sudo usermod -a -G docker $USER) or need to logout and back in.


Once docker is running we can start to setup amity. Therefore we need a configuration file. You can find a working example in our github-repository. Download the file and store it somewhere where you want your amity data being stored. Here are some example scripts for faster setup.

Linux
mkdir -p ~/.amity
cd ~/.amity
wget https://raw.githubusercontent.com/CalexCore/AmityCoin/dev/docker-compose.yml
MacOS
mkdir -p ~/.amity
cd ~/.amity
curl -O https://raw.githubusercontent.com/CalexCore/AmityCoin/dev/docker-compose.yml
Windows
New-Item -ItemType Directory -Path $HOME\.amity | Set-Location
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
curl -Uri https://raw.githubusercontent.com/CalexCore/AmityCoin/dev/docker-compose.yml -OutFile .\docker-compose.yml

Finally we need to replace the default wallet address with our own. Therefore open the docker-compose.yml with a text editor. You may can do this using your already opened terminal.

  • Linux: open -e ./docker-compose.yml
  • MacOS: open ./docker-compose.yml
  • Windows: Start-Process .\docker-compose.yml

Exchange the two occurrences of the current wallet address amit... with your own.

Show expected file content
version: '3.3'

services:
  daemon:
    image: calexcore/amitycoin
    container_name: amity_daemon
    restart: always
    expose:
      - "31018"
      - "21018"
    volumes:
      - ./.data:/data
    entrypoint: AmityCoind --data-dir /data --rpc-bind-ip 0.0.0.0 --fee-address amitWnmgfgYG4XerZGPLNFd5AM87rUkb3X2q4FcELpPsB4DXtT8YE3mETzAjrYLdDH39pJoCxSUHPU2yqZeY1RsJ1h5DgikVAz --fee-amount 2

  miner:
    image: calexcore/amitycoin
    container_name: amity_miner
    restart: always
    depends_on: 
      - daemon
    entrypoint: miner --address amitWnmgfgYG4XerZGPLNFd5AM87rUkb3X2q4FcELpPsB4DXtT8YE3mETzAjrYLdDH39pJoCxSUHPU2yqZeY1RsJ1h5DgikVAz --daemon-host daemon --log-level 3
I have no wallet address yet, let me make one.

Fortunately we have docker and ca do this quite simple. We just start a new instance of a wallet.

  • Linux: docker run --rm -it -v "$(pwd):/amity" -w "/amity" calexcore/amitycoin zedwallet
  • Linux: docker run --rm -it -v "$(pwd):/amity" -w "/amity" calexcore/amitycoin zedwallet
  • Windows: docker run --rm -it -v "$(Convert-Path $PWD):/amity" -w "/amity" calexcore/amitycoin zedwallet
Show expected output
═══════════════════════════════════PRESENTING═══════════════════════════════════
██╗   █████╗ ███╗   ███╗██╗████████╗██╗   ██╗ ██████╗ ██████╗ ██╗███╗   ██╗  ██╗
╚██╗ ██╔══██╗████╗ ████║██║╚══██╔══╝╚██╗ ██╔╝██╔════╝██╔═══██╗██║████╗  ██║ ██╔╝
 ╚██╗███████║██╔████╔██║██║   ██║    ╚████╔╝ ██║     ██║   ██║██║██╔██╗ ██║██╔╝
 ██╔╝██╔══██║██║╚██╔╝██║██║   ██║     ╚██╔╝  ██║     ██║   ██║██║██║╚██╗██║╚██╗
██╔╝ ██║  ██║██║ ╚═╝ ██║██║   ██║      ██║   ╚██████╗╚██████╔╝██║██║ ╚████║ ╚██╗
╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═╝   ╚═╝      ╚═╝     ╚════╝  ╚════╝ ╚═╝╚═╝   ╚══╝  ╚═╝
════════════════════════════════CN═SOFT═SHELL═V3════════════════════════════════

 AmityCoin v0.1.1.215 ()
 This software is distributed under the General Public License v3.0

 Copyright 2018, The Calex Developers

 Additional Copyright(s) may apply, please see the included LICENSE file for more information.
 If you did not receive a copy of the LICENSE, please visit:
 https://github.com/CalexCore/AmityCoin/blob/master/LICENSE



 1      open                     Open a wallet already on your system
 2      create                   Create a new wallet
 3      seed_restore             Restore a wallet using a seed phrase of words
 4      key_restore              Restore a wallet using a view and spend key
 5      view_wallet              Import a view only wallet
 6      exit                     Exit the program

Now type create and follow the instructions. You can name your wallet however you like but for now we assume it is called amity.

Show example wallet creation
═══════════════════════════════════PRESENTING═══════════════════════════════════
██╗   █████╗ ███╗   ███╗██╗████████╗██╗   ██╗ ██████╗ ██████╗ ██╗███╗   ██╗  ██╗
╚██╗ ██╔══██╗████╗ ████║██║╚══██╔══╝╚██╗ ██╔╝██╔════╝██╔═══██╗██║████╗  ██║ ██╔╝
 ╚██╗███████║██╔████╔██║██║   ██║    ╚████╔╝ ██║     ██║   ██║██║██╔██╗ ██║██╔╝
 ██╔╝██╔══██║██║╚██╔╝██║██║   ██║     ╚██╔╝  ██║     ██║   ██║██║██║╚██╗██║╚██╗
██╔╝ ██║  ██║██║ ╚═╝ ██║██║   ██║      ██║   ╚██████╗╚██████╔╝██║██║ ╚████║ ╚██╗
╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═╝   ╚═╝      ╚═╝     ╚════╝  ╚════╝ ╚═╝╚═╝   ╚══╝  ╚═╝
════════════════════════════════CN═SOFT═SHELL═V3════════════════════════════════

 AmityCoin v0.1.1.215 ()
 This software is distributed under the General Public License v3.0

 Copyright 2018, The Calex Developers

 Additional Copyright(s) may apply, please see the included LICENSE file for more information.
 If you did not receive a copy of the LICENSE, please visit:
 https://github.com/CalexCore/AmityCoin/blob/master/LICENSE



 1      open                     Open a wallet already on your system
 2      create                   Create a new wallet
 3      seed_restore             Restore a wallet using a seed phrase of words
 4      key_restore              Restore a wallet using a view and spend key
 5      view_wallet              Import a view only wallet
 6      exit                     Exit the program

What would you like to do?: create
What would you like to call your new wallet?: amity
Give your new wallet a password: ***
Confirm your new password: ***
Welcome to your new wallet, here is your payment address:
amitCM8krAm4SX7CAAAwNp5Sudwk7bbzGCYhZaXBSaNZWfrrP4HuKpjKFvzW1DorpybBZJLGXJndYbW6cY7MHawr2KytWziaP4

Please copy your secret keys and mnemonic seed and store them in a secure location:
Private spend key:
f6ccd11dd580891b0777281a920539f43f385aed2d812a85ba27adf2b3ac1001

Private view key:
755dbb1f7efe6039b1b174a310529001c92c0bbf3ffee113bbad7d13ebaa2e0e

Mnemonic seed:
pizza ulcers absorb mews exult hire foyer fleet icon lamb eden deity tusks amused winter enough feline spiders aphid abort voyage comb uttered vane voyage

If you lose these your wallet cannot be recreated!

It looks like AmityCoind isn't open!

Ensure AmityCoind is open and has finished initializing.
If it's still not working, try restarting AmityCoind.The daemon sometimes gets stuck.
Alternatively, perhaps AmityCoind can't communicate with any peers.

The wallet can't function fully until it can communicate with the network.

 1      try_again                Try to connect to the node again
 2      continue                 Continue to the wallet interface regardless
 3      exit                     Exit the program

What would you like to do?: exit
Shutting down...
Shutting down node connection...
Bye.

Make sure to copy or print the outputted Private spend key, Private view key and Mnemonic seed. If you ever loose your created wallet file and do not have access to those keys your account, and all AMIT in it will be lost. Thus,seriously: backup, please. Additionally the wallet creation will output a payment address. This is your public address you will need to use to configure docker-compose.yml.


Now everything is setup and we can start the miner.

docker-compose up -d
Show expected output
> docker-compose up -d
Creating amity_daemon ... done
Creating amity_miner  ... done

Congratulations. You started to mine AmityCoin and collaborating with our community to create a truly private cryptocurrency we can trust. Thank you.

Monitoring

You may noticed not very much changed. So how can you see what is actually happening in the background. First lets list our created machines.

docker ps
Show expected output
> docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                  NAMES
7e1df0d95719        calexcore/amitycoin   "miner --address ami…"   4 minutes ago       Up 11 seconds                              amity_miner
2366a12c1412        calexcore/amitycoin   "AmityCoind --data-d…"   4 minutes ago       Up 4 minutes        21018/tcp, 31018/tcp   amity_daemon

We can see two machines are currently running, one named amity_miner and the other amity_daemon. The daemon is responsible for interactions with other users in the blockchain while the miner request new tasks from the daemon and pushes newly found blocks. Lets have a look what they are doing, starting with the daemon.

docker logs amity_daemon
Show expected output
> docker logs amity_daemon
2018-Nov-15 16:52:37.778167 INFO

═══════════════════════════════════PRESENTING═══════════════════════════════════
██╗   █████╗ ███╗   ███╗██╗████████╗██╗   ██╗ ██████╗ ██████╗ ██╗███╗   ██╗  ██╗
╚██╗ ██╔══██╗████╗ ████║██║╚══██╔══╝╚██╗ ██╔╝██╔════╝██╔═══██╗██║████╗  ██║ ██╔╝
 ╚██╗███████║██╔████╔██║██║   ██║    ╚████╔╝ ██║     ██║   ██║██║██╔██╗ ██║██╔╝
 ██╔╝██╔══██║██║╚██╔╝██║██║   ██║     ╚██╔╝  ██║     ██║   ██║██║██║╚██╗██║╚██╗
██╔╝ ██║  ██║██║ ╚═╝ ██║██║   ██║      ██║   ╚██████╗╚██████╔╝██║██║ ╚████║ ╚██╗
╚═╝  ╚═╝  ╚═╝╚═╝     ╚═╝╚═╝   ╚═╝      ╚═╝     ╚════╝  ╚════╝ ╚═╝╚═╝   ╚══╝  ╚═╝
════════════════════════════════CN═SOFT═SHELL═V3════════════════════════════════

 AmityCoin v0.1.1.215 ()
 This software is distributed under the General Public License v3.0

 Copyright 2018, The Calex Developers

 Additional Copyright(s) may apply, please see the included LICENSE file for more information.
 If you did not receive a copy of the LICENSE, please visit:
 https://github.com/CalexCore/AmityCoin/blob/master/LICENSE


2018-Nov-15 16:52:37.778561 INFO    Program Working Directory: AmityCoind
2018-Nov-15 16:52:37.779238 INFO    Loading Checkpoints for faster initial sync...
2018-Nov-15 16:52:37.779328 INFO    Loaded 0 default checkpoints
2018-Nov-15 16:52:37.779414 INFO    Opening DB in /data/DB
2018-Nov-15 16:52:37.780438 INFO    DB not found in /data/DB. Creating new DB...
2018-Nov-15 16:52:37.783293 INFO    Initializing core...
2018-Nov-15 16:52:37.783738 INFO    Core initialized OK
2018-Nov-15 16:52:37.783793 INFO    Initializing p2p server...
2018-Nov-15 16:52:37.783969 INFO    Generated new peer ID: 6203143618660274375
2018-Nov-15 16:52:37.784015 INFO    Binding on 0.0.0.0:21018
2018-Nov-15 16:52:37.784071 INFO    Net service binded on 0.0.0.0:21018
2018-Nov-15 16:52:37.784109 INFO    Attempting to add IGD port mapping.
2018-Nov-15 16:52:41.788852 INFO    No IGD was found.
2018-Nov-15 16:52:41.788999 INFO    P2p server initialized OK
2018-Nov-15 16:52:41.789167 INFO    Starting core rpc server on address 0.0.0.0:31018
2018-Nov-15 16:52:41.789313 INFO    Core rpc server started ok
2018-Nov-15 16:52:41.789386 INFO    Starting p2p net loop...
2018-Nov-15 16:52:41.789443 INFO    Starting node_server
2018-Nov-15 16:53:02.473143 INFO    [42.51.41.62:21018 OUT] Your AmityCoin node is syncing with the network (0.01% complete) You are 7504 blocks (10 days) behind the current peer you're connected to. It's not a race, grab a coffee.
2018-Nov-15 16:53:02.473315 INFO    New Top Block Detected: 7505
2018-Nov-15 16:53:04.228516 INFO    Block 100 (14aaaf90e4701c3833fe06e75d93106e5228ab5dd4b0a39b5d19f8b04caa06ec) added to main chain
2018-Nov-15 16:53:05.609868 INFO    Block 200 (6661694af013638bab138c7bcfe2f69e754be9d34cd5340c02f498abd6748ced) added to main chain
2018-Nov-15 16:53:06.315927 INFO    Block 300 (dda27428921eb5236cfeba135211e57f3c338ceba5ee904c6c05f2c4681b241a) added to main chain
2018-Nov-15 16:53:06.853880 INFO    Block 400 (a51da7c6c168808f8a9c88b31608aff5daa5b15f605a6a35cf2c98d65f05f8e5) added to main chain
2018-Nov-15 16:53:07.761290 INFO    Block 500 (ac256e1244ced06d0d2a5897e5d746bb86c7314eb204865a217cb857ba4279f1) added to main chain

The daemon started synchronizing with the blockchain. Once it has finished, it will be part of the Amity community!

I started my own daemon. Is this secure?

Yes this is absolutely secure. Docker creates 'sandboxes', so even if the miner or daemon would have been hacked they cannot escape their cage. Furthermore; docker-compose creates an isolated network and only the miner has access to it.

What happens if I shutdown my computer or restart it, or the daemon/miner crashes?

We configured the machines as a service. Whenever you start/restart your computer they will start as well. Furthermore, the blockchain is locally cached on your computer and you will not need to download it every time. In addition, docker will track the status of your services and if they crash for any reason they will be restarted immediately.


Unfortunately, while our daemon is syncing the blockchain, the miner cannot receive any job. We can inspect his progress using:

docker logs amity_miner
Show expected output
> docker logs amity_miner
2018-Nov-15 16:52:38.424594 INFO    [MinerManager] Donate level: 2%
2018-Nov-15 16:52:38.424644 INFO    [MinerManager] requesting mining parameters
2018-Nov-15 16:52:38.425979 WARNING [MinerManager] Couldn't get block template: TcpConnector::connect, connection failed
2018-Nov-15 16:52:38.426016 WARNING [MinerManager] Couldn't connect to daemon: TcpConnector::connect, connection failed
2018-Nov-15 16:53:08.426095 INFO    [MinerManager] requesting mining parameters
2018-Nov-15 16:53:08.427146 WARNING [MinerManager] Couldn't get block template: Coreisbusy
Fatal: Coreisbusy
I am donating?

Yes 2% donation to our developer fund wallet is the default configuration. The last two of every 100 blocks mined are sent to the donation wallet address. You can change this amount by appending --donate-level 0 to the miner entrypoint in docker-compose.yml. If you change the service, make sure to restart it (docker-compose up -d).

version: '3.3'
...
miner:
    ...
    entrypoint: ... --donate-level 0

We will now have to wait some time for the blockchain to sync. You can monitor its progress by executing docker logs amity_daemon. Once it's finished, the miner will start with all cores available, and we can monitor our hashrate using docker logs amity_miner.

Show example log of a running miner
> docker logs amity_miner
...
2018-Nov-15 17:39:34.573516 INFO    [Miner] Starting mining for difficulty 254850806
2018-Nov-15 17:39:34.573574 INFO    [Miner] Thread 0 started at nonce: 1034367710
2018-Nov-15 17:39:34.573601 INFO    [Miner] Thread 1 started at nonce: 1034367711
2018-Nov-15 17:40:32.113810 INFO    [MinerManager] Mining at 645 H/s
2018-Nov-15 17:40:34.635662 INFO    [Miner] Starting mining for difficulty 244391903
2018-Nov-15 17:40:34.635724 INFO    [Miner] Thread 0 started at nonce: 3023423309
2018-Nov-15 17:40:34.635755 INFO    [Miner] Thread 1 started at nonce: 3023423310
2018-Nov-15 17:41:04.687688 INFO    [Miner] Starting mining for difficulty 248816920
2018-Nov-15 17:41:04.687764 INFO    [Miner] Thread 0 started at nonce: 3674148510
2018-Nov-15 17:41:04.687795 INFO    [Miner] Thread 1 started at nonce: 3674148511

Managing

For all commands managing our services docker-compose will search for a docker-compose.yml. There we assume you already opened a terminal and changed your active directory, as mentioned in the setup section.

  • downloading updates:

    Our continuous integration system automatically tests new releases and updates the containers. Therefore it is meaningful to update the services from time to time and getting the latest improvements.

    docker-compose down
    docker-compose pull
    docker-compose up -d

    Note if you configured a fixed version number for your services you will need to pick your desired version from hub.docker and update docker-compose.yml.

  • stop mining: docker-compose stop

  • start mining: docker-compose up -d

  • delete the service: docker-compose down

Known Issues

Windows does not use all my CPU cores.

By default docker runs in a virtual machine within windows. This machine is limited to two CPUs. One way to solve this problem is switching to Windows Containers and using the experimental LCOW feature. For more information have a look at docs.microsoft.com.