Docker commands

Build Docker image

Inside the klayr-service root folder
make build-images

This creates the necessary Docker images to start Klayr Service in the containers.

Start

Inside the klayr-service root folder
cp ./docker/example.env .env
make up

This will start Klayr Service with the default configuration, which in turn will connect to a Klayr Core Mainnet node.

In case a different node or network shall be used, configure Klayr Service accordingly.

Stop

Inside the klayr-service root folder
make down

This will stop Klayr Service.

Show the status of Docker containers

docker ps

Reset the Klayr Service database

To reset the database of Klayr Service, drop the respective MySQL and Redis databases.

Before resetting the database, stop Klayr Service:

make stop

Now connect to the Docker container in which you wish to reset the database. If you are not sure what to choose here, check the available containers via Show the status of Docker containers.

To connect to the interactive shell of the MySQL Docker container in which you wish to reset the MySQL database, execute the following command:

docker exec -it klayr-service-mysql-primary-1 bash

Drop Database

  • MySQL DB

  • MariaDB

  1. Login to MySQL with the klayr user.

    mysql -uklayr -ppassword

    On successful login, you enter the MYSQL command-line client:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2044
    Server version: 8.0.27 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  2. Drop the klayr database.

    mysql> drop database klayr;
  3. Create a fresh database klayr.

    mysql> create database klayr;
  4. Log out from MySQL by typing quit;

    mysql> quit;

Log out of the docker container by pressing CRTL + D.

MariaDB also uses the same SQL commands for querying and manipulating the relevant data, including data storage, client libraries, and replication.

  1. Login to MariaDB with the klayr user.

    docker exec -it klayr_mariadb mysql -uroot -p

    On successful login, you enter the MariaDB command-line client:

    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 9
    Server version: 10.7.8-MariaDB-1:10.7.8+maria~ubu2004 mariadb.org binary distribution
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  2. Drop the klayr database.

    MariaDB [(none)]> drop database klayr;
    Result
    Query OK, 0 rows affected (0.009 sec)
  3. Create a fresh database klayr

    MariaDB [(none)]> create database klayr;
    Result
    Query OK, 1 row affected (0.001 sec)
  4. Log out by typing quit;.

    MariaDB [(none)]> exit;

Log out of the docker container by pressing CRTL + D.

Flush Redis DB

Reset the databases for Redis after dropping the MySQL database:

Execute command in running docker container.
sudo docker exec -it klayr-service_redis_core_persistent_1 /bin/sh
Truncate redis database.
redis-cli flushall
Log out of the docker container again by pressing CRTL + D.

The flushall command truncates all existing Redis databases:

Deletes all the keys of all the existing databases, not just the current selected one. This command never fails.

For more information, check the Redis documentation: FLUSHALL.

To flush only a particular DB in Redis, execute the following command instead:

redis-cli -n <db_number> flushdb

Start Klayr Service

After the databases are reset, start Klayr Service again as usual:

make up
When Klayr Service is started again after a database reset, then the process to reindex all the data is initiated. This can be quite time-consuming when the chain is long, spanning over hours.

Taking Snapshots

If you wish to take a snapshot of your Docker installation, the details can be found here on the Snapshots page.

Logging

The possibility exists here to either use the docker commands or the make commands to check the logs, and both options are listed here below.

For docker, to check the logs for the different microservices of Klayr Service, use the command docker container logs CONTAINER, where CONTAINER is the respective Docker container that holds the logs you wish to view.

For example, to see the logs for the Gateway microservice, execute the following command:

docker container logs klayr-service_gateway_1

To check the logs for different microservices using the make commands, the following commands listed below can be used:

Displays the logs for all the microservices that have been logged so far, and that are currently existing
make logs
Displays the latest logs for all the microservices
make logs-live
Displays the logs for the specified microservice.
make logs-blockchain-connector

In the above example, it will display logs only for the blockchain-connector microservice.

Displays the latest logs for the specified microservice.
make logs-live-blockchain-connector

In the above example, it will display the latest logs only for the blockchain-connector microservice.

Replace the blockchain-connector with the specific service name required.

Upgrade Klayr Service

To upgrade the Docker container to a desired version, please follow one of the two options below. To find all the tagged versions for Klayr Service, please check the available tags on GitHub.

  • Option A - Download pre-built images from DockerHub

  • Option B - Build images locally

  1. Stop Klayr Service

    make stop
    In case the database needs to be flushed please execute the make down command instead. Please check the release notes for the relevant version to see if the existing databases need to be flushed.
  2. Checkout the version with git checkout <tag>

    git checkout v0.7.8
  3. Update docker-compose.yml to download the specific image versions from the DockerHub as shown below. Update specified images with the desired version, for example 0.7.8.

    docker-compose.yml
    blockchain-app-registry:
        image: klayr/service_blockchain_app_registry:0.7.8
        ...
    
      blockchain-connector:
        image: klayr/service_blockchain_connector:0.7.8
        ...
    
      blockchain-indexer:
        image: klayr/service_blockchain_indexer:0.7.8
        ...
    
      blockchain-coordinator:
        image: klayr/service_blockchain_coordinator:0.7.8
        ...
    
      transaction-statistics:
        image: klayr/service_transaction_statistics:0.7.8
        ...
    
      fee-estimator:
        image: klayr/service_fee_estimator:0.7.8
        ...
    
      gateway:
        image: klayr/service_gateway:0.7.8
        ...
    
      market:
        image: klayr/service_market:0.7.8
        ...
    
      export:
        image: klayr/service_export:0.7.8
  4. Start Klayr Service in the containers.

    make up

Build the images locally using the following steps. Navigate inside the klayr-service root folder, and execute the following commands.

  1. Stop Klayr Service

    make stop
    In case the database needs to be flushed please execute the make down command instead. Please check the release notes for the relevant version to see if the existing databases need to be flushed.
  2. Checkout the version with git checkout <tag>

    git checkout v0.7.8
  3. Build the required updated Docker images

    make build-images
  4. Start Klayr Service in the containers

    make up

To verify the microservice logs, please refer to the Logging section.