Running a Docker Swarm on Raspberry Pi 5

Zach Koch - Sep 9 - - Dev Community

Intro

This article assumes Raspberry Pi 5s running Pi OS 64-bit connected to your local network.

You can use direct input, ssh, or my new favorite Raspberry Pi Connect to run these commands

If you follow my install instructions below, you will likely need to add sudo before each docker command. Otherwise you get an error like permission denied while trying to connect to the Docker daemon socket at ...

Docker swarm layout

A Docker swarm consists of

  • manager nodes which run tasks and add availability
  • worker nodes which host containers and add capacity

The recommended minimum of manager nodes is 3 for high availability. This is so you can take one down and the other two will continue to run the swarm.

Manager nodes also act as workers with extra overhead.

In my case I have 3 devices total so I will be making all of them managers, but any additional devices will be workers.

Install Docker

You can follow my guide to install docker on your raspberry pi 5.

Initialize the swarm

Use ifconfig to see your ip

It should be the first ip listed likely under:

  • eth0 for ethernet
  • wlan0 for wifi

Then use the following command to initialize your first manager node

docker swarm init --advertise-addr [ip address]
Enter fullscreen mode Exit fullscreen mode

Add other managers

On the node where you initialized your swarm run this command

docker swarm join-token manager
Enter fullscreen mode Exit fullscreen mode

Copy the output and for each of your other devices input this line to add them as manager nodes

Add worker nodes

If you want to add worker nodes int he future, the process is the same but you use this line on a manager node:

docker swarm join-token worker
Enter fullscreen mode Exit fullscreen mode

Test by adding a service

To test your swarm use this command

docker service create --replicas 5 --name helloworld alpine ping docker.com
Enter fullscreen mode Exit fullscreen mode

This will create a single service with 5 replicas/containers of helloworld running.

To see the service run

docker service ls
Enter fullscreen mode Exit fullscreen mode

to see where the service has placed the replicas use

docker service ps helloworld
Enter fullscreen mode Exit fullscreen mode

Under the nodes column you should see that it has spread the replicas across your devices

To remove the service and containers enter

docker service rm helloworld
Enter fullscreen mode Exit fullscreen mode
. . .
Terabox Video Player