Category Archives: Raspberry Pi

Docker Custom Images

Download PDF

Docker Custom ImagesCreating Docker Custom Images on the Raspberry Pi

In this tutorial we are expanding on the previous video where we looked at using Docker and the Docker engine on the Raspberry Pi. Here are still working with the basics of Docker at an overview level but we will gain a better understanding of how and why we use Docker by building Docker custom images. We will stick with the Raspberry Pi 2 has the Docker host but you may be using any host Docker system. As I am using ARM hardware I will use the armbuild/debian image as my base but you may just use Debian if you are using standard Intel hardware. At the end of this module you will be able to create Docker custom image from a Dockerfile.

Select Your Base Image

In Docker images are Read-Only templates that can be used to provision Containers. Containers and vaguely comparable to Virtual Machines in other technologies, but very vaguely . One major way that Docker Containers differ from traditional virtual machines is that they are designed to run one process only. This may be your web server or your database server etc. Containers have a thin read-write layer that overlays the underlying Image that it was provisioned from. In the scenario we want to deploy and Apache HTTPD server with PHP. We will use a Debian base image for this. Later we will add the required packages to the base image to create the Docker Custom image.

$ docker pull armbuild/debian:8.0 #I am using ARM hardware just debian:8.0 for Intel

Create the Dockerfile

A Docker file is a text file that contains instructions on how to build the new image. It has to be called Dockerfile in the exact case. In a perfect world you will create this in its own empty directory as contents from the directory that the Dockerfile is located in can be added to the image you are building.

For the purpose of this we will create a new test directory in or HOME directory:

$ mkdir $HOME/test ; cd $HOME/test

From with the new directory we can create the $HOME/test/Dockerfile with the editor of choice:

FROM armbuild/debian:8.0
RUN apt-get update && apt-get install php5 && apt-get clean
CMD ["/usr/sbin/apache2ctl","D","FOREGROUND"]


This instruction defines the image that we base the image from


These are instructions to run inside the temporary container during image creation. We have combined the commands together to reduce the amount of layers that are created in the resulting image. Installing PHP5 on the debian image will install the Apache HTTPD package as a dependency.


We tell the resulting container run from this image to listen on port 80 or to open port 80. We need this to talk to the wen server. We will later map port 80 on the host to port 80 on the Docker container to allow access from external hosts.


This defines the command that will be PID 1 or Process ID 1 when the container start. We can use CMD or ENTRYPOINT but CMD allows us to overwrite the command from the command line whereas ENTRYPOINT does not. This is useful sometime in faulting a container in that we can stat it with a bash shell when ENTRYPOINT is not defined.

Create the Docker Custom Image

Now we have the Dockerfile we can build the new image. From the test directory:

$ cd $HOME/test
$ docker build -t debian/web .

We use the -t option to set the tag or name of the image. As it is based on debian I use that and then /web as it is a web server image. These names are fine so long as you do not intend to upload them to Docker hub where they will need to named after your userid. The dot or period at the  end denotes that we look for the Dockerfile in the current directory. When we run the command it may take a few minutes installing the software

$ docker images

Using the above command we should see the new image once it is created.

Building Containers

We can run a test container to see that it works

$ docker run -d -p 80:80 --name test debian/web

We should now be able to browse to the Docker host on port 80 and see the standard Debian welcome page. To add our own content we need to ensure the website is available in a directory, such as $HOME/www. We will first stop the test container and then start a new one with the $HOME/www directory on the host mapped to /var/www/html/ on the container. Remember we must create the website in on the Dockerhost and mount it to the container at runtime

$ docker stop test
$ docker rm test
$ docker run -d -p 80:80 -v /home/pi/www:/var/www/html --name test debian/web

Now when browsing to the site we should see the content of the website we created in your brand new container.

The video follows please take a look….

Raspberry Pi Docker Host

Download PDF

RPI Docker HostUsing an RPI Docker Host

In this blog we look at using a Raspberry PI 2 and a Docker host device. Yes an RPI Docker Host. In the video we use the RPI 2 but I also have it running on a Model B with the single core and 512MB RAM. The Version 2 has 4 cores and 1GB RAM so is better suited to this type or work. But for simple learning the Model B or B+ is fine. I am also running this with just an 8GB SD card or MicroSD card in the model 2. We don’t need a lot of space wither for the host OS or docker containers and images.

Setting the Hostname

This is a little different in the HypriotOS. Their boot loader sets the hostname and we set it in the /boot partition. This means that it can be set before you boot the system if you access the /boot device on another system even Windows. As my system is up and running we can configure this by editing the /boot/occidentalis.txt file and changing the hostname from black-pearl to your hostname. A reboot will then configure the hostname and add entries to the /etc/hosts.

Docker is Pre-Installed

Docker 1.6 is pre-installed on this system so this is an RPI Docker Hosts out of the box. Whilst 1.8 is the latest version 1.6 is not old and better than many current distributions use. The user pi is a member of the docker group so can manage Docker. Any member of the docker group can manage the Docker host. . The password for pi is raspberry and the root password is hypriot.

Show the client version
$ docker -v
Show client server and golang version
$ docker version
Display more detailed information
$ docker info

What is Docker

Docker is a container virtualization product. Allowing quick and easy deployment of services is separated Micro Operating Systems that share the host kernel. The downloaded images are very small and customizable. If you want a web-server or MySQL server you can spin up a container in seconds and the service will be running.

Take a Look

We will now fire up a web-server in its own OS and IP Address. This will be hidden behind a NAT network on the Docker host. To access the web server running in the container we map port 80 on the host to 80 on the container. As we don’t have any images it will download and spin-up  with the one command:

$ docker run -d -p 80:80 hypriot/rpi-busybox-httpd

This literally takes a few seconds and then we can browser to the Docker host and see the website. Sure the content is not our own but it easy to add content to the container as it starts.

The video will step you through what we have discussed:

Working with sysstat and sar

Download PDF

LPIC-2-201Continuing with the objective 200.1 for the LPIC-2 117-201 exam we learn how to monitor our Linux system with tools from the package sysstat. Will will install sysstat on our Raspberry Pi and learn to use tools like iostat and mpstat that are included with the package. the main process to look at the data collection on the sar tool.

When enabled cron will collect data via an sa1 script every 10 minutes and write to /var/log/sa/sa<daynumber> or on Debian based systems like Ubuntu and the Pi /var/log/sysstat/sa<daynumber>. The sa2 script is deigned to create the summary data.

The amount of logs maintained can be controlled via the HISTORY directive in the file:

/etc/sysstat/sysstat (Debian)
/etc/sysconfig/sysstat (Red Hat)

If more than 28 is specified then sub directories for the months will be created.

Before the log files are initialized we can read data with

sar -u 1 1

To read CPU activity

sar -q 1 1


To read load average information. Without the interval and count that data would be read from the day file that matches the current data or the specified date file

sar -q (current day)
sar -q -f /var/log/sysstat/sa1 (from the first of the month)


An Introduction to Python on the Raspberry Pi

Download PDF

An Introduction to Python on the Raspberry Pi

LinuxEssentialsBorderSMALLFor this edition of LPI Linux Essentials for the Raspberry Pi we take the time to introduce ourselves to Python programming. When writing code in Python the idea is to stick to the 20 Zen rules of Python, the 20th is never spoken. To display this rules from a Python prompt you can type:

import this

We can start a Python prompt from the command line of the Raspberry Pi by entering the command:


Note: Running just python we start python version 2.7 not version 3.

The interactive Python shell is known as the REPL:

  • Read
  • Evaluate
  • Print
  • Loop

We can run simple arithmetic operations:

8 * 3

And so on. For more complex mats we can import a Python module:

import math

The result of the evaluation will be printed, I think it is 12.

Python uses significant white space to help define code blocks rather than braces that are often used in other languages. The lack of braces should aid readability by forcing the need to indent code. The standard is to use 4 spaces for an indent level. We see this in the video with a simple for loop:

for name in 'bill', 'jo', 'jack':
print("We are out of the loop")

The end of the for statement and the start of the code block is identified by the : . Each line of code that makes up part on the loop is then indented 4 spaces. The final line is not indented and so is not part of the loop.

If we wanted to print the name in upper case (upper) or proper case (capitalize) we can use methods from the string. The variable name once created is immutable, ot cannot be changed. When we convert it to upper case we create anew string, this means that we can use the original string if we need;

for name in 'bill', 'jo', 'jack':
print("We are out of the loop")

To leave the REPL interactive shell on the Pi use the keys Control + D

Understanding openLDAP Directories on the Raspberry Pi

Download PDF

LinuxEssentialsBorderSMALLThe purpose of a Directory Server such as openLDAP is to centralize user information. That may be just for a white-pages where users can search for the phone or extension of other users or it may be used as a centralized account repository so users can log on from  any Linux device or Pi without having to have an account on the local machine, the account details are all in the Directory. In a Microsoft world the Active Directory is an LDAP Directory service, openLDAP is an open source implementation of the Directory service.

For the purposes of the Linux Essentials exam you will just need to know about openLDAP and not really too much detail on configuring it. If you want to setup the Raspberry Pi as an openLDAP server then these two links should help you.

Installing openLDAP on the RPi

Authenticating the RPi to a Central openLDAP Directory

In the video we look at connection to the openLDAP server using lat, the LDAP Administration Tool.

Understanding a Simple Samba Server on the Raspberry Pi

Download PDF

LinuxEssentialsBorderSMALLIn this video we look at a simple Samba Server on the Raspberry Pi for the LPI Linux Essentials exam. This is all about understanding major open source applications and SAMBA; Windows File and Print Sharing is certainly that. You will see that is is easy to create file shares on the Raspberry Pi that are available to Windows Client. The normal windows explorer can connect the the file shares that we define on the Pi.

To install Samba:

sudo apt-get install samba samba-common-bin

We then need to create samba user. These are user names and passwords that will be used by the connecting window’s users. The account names that we use must also be Linux users. We will add in the pi account into the samba password file

smbpasswd -a pi

Now we will edit the file /etc/samba/smb.conf. This coud be edited with nano or vi but you will need to run with sudo or as root.

We can define a share

path =/repo
read only = yes

Now restart the service

sudo service samba restart

And from your Windows client you can connect to the share. I am using the IP address of the Pi as I do not have a DNS server setup the resolve the name to and IP. You can use the command

ip a

To display the IP Address.

Installing and Using MySQL on the Rapberry Pi

Download PDF

LinuxEssentialsBorderSMALLIf you are studying for you LPI Linux Essentials then objective 1.2 will want to introduce to you some of the major open source software applications. As far as server applications the MySQL database server is one of the big ones. Acting as the back-end to many CMS, content management systems, such as Drupal, WordPress and Moodle you are likely to come across MySQL sooner rather than later, It is also the M in the LAMP  stack, Linux, Apache and PHP. For this video we will look at installing MySQL.

sudo apt-get update
sudo apt-get install mysql-server mysql-client

With this installed we will prompted to set the root account for MySQL. this is a separate account to the Linux root user and should have different passwords. We can login using the client:

mysql -u root -p

We will be prompted for the password.

We can create the new database

create database tup;
use tup;

The we will create the table:

create table users (
userid tinyint signed not null primary key auto_increment,
username varchar(50)

With the table created we can add data to the table:

insert into users (username)
select * from users;

So a quick introduction to MySQL.

Image Manipulation on the Raspberry Pi using ImageMagick

Download PDF

LinuxEssentialsBorderSMALL Still working though are major open source application for the LPI Linux Essentials topic 1.2 we are going to become acquainted with ImageMagick. This is a set of command line tools but do not be put of by that. We will see how easily it is to covert image formats as well as other manipulations.  The real importance here, as we all these applications, it to gain the appreciation of the tools the open source software can offer.

To install this on the Raspberry Pi:

sudo apt-get update
sudo apt-get install imagemagick

If you have a PNG format image that you want to convert to JPEG; this can be achieved from the command line:

convert file.png  file.jpeg

To resize an image to 150 pixels width, height is adjusted to scale

convert file.png -resize 150 150-file.png

To resize image to 150 pixel height and allowing width to scale accordingly:

convert file.png -resize x150 150-file.png

This of course can be part of a batch process:

for p in *.png ; do
  convert "$p" -resize 150 150-"$p"

Take the time to watch the video and find out more.

Using GIMP on the Raspberry Pi

Download PDF

LinuxEssentialsBorderSMALLNo, I am not mad and this is REAL. We show how you can create your own logo or manipulate images within the GIMP package on the £20 PC that is the Raspberry PI. You know that visiting the local PC store you will not be able to leave without having spent  may be £250, then you might spend something similar on Photoshop. The LPI Linux Essentials introduces the advantages that a £20 computer a free Open Source Software, GIMP has to offer.

Installing GIMP on the Raspberry Pi is simple

sudo apt-get install gimp

Then we create our 400 by 400 pixel image in minutes in real time in the video

Installing an Apache Web Server on the Raspberry Pi

Download PDF

LinuxEssentialsBorderSMALLOf course we have server applications as well as those for the desktop. Adding the Apache httpd server to the Raspberry Pi will enable the tiny device to serve web content to you are the massed numbers of users on the worldwide web. You can imagine using the Raspberry Pi with online documentation that you make available though the web server. Even if this just to you and your office or home. The web server may also reach out to run other scripts and the web server may be the front-end graphical interface that you supply to control your pet robot or home heating. A wb server is omnipotent.

To install the web server on the Pi:

sudo apt-get update
sudo apt-get install apache2

Once installed the packaging script will configure apache for autostart and start the service. You should be able to browse to your site from the desktop of the Pi using the name localhost.


You will need to know the Ip Address of the Pi to access it from another host. from the command line try :

ip address show

On my system my address is

The standard Apache welcome page will display display “It Works”. If we want we can then replace this page with one of our own making. The page is located on the Pi as /var/www/index.html