How to Install Docker on Raspbian OS

29/12/2020
Chưa phân loại
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.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Install DenyHosts on Ubuntu

Install and Configure DenyHosts on Ubuntu DenyHosts is a python script which allows or denies access to SSH server using...
28/12/2020

Installing Debian 10 Minimal Server

On a production server, you want only the bare minimum programs that are absolutely required for the proper function of...
Chưa phân loại, vps giá rẻ
29/12/2020

Install Ubuntu on Raspberry Pi

Installing Ubuntu Mate on Raspberry Pi 2 and 3 WHAT IS RASPBERRY PI? Raspberry pi is a credit card-sized computer that can...
12/02/2020