Build your PiZero Swarm with OTG networking

So I unleashed a picture on the Internet several weeks ago which combined Docker, the Pi Zero and OTG networking. A lot of you responded to the post and wanted to try it out for yourself so I've put a new tutorial together.

The Raspberry Pi foundation's Matt Richardson also bundled up the original tweet along with some of my best Docker material and posted it onto the official blog below:

If you have no idea what Docker is, check out the post from the Raspberry Pi foundation above

Before we get into the guide, I wanted to give you a bit of background.

Q&A

OTG networking uses a gadget module in the Linux Kernel and can be used as a stand-in for Ethernet. Docker will run on an OTG network in the same way it would any other - providing that the various hosts have connectivity with each other.

Why would I use OTG networking?

OTG networking when done right means that a Pi Zero can be connected to almost any host device (PC, Pi 3, Laptop) with a single USB cable to create a fully-workable network.

This saves on network switches, cables, power supplies and bulk. That would have been a handy saving @ Container.Camp:

So how does it work?

You will get your hands messy by editing system config files and setting up static IP addresses and subnets. Once complete you will have in theory the equivalent of a USB ethernet adapter.

If hacking on system files is not for you, then you may find the ClusterHAT (which comes with pre-flashed images) to be an easier alternative. See below.

But Docker, though?

Once your networking is fully configured you can set up a Docker Swarm in exactly the same way you would with an Ethernet configuration with my other Deep Dive guide.

If you're wondering what a Swarm is, this is the best place to start:

Here is an example from last night when I ran through the instructions and created a brand new OTG cluster with Docker:

OK.. how do I do this?

Follow the QuickStart guide on Github.com:

Please send your comments, questions and suggestions my way on Twitter or via the comments section.

Who else is doing this?

There is a very cool product called the ClusterHAT which can be mounted onto a Pi's GPIO header to provide a USB hub for your Pi Zeros. Docker can also be used with this setup.

James from Raspberry Pi Berlin Meetup has built a 360-degree camera using Pi Zeros and OTG networking. I'm still trying to convince him to try out Docker. It makes building, deploying and updating your software so much easier than manual hacking and scripts.

What could go wrong?

The reason for the air-gap between my initial Tweet and these instructions is due to the sheer amount of unreliability I've experienced with OTG. The power supply needs to be just right, the host needs to be just right, the cables have to be perfect quality - and if the planets align you may be able to boot up 4x Pi Zeros at once.

Don't let this put you off - I would like to improve the solution so please send in your comments, questions and suggestions.

The bandwidth may also be more limited when using 4x OTG devices through the shared USB host than through Ethernet ports. It would be good to see how this plays out in practice - if you want to do some benchmarking with Docker Swarm that would be really interesting to see.

See Also:

I host my blog on a Raspberry Pi 3 using Docker. You can find out more below:

If you want to find Pi Zeros then check out stockalert.alexellis.io and the write-up below:

Alex Ellis

Read more posts by this author.

United Kingdom http://alexellis.io/

Subscribe to alex ellis' blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!