We all know how wonderful piece of hardware the Raspberry Pi is, can do many things, just to mention three cool projects: Multimedia Center, Meteorological Station and Retro Game Console. In this Awesome List you could get a collection of tools, projects, images and resources related to Raspberry universe.
I like to be at the technological forefront, it means I’m always testing services to satisfy some particular interest. Raspberry Pi has become my faithful companion of these hobbies, however many times I have given up to try out a new service because of the anxiety of going through the process of starting from scratch a new service setup and to add unnecessary extra load on my Pi.
Recently, I had the chance to use and setup Laradock, a Docker development environment and this project was a radical change for me in how to tackle development environments. I had already heard about Docker and I always believed that Docker was just a VM manager (what a n00b!), but after using it and reading a lot about it I understood what it really is, a platform that simplify the process of building, shipping, running and sharing applications in different environments and in that moment I’d realized Docker and Raspberry Pi can give me all the confidence to use and build services quickly and efficiently without reinstalling again and again the Raspberry OS.
Through this article I want to describe my procedure to setup Docker Engine using a Debian headless server on a Raspberry Pi. With this setup, you will manage to build and execute as many
docker containers as a Raspberry PI can withstand (i.e. VPN server, TOR router, Load Balancer, Apache or Nginx Server, NAS server, etc.). As you realized, a
docker container is an isolated and secured server instance running as a virtual OS inside Docker Engine and sharing resources with the host OS.
To complete this guide you will need:
- Raspberry Pi (dah!).
- MicroSD card and adapter.
- Ethernet connection.
- Linux box to complete following steps.
There are several operating system variants for Raspberry Pi. I’m going to use the latest Raspbian Jessie Lite image, a headless and minimal image based on Debian 8.
Find device where your SD card is located in your linux box. Use
lsblk command and search disk with the size of your SD card. In my case, my device is
Format the partition of your SD card, which I don’t think you need to do, but I thought it would be good to remind myself of the mkfs command.
raspbian_lite.zip and copy the image in your SD card. If you use
dd make sure that you are not using the first partition on de SD card, use
of=/dev/mmcblk0 and not
For Jessie Lite, SSH is disabled by default. You must enabled it by placing a file named
ssh, without any extension, onto the boot partition of the SD card. When the Pi boots, it looks for the ssh file.
You can execute following script to auto create the ssh file onto the boot partition of the SD card.
You could also mount the SD card using your linux box and manually create the file in boot partition.
It’s time to boot your rpi, plug the SD card in your Pi and turn it on. All raspberry devices MAC addresses in the world starts with B8:27:EB, if your pi is connected to the network you can easily find it with a
nmap command sorcery. Replace 192.168.1 with the according segment of your internal network.
In my case I got two IP addresses, 192.168.1.4 is a Pi running a NAS server and 192.168.1.135 is the one recently created.
That’s it! You can now connect through SSH
ssh firstname.lastname@example.org and configure your Pi via
sudo raspi-config. (The default user is pi and default password is raspberry)
Since 2016, Docker provides official support for the ARM architecture. To install Docker Engine, logon to your Pi and just type:
If everything goes well, you should be able to check Docker version in console.
After some time using Docker, one of the first tools you will need from Docker universe is
docker-compose, So it is better to have it installed now. Just type:
If everything goes well, you should be able to check Docker Compose version in console.
docker-compose you should be able to manage multiple containers as one single project application. From development point of view, this is one of the features I love, it has a similar purpose as
package.json manage your nodejs and module project dependencies, with
docker-compose you are able to define your multi-container dependencies in
docker-compose.yml file in order to build and run a particular environment.
And from here, my friend, you can start to create, pull, run, stop, delete containers as if there were no tomorrow.
As a quick example, let’s try a service that I love, AllTube, is a video download service and could be used to save music sessions from Youtube in mp3 format, I usually use it to have my gym workout sessions on my mobile. To create and run a container with AllTube in your Pi-Docker engine just ssh to your pi and type:
If you want to stop this service just type
sudo docker stop alltube or if you want to start it again
sudo docker start alltube. Your OS host will never be affected with any dependency from AllTube.
Let me know in comments, what do you think? Do you want me to write about a particular service running on a Docker-Pi?