Published 28 November 2018

Using Credits blockchain software in Docker

Description

Description

The purpose of this article is to demonstrate the use of Docker and CREDITS software. CREDITS software consists of configuration files and the three modules: Wallet Desktop (user wallet), contract-executor (execution of smart contracts), and node module.

In the Docker container we will use Wallet Desktop and contract-executor.

Components

Components

Docker is software for automating deployment and application management in a virtualization environment at the operating system level. Allows you to "package" the application with all its environment and dependencies in a container that can be ported to any Linux system, as well as providing a container management environment.

Portainer is the most popular web interface for working with Docker hosts and Docker Swarm clusters. Is launched by deploying a Docker image that is passed address/socket of the Docker host as a parameter. Allows you to manage containers, images (can pick them up from Docker Hub), networks, volumes.

Installing components

Installing components

Docker

Installation in Windows. Download page.

Installation on Linux is done using the Advanced Packaging Tool (apt). Installation commands:

sudo apt-get update

sudo apt-get install \
   apt-transport-https \
   ca-certificates \
   curl \
   software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo apt-key fingerprint 0EBFCD88

sudo add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

sudo apt-get update

sudo apt-get install docker-ce

Portainer

The installation is the same on both operating systems, except on Linux you must add the sudo command:

Windows:

docker volume create portainer_data
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Linux:

sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Two-in-one

Two-in-one

To run Wallet Desktop and contract-executor in a container simultaneously, we will use a simple program in C++, code, let's call the file runner.cpp:

Build command:

g++ -pthread runner.cpp  -o runner

the build must be done on a computer with Linux operating system.

Creating a Dockerfile script file and image

Creating a Dockerfile script file and image

FROM ubuntu:18.04

# update && java 8 install

RUN apt-get update && \

apt-get upgrade -y && \

apt-get install -y software-properties-common && \

add-apt-repository ppa:webupd8team/java -y && \

apt-get update && \

echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \

apt-get install -y oracle-java8-installer && \

apt-get clean

# setup worker dir

WORKDIR /credits

# copy all files from current dir to ./credits

COPY . /credits

# ports

EXPOSE 6000

EXPOSE 9090

# run

CMD ["./runner"]

The directory containing the Dockerfile file needs to be placed to the unzipped CREDITS software (Release 2.2) archive. In the case of an image build in Linux OS files ./client and ./runner must be marked as runned:

chmod +x client

chmod +x runner

Image build command: docker build -t credits .

Starting the container from the created image

Starting the container from the created image

Note: When starting from Linux, you must add the sudo command.

Use the following command to create a container from the collected image:

docker volume create test_db - create the volume, where the database will be stored

docker run -it -p 6000:6000 -p 9090:9090 --mount source=db,target=/credits/test_db credits:latest bash

starting from container

Check the success of the launch - ./runner command:

at the initial start you will be prompted to generate a new key.

The figure shows that it is running the client (node) and contract-executor in container.

Now you can run only user Desktop Wallet on the host machine.

Note: container can be run remotely anywhere, for example, in Azure.

28 Useful article

Contents