Docker

TIP

Prerequisites to be installed:

Introduction

Docker is the de facto industry standard for packaging applications into a container. By doing so, all dependencies, such as the language runtimes, operating system, and libraries are combined with the product.

Different cloud providers offer specific products to host your Docker containers, such as:

Orchestrators with Docker as a first class citizen:

Production

  • ARK Core Production ready Docker images are now available at Docker Hub

Run Relay Only

cd docker/production/$NETWORK     # (NETWORK = devnet || mainnet)
docker-compose up -d

This will run two separate containers. One for Core itself and another one for PostgreSQL.

Run Relay and a Forger

TIP

Prerequisites to be installed:

Two additional steps are needed to be able to run a forger:

  1. MODE has to be set to forger (MODE=forger) in your $NETWORK.env file.
cd docker/production/$NETWORK     # (NETWORK = devnet || mainnet)
sed -i 's/^MODE=relay/MODE=forger/g $NETWORK.env
  1. Configure your delegate secret and password. Just use the additional script enc.sh.
bash enc.sh

You will be asked to enter your delegate secret, followed by entering your password twice. Script will create a new folder named enc, containing set of encrypted public and private keys.

WARNING

Folder enc is needed during core container startup. After making sure your forger is up and running it is preferably to delete it. The disadvantage of this would be that if you your server gets rebooted or simply core container restarted, you will have repeat step 2.

Now let's run the forger:

docker-compose up -d

This will fire up two separate containers. One for Core itself and another one for PostgreSQL.

Custom Settinings

TIP

If you prefer to use custom DB Name, DB User and DB Password simply adjust variables POSTGRES_PASSWORD, POSTGRES_USER, POSTGRES_DB (file=docker-compose.yml) and CORE_DB_PASSWORD, CORE_DB_USERNAME and CORE_DB_DATABASE (file=$NETWORK.env) correspondingly.

In case you want to use a remote PostgreSQL server simply adjust variable CORE_DB_HOST in your $NETWORK.env and run only Core container:

cd docker/production/$NETWORK     # (NETWORK = devnet || mainnet)
docker-compose up -d core

FAQ

How Do I Start With Empty DB?

Just execute the following code:

docker-compose down -v
docker-compose up -d

Where Are the Config Files and Logs Located?

ARK Core container mounts by default the following local paths as volumes:

~/.config/ark-core
~/.local/share/ark-core
~/.local/state/ark-core

Having that said, your config files are locally accessible under:

~/.config/ark-core/$NETWORK/

Pool database as well as db snapshots are locally accessible under:

~/.local/share/ark-core/$NETWORK/

Log files are locally accessible under:

~/.local/state/ark-core/$NETWORK/

Alternative way of following the logs would be, by using the command:

docker exec -it core-$NETWORK pm2 logs

How Do I Start Everything from Scratch?

Just use the purge_all.sh script.

Building Your Own ARK Core Docker Image

Custom Docker image builds of ARK Core are possible by using the file docker-compose-build.yml. Make your own modifications of ARK Core source code and run your custom container by executing:

cd docker/production/$NETWORK     # (NETWORK = devnet || mainnet)
docker-compose -f docker-compose-build.yml up -d

This will build your ARK Core Docker image and run two separate containers. One for Core itself and another one for PostgreSQL.

Update

Docker Live Updates Are Now Possible With CLI

As a preliminary step, installation of development tools is necessary (only needed once, when doing initial update):

docker exec -it core-$NETWORK sudo apk add make gcc g++ git python

We are all set! Run the update and follow instructions:

docker exec -it core-$NETWORK ark update

TIP

Updates and all changes made to the containers are kept even on container or host restart.

Update is also possible by destroying and running Core container from scratch, so it downloads the latest image.

TIP

Make sure you destroy only Core container in order to keep your database and avoid syncing the blockchain from zero block. The commands example below does it.

cd docker/production/$NETWORK 
docker stop core-$NETWORK
docker rm core-$NETWORK
docker rmi $(docker images -q)
docker-compose up -d core

Development

Generate the Configurations

ARK Core include several Dockerfile and docker-compose.yml templates to ease development. They can be used to generate different configurations, depending on the network and token.

For instance, you could use this command:

yarn docker ark

This command creates a new directory (docker) that contains 1 folder per network.

Containerize the Persistent Store

Run a PostgreSQL container while using NodeJS from your local environment.

This configuration is well suited when you are not developing ARK Core, but instead working with the API. By tearing down the PostgreSQL container, you reset the Nodes blockchain.

WARNING

PostgreSQL is run in a separate container and it's port gets mapped to your localhost, so you should not have PostgreSQL running locally.

cd docker/development/$NETWORK     # (NETWORK = testnet || devnet)
docker-compose up

To run the containers in the background:

docker-compose up -d

In case you need to start with a clean Database:

docker-compose down -v
docker-compose up -d

Serve ARK Core as a Collection of Containers

Run a PostgreSQL container, build and run ARK-Core using a mounted volume.

When a container is built, all files are copied inside the container. It cannot interact with the host's filesystem unless a directory is specifically mounted during container start. This configuration works well when developing ARK Core itself, as you do not need to rebuild the container to test your changes.

TIP

Along with PostgreSQL container, now you also have a NodeJS container which mounts your local ark-core git folder inside the container and installs all NPM prerequisites.

cd docker/development/$NETWORK      # (NETWORK = testnet || devnet)
docker-compose up -d

You can now enter your ark-core container and use NodeJS in a Docker container (Linux environment).

docker exec -it ark-$NETWORK-core bash

Need to start everything from scratch and make sure there are no remaining cached containers, images or volumes left? Just use the purge_all.sh script.

WARNING

Development files/presets are not Production ready. Official Production ARK-Core Docker images are now available at Docker Hub.