Let’s check our local repository.

[email protected]:~/projects/docker/lisky-node$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE lisky node 351c7a113c7d 39 minutes ago 696MB node latest ec70562ad6f0 2 days ago 673MB [email protected]:~/projects/docker/lisky-node$

The 673MB image node:latest was pulled to my local repository from the public Docker Hub repository in order to build my 696MB Docker image tagged lisky:node. The image node:latest has many Linux commands in it which would be helpful if we wanted to do something more than just running Lisky during development and testing.

How to Run the Lisky Container

Now that we have a new image, we can start its container and test it.

Here is an explanation of the command:

docker run --tty --interactive --rm lisky:node lisky

docker The base command for the Docker CLI. run Run a command in a new container --tty Start a pseudo tty terminal. It is _not_ the same as the "tag" option for "docker build" --interactive Run in interactive mode. --rm Automatically remove the container from memory when it exits. lisky:node The tagged Docker image to be started. lisky Run the command "lisky" inside the container after it is launched.

When Lisky starts I’ll run the Lisky command config to test it.

It works! We can now push the image to hub.docker.com and pull the lisky:node image to any other Linux, Microsoft Windows or MacOSX computer that has Docker installed and they will all run the Lisky Docker image successfully.

If you want to run more Lisky commands, see lisk.io/documentation/lisk-commander/usage/commands and re-run the command docker run --tty --interactive --rm lisky:node lisky . But don’t get too distracted! We still have some more interesting items to cover in this tutorial.

Let’s Build a Smaller Lisky Image

I want to build a smaller and simpler Lisky image if I am going to run many Lisky containers to simulate lots of users in a Lisk network. Fortunately, the Docker Hub also has a node:alpine image which is ~5MB!

Here is my Dockerfile for building a much smaller Lisky image.

[email protected]:~/projects/docker/lisky.alpine$ cat Dockerfile FROM node:alpine RUN apk --no-cache add git RUN npm install --global --production lisky

Lisky requires the git command which is missing in node:alpine. That is why I have RUN apk --no-cache add git in my Dockerfile to install git.

We already know how the following ‘docker build’ command works. Here is the captured output.

How small is our new Lisky image?

Now let’s check the size of the Lisky image built on top of the small node:alpine image.

[email protected]:~/projects/docker/lisky-alpine$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE lisky alpine 67b0d1b804fb 8 minutes ago 113MB lisky node 351c7a113c7d About an hour ago 696MB node alpine 4a6857f6f75d 2 days ago 68.4MB node latest ec70562ad6f0 2 days ago 673MB [email protected]:~/projects/docker/lisky-alpine$

Our new Docker Lisky image is 113MB. We have decreased the size of our Lisky image by 84%!

Testing Our Small Lisky Image

Let’s test our new lisky:alpine image by starting the container in interactive mode. We will then run some test commands:

set pretty true to make the output easier to read. set testnet true to send Lisky commands to Testnet. config to show our new Lisky configuration. get transaction 16138217535681461985 . I found that transaction ID on https://testnet-explorer.lisk.io/. (try other values for extra credit 😀 ) exit to exit Lisky.

Here are the results of the test.

Like the test we did with the 700MB image lisk:node, we know it works.

But what if I want to automate sending commands to this Lisky container, such as in a script? Luckily, there is a docker exec --interactive --detach CONTAINER COMMAND that lets us do just that.

docker The base command for the Docker CLI. exec Run a command in a running container. --interactive Keep STDIN open even if not attached. --detach Detached mode: run command in the background. CONTAINER Assigned name of the container. COMMAND The command sent from our command line to the running container.

First, we need to start the container in interactive mode and run the container in the background. Then we will run docker ps to get the friendly name of the container.

[email protected]:~/projects/docker/lisky-alpine$ docker run --interactive --detach lisky:alpine 23c7803dddc1f2b64bfc055b703fe304674245f0153d3668241bf47d9bb66006 [email protected]:~/projects/docker/lisky-alpine$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 23c7803dddc1 lisky:alpine "node" 4 seconds ago Up 2 seconds relaxed_mcnulty [email protected]:~/projects/docker/lisky-alpine$

Now that we have the assigned container’s friendly name, “relaxed_mcnulty”, we can send commands directly from the command line, or from a script, to it.

Here is my test script:

[email protected]:~/projects/docker/lisky-alpine$ cat sendcmdstoLisky.sh echo "set json true" docker exec --interactive relaxed_mcnulty /usr/local/bin/lisky set json true echo "set pretty true" docker exec --interactive relaxed_mcnulty /usr/local/bin/lisky set pretty true echo "set testnet true" docker exec --interactive relaxed_mcnulty /usr/local/bin/lisky set testnet true echo "get address 6076671634347365051L" docker exec --interactive relaxed_mcnulty /usr/local/bin/lisky get address 6076671634347365051L

And here are the results.

Let’s review what we have learned.

A basic introduction to Docker concepts.

A Dockerfile is a recipe for building an image. If you want to learn more, here is a good tutorial for writing Dockerfiles: www.howtoforge.com/tutorial/how-to-create-docker-images-with-dockerfile/ .

How to build a Docker image from a Dockerfile. docker build --tag lisky:alpine .

How to start a Docker container from a Docker image and use it interactively. docker run --interactive --tty --rm lisky:alpine lisky

How to run basic Lisky commands. For more commands, see lisk.io/documentation/lisk-commander/usage.

How to send commands to running containers using docker exec --interactive container command .

Hope you enjoyed this article as much as I enjoyed researching and writing it!

You can find the Docker images created for Lisky in this article at hub.docker.com/r/johnalexhebert/lisky/.

Next Article: A Network of Lisk Nodes and Lisky Clients Using Docker Containers

My next article will cover creating an isolated Docker network of Lisk Core nodes and launching multiple Docker Lisky containers inside of it for development and testing.

Questions and Suggestions:

[email protected]

twitter: John Hebert