More cribsheet, memory jogger for myself.

In this post I set up a Scala service, connecting to Kafka and Cassandra, built via jenkins, installed into the insecure docker registry, downloaded to the swarm Raspberry PI’s and then start it. I compare the performance from a jvm outside docker, to docker run, to docker swarm running it.

Think of this as a first step into swarm mode on a PI swarm.


Creation of the swarm

docker swarm init –advertise-addr

docker swarm join –token [The join token]

Swarm information and state

docker node ls

docker info

Service creation for a Scala service

Use the assembly plugin to create a single jar, and SBT to assemble it. Copy the jar to a root dir for the docker image, and put in the Dockerfile, for example the one below.

Note that I set up a Jenkins build, and have it creating the assembly for the service.

Test outside docker

It’s obvious, but once you have your jar, make sure it runs. So, for my login service run it on the target raspberry pi:

scp jonathan@
java -cp svclogin.jar -Denv-name=pi com.jgibbons.svclogin.LoginService

This service hooks into Cassandra and Kafka, which are running on a Linux server.

use keyspace test_auth;
select * from website_user;

The other thing I do is gather latency stats in this test

2017-12-31 10:30:01.263 LoginServiceTestHarness In ,
2017-12-31 10:30:01.181 LoginService Out,
2017-12-31 10:30:01.174 LoginService In ,
2017-12-31 10:30:01.121 LoginServiceTestHarness Out

The latencies are using a slow wifi connection (too many bricks in the way). I should also point out that my ZooKeepers lost quarum so I increased their tick size to 10 seconds.

So, test complete, lets try it in a Docker image.

Build docker image


FROM resin/raspberry-pi-openjdk
MAINTAINER JonathanGibbons
COPY svclogin.jar /home/svclogin.jar
CMD ["java","-cp", "/home/svclogin.jar","-Denv-name=pi", "com.

Now build it within local Docker, and extract the image for loading on the target PI, or just build it on the PI.

docker build -t svclogin-app .
docker save svclogin-app > svclogin-app.tar.gz
scp svclogin-app.tar.gz pi@

Since the image is arm specific, run it on the pi (

docker load < svclogin-app.tar.gz
docker images
docker run -it --rm --name docker-svclogin svclogin-app

The stdout from the test against gives me some metrics

2018-01-01 15:44:52.105 LoginServiceTestHarness In ,
2018-01-01 15:44:52.322 LoginService Out,
2018-01-01 15:44:52.292 LoginService In ,
2018-01-01 15:44:51.785 LoginServiceTestHarness Out

Now to run this image in the swarm

docker service create --restart-max-attempts=10 --detach=true --name docker-svclogin svclogin-app
docker service inspect docker-svclogin
docker service ps docker-svclogin

Sadly, the error now is that “No such image: docker-svclogin.1” on all the PI’s except the one where I built the image. Obviously I need the registry, or a deployment mechanism to load the image on all of the PI’s.

But on the PI where the image was built:

docker service logs docker-svclogin

and I can see the log output! So run the test again:

2018-01-01 16:44:55.321 LoginServiceTestHarness In ,
2018-01-01 16:44:55.554 LoginService Out,
2018-01-01 16:44:55.506 LoginService In ,
2018-01-01 16:44:54.997 LoginServiceTestHarness Out

Docker registry

Only running in pre-prod mode, so, run the registry image within docker….

docker run -d -p 5000:5000 --restart=always --name registry registry:2
docker stop registry && docker rm -v registry

So, once I have built my image, I can push it to my registry, but first lets make sure its set up to be insecure (!). You have to do this on every node in the swarm, as each of them will want to download from the repository.

sudo vi /etc/docker/daemon.json
{ "insecure-registries":[""] }

and restart it

sudo service docker restart
docker run -d -p 5000:5000 --restart=always --name registry registry:2
docker build -t svclogin-app:1.0.0 .
docker tag svclogin-app:1.0.0
docker push
docker image remove svclogin-app:1.0.0
docker image remove

Note you can now use the HTTP interface to look in the registry catalog using Firefox (or whatever)

Now on the raspberry pi’s, you can either let swarm pull the image, which means you cannot tell any progress, or do it yourself. Note that scp the saved tar image would actually work rather than using the registry…

docker pull
docker service create --restart-max-attempts=10 --detach=true --name swarm-svclogin
docker service inspect swarm-svclogin
docker node ls
docker service ps swarm-svclogin
docker service logs swarm-svclogin

Some other docker service commands

docker service logs
docker service ls
docker service rm
docker service scale
docker service ps
docker service update

Thats that for now, ie I have a deployed docker swarm service.