Category Archives: Docker

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: