Dockerizing Decred - dcrd

2 minute read

Updated:

1. Introduction

Decred blockchain server, dcrd, can be executed from a Docker VM.

If you are new to Docker, please read the docs to learn more. Below you can read an introduction to Docker from the official documentation:

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

This article assumes the structure described in Scenario 4 explained in article dcrdata: running your own block explorer.

Figure 1 – Running Decred on Docker
Figure 1 – Running Decred on Docker

2. Configuring Docker files

Docker can be executed from your local computer/server or from a Cloud service like Amazon AWS or Microsoft Azure.

The following steps were performed on a macOS 10.15.6.

a) Install Docker Desktop from https://www.docker.com/get-started

b) This example assumes the following folder structure, with three files created in the same dcrd folder, child of a parent docked_decred folder.

docked_decred
|_ dcrd
   |_ Dockerfile
   |_ dcrd_install.sh
   |_ logview_dcrd.sh

The first half of the Dockerfile tells Docker to download an Alpine Linux 3.12 image, create a storage volume named ‘dcrd_volume’, update the package list, install gnupg and tar, and then open TCP port 9108 (necessary if a dcrdata will connect to this dcrd, otherwise this line EXPOSE 9108/tcp can be removed).

Dockerfile

FROM alpine:3.12

LABEL maintainer="Marcelo, from Decred" \
      version="0.1"

VOLUME dcrd_volume

WORKDIR /
RUN apk update
RUN apk add gnupg tar
EXPOSE 9108/tcp

COPY dcrd_install.sh .
COPY logview_dcrd.sh .
RUN chmod +x logview_dcrd.sh
RUN chmod +x dcrd_install.sh
RUN /dcrd_install.sh

CMD ["/opt/decred/dcrd", "--txindex", "--addrindex"]

The second half copies two scripts from the same folder where the Dockerfile resides (you will have to put all the files in the same folder) to the Docker image. The line RUN /dcrd_install.sh tells Docker to run the following script after the download and the last line tells it to start dcrd with the flags “–txindex” and “–addrindex”, used by dcrdata, as soon as the script execution is finished.

dcrd_install.sh

DECRED_VERSION="1.5.1"
DECRED_PKG="decred-linux-arm64-v${DECRED_VERSION}.tar.gz"
DECRED_MANIFEST="decred-v${DECRED_VERSION}-manifest.txt"
DECRED_MANIFEST_ASC="decred-v${DECRED_VERSION}-manifest.txt.asc"
DECRED_DIR="decred-linux-arm64-v${DECRED_VERSION}"
PGP_SERVER="keyserver.ubuntu.com"
DECRED_PGP_KEY_FP="0x518A031D"

wget https://github.com/decred/decred-binaries/releases/download/v${DECRED_VERSION}/${DECRED_PKG} \
https://github.com/decred/decred-binaries/releases/download/v${DECRED_VERSION}/${DECRED_MANIFEST} \
https://github.com/decred/decred-binaries/releases/download/v${DECRED_VERSION}/${DECRED_MANIFEST_ASC}

gpg --keyserver ${PGP_SERVER} --recv-keys ${DECRED_PGP_KEY_FP}
GPG_SIG=$(gpg --with-colons --status-fd 1 --verify ${DECRED_MANIFEST_ASC} 2> /dev/null)
SHASUM_SIG=$(sha256sum -c ${DECRED_MANIFEST} | grep -c "OK")

if [[ `echo $GPG_SIG | grep -c GOOD` -eq 1 && $SHASUM_SIG -eq 1 ]]; then
    tar -xzf ${DECRED_PKG}
    rm ${DECRED_PKG} ${DECRED_MANIFEST_ASC} ${DECRED_MANIFEST}
    mv ${DECRED_DIR} /opt
    ln -s /opt/${DECRED_DIR} /opt/decred
fi

logview_dcrd.sh is a one-liner script to facilitate reading the status.

logview_dcrd.sh

No big deal here. This script just simplifies tapping into dcrd log file instead of writing its full path.

tail -f /home/.dcrd/logs/mainnet/dcrd.log

3. Running a Dockerized dcrd

On your host, type the following command to start Docker dcrd VM:

$ docker -

Execute logview_dcrd script the check if dcrd is downloading the blockchain:

$ ./logview_dcrd.sh

4. Next steps

Now that we have a running dcrd on Docker, the next part will deal with dcrdata and PostgreSQL to dockerize the block explorer.