Raspberry Pi

How to Install Docker on Raspbian OS

Raspberry Pi is a single board computer. Since Docker is a containerization system, it does not need much resources to run containers. It’s very lightweight. So, Docker can be a perfect candidate for web app development and testing on Raspberry Pi. Of course, you can do other things like running a web server, proxy server or a database server etc. on Docker on Raspberry Pi single board computer.

In this article, I am going to show you how to install Docker on Raspbian OS that runs on Raspberry Pi. So, let’s get started.

Installing Raspbian OS on Raspberry Pi:

You can easily install Raspbian OS on your Raspberry Pi device.

I’ve written a dedicated article on installing Raspbian OS on Raspberry Pi. You may check it out at https://linuxhint.com/install_raspbian_raspberry_pi/.

If you don’t have an external monitor, then you can enable SSH access before you boot into Raspbian OS from your Raspberry Pi and SSH into it. I have demonstrated the process in another article of mine which you can check at https://linuxhint.com/rasperberry_pi_wifi_wpa_supplicant/.

Installing Docker on Raspbian OS:

By now you should have Raspbian OS installed on your Raspberry Pi single board computer. Now, boot into Raspbian OS.

If you’re using Raspbian OS with Desktop Environment, then open up a terminal. If you’re using Raspbian OS lite version, then connect to it using SSH.

You can connect to your Raspberry Pi through SSH using the following command:

$ ssh pi@IP_ADDR

NOTE: Here, IP_ADDR is the IP address of your Raspberry Pi.

If you’re connecting to your Raspberry Pi for the first time, then you will see the following message. Just type in yes and then press <Enter>.

Now, type in the password of your Raspberry Pi and press <Enter>.

You should be logged in to your Raspberry Pi.

Now, update the APT package repository cache of Raspbian with the following command:

$ sudo apt update

The APT package repository cache should be updated.

Now, you have to upgrade all the software package of Raspbian OS. This is an important step.

To update all the software package of Raspbian, run the following command:

$ sudo apt upgrade

Now, to confirm the update operation, press y and then press <Enter>.

The software packages are being updated as you can see. It will take a while to complete.

At this point, the software packages should be updated.

Now, you have to install the kernel headers for the Raspbian OS. This is important as if you don’t install the kernel headers, Docker won’t work.

To install the kernel headers, run the following command:

$ sudo apt install raspberrypi-kernel raspberrypi-kernel-headers

Now, press y and then press <Enter> to confirm the action.

The kernel headers should be installed.

Now, you can install Docker with the following command:

$ curl -sSL https://get.docker.com | sh

Docker is being installed. It may take a while to complete. Time for a cup of coffee!

Docker should be installed.

Now, you should add the user pi to the docker group. So, you will be able to create and manage Docker containers, images, volumes etc without sudo or super user privileges.

To add the user pi to the group docker, run the following command:

$ sudo usermod -aG docker pi

Now, you have to restart the Raspberry Pi in order for the changes to take effect.

To restart your Raspberry Pi, run the following command:

$ sudo reboot

Once your Raspberry Pi boots, connect to it using SSH again.

Then, to check whether Docker is working or not, run the following command:

$ docker version

As you can see, Docker is working perfectly.

 

Creating Your First Container:

In this section, I am going to show you how to create a Docker container. The main objective here is to show you that Docker on Raspberry Pi does work really well.

Let’s say, you want to create a nginx server container. To do that, run the following command:

$ docker run -d -p 80:80 nginx

Docker is downloading the container image as it is the first nginx container being created and the image is not cached locally yet.

The nginx container should be created.

As you can see, the container is running.

$ docker container list

Also, I can access the nginx HTTP server container from my browser.

So, that’s how you install Docker on Raspbian OS that runs on your Raspberry Pi. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.