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.

Commands

Creation of the swarm

docker swarm init –advertise-addr 192.168.1.241

docker swarm join –token [The join token] 192.168.1.241:2377

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@192.168.1.254:/home/jonathan/.jenkins/workspace/SvcLogin/svclogin/target/scala-2.12/svclogin.jar
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.

./cqlsh 192.168.1.254
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

Dockerfile

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

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@192.168.1.245:/opt/apps/docker_trial/

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

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":["192.168.1.254:5000"] }

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 192.168.1.254:5000/svclogin-app
docker push 192.168.1.254:5000/svclogin-app
docker image remove svclogin-app:1.0.0
docker image remove 192.168.1.254:5000/svclogin-app

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

http://192.168.1.254:5000/v2/_catalog

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 192.168.1.254:5000/svclogin-app
docker service create --restart-max-attempts=10 --detach=true --name swarm-svclogin 192.168.1.254:5000/svclogin-app
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.