How To Setup A Node With Docker?
Docker is the de facto industry standard for packaging applications into a container. By doing so, all dependencies, such as the language run-times, operating system, and libraries are combined with the product.
Prerequisites to be installed:
Supported Cloud Providers
Different cloud providers offer specific products to host your Docker containers, such as:
Orchestrators with Docker as a first class citizen:
ARK Core Production ready Docker images are now available at Docker Hub
Get The Needed Docker Files
The code sample below downloads the needed files from our official GitHub Core repository .
Set NETWORK=mainnetif you prefer to run a Mainnet node. ``
1NETWORK=devnet2mkdir ~/$NETWORK3cd ~/$NETWORK4curl -sOJ https://raw.githubusercontent.com/ArkEcosystem/core/master/docker/production/$NETWORK/docker-compose.yml5curl -sOJ https://raw.githubusercontent.com/ArkEcosystem/core/master/docker/production/$NETWORK/$NETWORK.env
Running a Relay Node
1cd ~/$NETWORK # (NETWORK = devnet || mainnet)2docker-compose up -d
This will run two separate containers. One for Core itself and another one for PostgreSQL.
The public API won’t be available until a relay is fully synchronized with the network and blockchain. All requests before this will result in a connection reset because the port is not yet bound to an application.
How To Run a Relay and a Forger Node
Prerequisites to be installed
Two additional steps are needed to be able to run a forger:
MODE has to be set to
(MODE=forger) in your
1cd ~/$NETWORK2sed -i 's/^MODE=relay/MODE=forger/g $NETWORK.env
Step 2. Configure your delegate secret and password. Just use the additional script 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.
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
This will fire up two separate containers. One for Core itself and another one for PostgreSQL.
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. For a full list of Core variables go here.
You can also change default log levels by adjusting variables CORE_LOG_LEVEL and CORE_LOG_LEVEL_FILE (file=$NETWORK.env). Note that DEBUG level will probably add some CPU overhead during network sync.
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:
1cd ~/$NETWORK2docker-compose up -d core
How Do I Start With Empty DB?
Just execute the following code:
1cd ~/$NETWORK2docker-compose down -v3docker-compose up -d
Where Are the Config Files and Logs Located?
ARK Core container mounts by default the following local paths as volumes:
Having that said, your config files are locally accessible under:
Pool database as well as db snapshots are locally accessible under:
Log files are locally accessible under:
Alternative way of following the logs would be, by using the command:
1docker logs --tail 50 core-$NETWORK -f
How Do I Start Everything from Scratch?
Just use the
How To Build Your Own ARK Core Docker Image
This requires cloning ARK Core Github repository .
1cd ~/2git clone https://github.com/ArkEcosystem/core
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:
1cd ~/core/docker/production/$NETWORK # (NETWORK = devnet || mainnet)2docker-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.
How To Update Core Version Within Docker Image
Option 1: 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):
1docker exec -it core-$NETWORK sudo apk add make gcc g++ git python
We are all set! Run the update and follow instructions:
1docker exec -it core-$NETWORK ark update
Updates and all changes made to the containers are kept even on container or host restart.
Option 2: Update is also possible by destroying and running Core container from scratch, so it downloads the latest image
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 this:
1cd ~/$NETWORK2docker stop core-$NETWORK3docker rm core-$NETWORK4docker rmi $(docker images -q)5docker-compose up -d core
Generate the Configurations
ARK Core includes several
docker-compose.yml templates to ease the development. They can be used to generate different configurations, depending on the network and token.
For instance, you could use this command from the root core folder:
1yarn 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.
PostgreSQL is run in a separate container and it’s port gets mapped to your
localhost, so you should not have PostgreSQL running locally.
Clone ARK Core Github repository :
1cd ~/2git clone https://github.com/ArkEcosystem/core
1cd ~/core/docker/development/$NETWORK # (NETWORK = testnet || devnet)2docker-compose up
To run the containers in the background :
In case you need to start with a clean Database:
1docker-compose down -v2docker-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.
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.
1cd ~/core/docker/development/$NETWORK # (NETWORK = testnet || devnet)2docker-compose up -d
Enter your ark-core container and use NodeJS in a Docker container (Linux environment) with the following command:
1docker 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.
Development files/presets are not Production ready. Official Production ARK-Core Docker images are now available at Docker Hub .