Get Started with Docker - Part 2a : Raspberry Pi & Linux Install Guide
Tags: docker, tutorial, beginners, raspberrypi
Published: 2024-02-27 20:31:34

Running Docker is pretty straightforward on Linux and makes using a Raspberry Pi, in my opinion a lot easier. It's really helpful when trying to squeeze out every last bit of performance from the lil computer that can.

>If you're looking to install this on Windows then click the link below for our Windows Setup Guide : "Get Started with Docker - Part 2b: Windows Install Guide" - **Coming Soon**

Personally, I’ve found **Raspberry Pi OS** to be most the stable distribution when using the Pi. You can of course use your preferred Linux flavour like Ubuntu, Fedora etc as the operating system for your Pi.

In this guide, we'll install **Docker** onto a Raspberry Pi 4B 4GB using **Raspberry Pi OS**.

We're going to:

-   Update your Raspberry Pi and Raspberry Pi OS Linux
-   Install Docker and all it’s required components using the convenience script
-   Install Docker Compose
-   Add your Pi user to the Docker group
-   Test the installation with your first test Docker Container

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExNzFxZHNnNTQ5cHl5OTU5ZjhvZXNjazY0eHA0YjhxNzVtYmpxNTBjZiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/IAJBKTMu3NSbm/giphy.gif">

>💡 If you want to know how to "Set up Your Raspberry Pi with Raspberry Pi OS" then check out the below Beginner's Guide to Get Started and then you can continue along with the rest of the guide below - **Coming Soon**

___

## Using GUI or SSH?  

In my case I like to use SSH to connect from another machine, as it uses less resources than the GUI.

Using SSH means you don't have to have a monitor plugged into your Pi to run commands which can help devices like the Pi Zero.

You’re welcome to use the commands in this guide either in the terminal using the GUI, or connecting via SSH.

This guide will also assume that you've connected to your Pi using SSH once already and know it's IP address or can find it.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExMWM0c2wxZGhxd2trYzQycXQ0dGp0dnJ4ZWR2MDM0Y2J0dWNodXplMiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/bi6RQ5x3tqoSI/giphy.gif">

First, let's make sure the Pi's updated.

___

>The example IP address for the Pi in this guide, is ****192.168.0.177**** but yours will probably be different so please replace that below as needed.

>We're also going to be using the username ****pi**** in this guide but if you've changed yours then please replace it for the username >as needed to.

___

## Update Your Pi

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExYm81OXV2NG91emtseDdqN3RyMWZva293Z2J5bXpqcDVldnY2cGJjdiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/Fn7EouKtFLHXhWKgFI/giphy.gif">

-   Connect to your **Pi** using **SSH**

-   Open up **Windows Terminal** and enter the below with your username and IP Address

```
ssh pi@192.168.0.177
```

-   You'll then be prompted for your **password** to login.

-   Run an **update** and **upgrade** on the **Pi** using the sudo command below

```
sudo apt-get update &amp;&amp; sudo apt-get upgrade
```

-   This will take a few minutes depending on your internet connection and the last time your Pi was updated.

-   Type **"Y"** and **Press Enter** to continue and install the updates.

-   Installing the updates will take a lot longer than checking for them so this is the perfect time to grab a coffee and come back later.

-   Once updated you'll come back to the command line.
    
-   Type the below command to reboot your PI to commit the updates, wait for it to start back up and connect again by using SSH for the next step.
    
```
sudo systemctl reboot
```

>Please Note: If your Pi hangs, become unresponsive and doesn’t reboot here. Then you may need to disconnect the power cable from the back of the Pi, wait about 15 seconds and reconnect it. This will power cycle the Pi and shouldn’t damage anything but may be the only way to get it to fully reboot as a last resort.

___

## Install Docker  

Docker on **Raspberry Pi OS** is officially supported and that means we can use an install script to automate most of the setup, provided by Docker.

![Docker Hub Image 01](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbhejpiz64909mqxrwpd.png)

-   Once you've updated and rebooted then connect back to the Pi using SSH

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/esud3utqrerrftsmxcdg.png)

-   Credit to this article from [PiMyLife](https://pimylifeup.com/raspberry-pi-docker/) for the suggestion of piping the script directly into the terminal using the below one liner.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExMmMyemdrdThqbmRkY3hkc2poaTFvN2MyMXh1b2twaGpldngwNXE3MCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/jUL2CIAKP9gOKmYMFC/giphy.gif">

-   I'd also suggest adding on the **sudo command** at the beginning as I've had some issues with the **curl** command failing to download on an Azure Ubuntu VM installation.

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

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/67wt4ola3gifadpxenrr.png)

-   This will take a lot longer than the previous update took earlier and the script will download all files and dependencies needed for your **Docker** installation.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vaw6pn3y8g4sbsqwwnw2.png)

-   You may want to grab another coffee and let the script do it's work


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xx0pbkt5xm1imskc6hou.png)

-   You now have **Docker** with the **Docker Engine** installed on your **Raspberry Pi**.
-   Type the below line and **Press Enter** to check for any running docker containers

```
sudo docker ps
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qm0vm6o7k6hzmjhpa2p3.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh6u5jwgujvt3ka3t2pa.png)

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExc3pubmwzb3dkOG9iMnBlM3p5OGFrbjNzdHM5ODd5dXh3bWVyMXdnayZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3nlnWnTYCRxPnzMihQ/giphy.gif">

___

## Install Docker Compose  

You’ve almost got all of the basic components for Docker installed but if you want to use **Docker Compose** YAML files then you’ll need to have **Docker Compose** installed.

-   Type the below command and **Press Enter** to get it installed

```
sudo apt install docker-compose
```

![I](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tgv769a55qi0hm244ef.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60n9ud2psjeh8sty83wy.png)

-   Type **"Y"** and **Press Enter** to continue and install the updates.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqlgj46rxov1jk4dvn96.png)

-   This will remove any extra parts to **Docker** that were installed using the Automated script and also install what we need to get **Docker Compose** running.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqd67u2f3t55p86jvcad.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttvagg4rc4808adpui5b.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itg4g31i1868qbs2ecls.png)

-   Once that’s installed, you can check your **Docker Compose** version with the below command.

```
sudo docker-compose version
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wy6pvuuuv7orzixe0ia8.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sxmvn7r6v4puu5arml3x.png)

-   Then type "**clear"** and **Press Enter** to clear the terminal for our next step.

```
clear
```


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ft34qs55wdfipije9vh.png)

Now that we’ve installed **Docker, Docker Engine** and **Docker Compose**, we need to set up our **Docker** permissions.

___

## Add Pi User to Docker  

You've now got **Docker** installed but when you try to run a **Docker** command you get a permissions issue.

We have a few options here.

You can add **sudo** before every command, **su -** to become root or add the Pi user to the **Docker** group.

We’re going to go for the third option.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExMXRyYmtpOG1nb2ZlcnR4d2dncHVpeW0yMnFsNnJnbTFtc3lwaGs3ZCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3otPoIohp3elV46VEY/giphy.gif">

-   Open a New Terminal or if you're continuing from our last step it should look like this


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mq87ugnmqm3yz8jj1jjs.png)

-   If you **HAVEN'T** used the convenience script then you need to create the docker group first using the below command

`sudo groupadd docker`

-   If you **HAVE** used the convenience script then type the below line and **Press Enter** to add the **Pi** user to the **Docker** group.

```
sudo usermod -aG docker pi
```


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6t3ssghmam30m3t9onq7.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7cejsqqn28waetarpjsl.png)

-   To apply the changes you’ll need to log out and back in via SSH.
-   Type **"logout"** and **Press Enter** to logout

```
logout
```


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zehigvixg5xbrnksrxpa.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j43ggjga1zzqk4012vi7.png)

> 💡Please Note: If you're using a VM then you'll probably need to reboot the VM for your user changes to apply

-   Connect back to Log back in, using the **Pi** user and **password**

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/canb9qwyjmbhgghff7g1.png)


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9ohlajz701hkodmrc45.png)


-   Run the below command to see which **groups** the **Pi** user is currently a member of

```
groups
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocn79f4ch6yhvw78xgq1.png)

-   You should see **docker** as one of the groups listed for Pi with a line similar to this in the terminal output.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1h1t2mexwq6f28rywir.png)

-   We need to apply the changes to the running **Docker Service.**
-   We can do this by restarting that service only, without restarting the whole Pi
-   Run the below command and **Press Enter** to restart the **docker** service

```
sudo service docker restart
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/939m1ki84ya9d5x29xsz.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70owxa3uuuv9zil6l32f.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi8ntefmpiwtaeku3mls.png)

-   Run the below **docker** command to check for running containers again. This time without using **sudo** before it

```
docker ps
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vb0o8v8p64dvk08ka7rx.png)

Congratulations, the Pi user is now part of the **docker** group.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZmZ6M3FoNmI0OG5jOHFzOWM1YnVtMHBsZDY2eHRkbG10aDFrN3RzciZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/Ln9YwHWf9jwb3eKHMD/giphy.gif">

This means you can now run **docker** commands without running **sudo** or being logged in as root.

___

## Testing your Docker Installation - Hello World  

We should now have **Docker** and **Docker Compose** installed. In addition, the **Pi** user should be able to use Docker commands.

-   To test this all out run the below command in your terminal

```
docker run hello-world
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kw4s37h1wa7qm6mj9vea.png)

-   This should then download the "**hello world**" docker image from **Docker Hub**, create the container locally and output some text to the terminal.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yc56km9fiw6jf4h50sg9.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4940f7ti8b6pfsc9w4u.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jamrz3ypq55iz3shni0b.png)

-   If you look in the output you'll see this message and then a brief explanation of what this just did.

```
Hello from Docker!
This message shows that your installation appears to be working correctly.
```

-   Congratulations, you've successfully set up Docker on your Raspberry Pi. We're finally ready to spin up some applications and services.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExdGxmd2N4NGxwYXgyM3k1bTZqN2g4cmh5OG1lb240dTExam93MTRncyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/lcEktA2AJUqDm/giphy.gif">

Next up, in Get Started with Docker : Part 2b - We'll be looking at installing Docker and Docker Desktop on a Windows machine using WSL.

__

Don't forget to explore the rest of our website as we build out more content. Stay tuned for more tutorials, tips, and tricks to help you make tech work for you.

If you want to stay up-to-date with regular updates, make sure to subscribe to our free mailing list.

___