From SmartCore Wiki
Jump to: navigation, search

Installing docker swarm

This i an experimental setup. The purpose is to finalize the solution for SmartCores working in concert, in a local setting.

Aim of this test is to achieve the following:

  • Encapsulation of SmartCore services into docker modules, for easy deployment
  • Establish a cluster structure, to utilize the available combined resources.
  • Establish mesh networking capabilities.
  • Configure an distributed file system, able to support rocket-store database.
  • define the optimal method of inter-process communication/ service requests between instances of SmartCore.

Up to date

The Docker swarm should be installed on an up-to date Raspbarian

To make the current installation current:

   sudo apt-get update
   sudo apt-get upgrade
   curl | sudo bash
   sudo usermod -aG docker admin

on PI Zero there is a bug in the compilation of version 18.09.X that dump the core. You have to downgrade to version 18.06.1 :

   sudo apt-get remove docker
   sudo apt-get install docker-ce=18.06.1~ce~3-0~raspbian

Initilize swarm

   docker swarm init

Store the swarm token. it might look like this:


Add other nodes to the swarm, by running this on the new node:

   docker swarm join --token SWMTKN-1-0e99skdr1voer2o02iwwxnqc1de0lwnkabhdal635l0vlzwryu-73djph149p8gizmc0adk09k1g

Test that swarm is running:

   docker node ls

To get the swarm toke at a later time, run this command on the swarm manager node:

   docker swarm join-token manager

Build a docker application

let build a super simple webserver, serving a page at port 8080.

This command will produce a web server instance, serving local php files.

   php -S

Create an index.php file, that show some in formations:


Create a docker definition file:

   # Include a PHP image
   FROM php:7.2-cli
   # Set the working directory to /app
   WORKDIR /app
   # Copy the current directory contents into the container at /app
   COPY . /app
   # Make port 8080 available to the world outside this container
   EXPOSE 8080
   # Run when the container launches
   CMD [ "php", "-S" ]

Create container:

   docker build --tag=web-test .
   docker image ls

RUN a test webserver

   docker service create --name web --replicas 1 --publish 8080:80 hypriot/rpi-busybox-httpd vsvyanuw6q6yf4jr52m5z7vr1

Install distributed FS

Run installation on all nodes:

   sudo apt install glusterfs-server glusterfs-client
   sudo systemctl enable glusterfs-server

Create a shared directory on each node.

   sudo mkdir -p /tmp/cluster

create replicated file system:

   sudo gluster volume create scfs replica 3 <IP address node 1>:/tmp/cluster <IP address node 2>:/tmp/cluster <IP address node 3>:/tmp/cluster force
   sudo gluster volume start scfs


   sudo gluster volume info

Mount on each node: pi@rpi-01:~ $ sudo umount /mnt pi@rpi-01:~ $ sudo echo 'localhost:/rpi-gfs /mnt glusterfs defaults,_netdev,backupvolfile-server=localhost 0 0' >> /etc/fstab pi@rpi-01:~ $ sudo mount.glusterfs localhost:/rpi-gfs /mnt pi@rpi-01:~ $ sudo chown -R pi:docker /mnt