Step 2: Install docker on Raspberry pi

Step 2: Install docker on Raspberry pi
Photo by Ian Taylor / Unsplash

For your new setup, it's recommended to use a Raspberry Pi 4. Begin by downloading the Raspberry Pi Imager from the official website. Follow the process to replace all the settings as per the guidelines provided.

It's crucial to select a strong password and to replace the default username on your Raspberry Pi to ensure your system's security.

Raspberry Pi OS – Raspberry Pi
From industries large and small, to the kitchen table tinkerer, to the classroom coder, we make computing accessible and affordable for everybody.

Download Raspberry pi Imager

It's also advisable to enable SSH and opt for password authentication for convenience. These settings can be modified at a later time.

Static ip address

It's essential to set a static IP address for your Raspberry Pi to ensure consistent access. This is particularly important for services that require a constant connection to a specific IP address; otherwise, they may fail to connect.

To establish this, first determine the IP address assigned to your Raspberry Pi by your router.

Then, initiate an SSH connection through the terminal using the following command, substituting "yourUsername" with your actual username and "192.168.1.5" with the IP address you've identified:

ssh yourUsername@192.168.1.5

After entering your password, you'll have access to your system. To configure a static IP address for your Raspberry Pi, you'll need to modify the dhcpcd.conf file. With the assumption that your router and DNS server address is 192.168.1.1, follow these steps to set a static IP:

sudo nano /etc/dhcpcd.conf

Copy and paste the following configuration into the dhcpcd.conf file:

interface eth0
static ip_address=192.168.1.5/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

This configuration sets the static IP address of your Raspberry Pi to 192.168.1.5, with 192.168.1.1 as both the gateway (router) and DNS server address.

After applying the changes, reboot your system to ensure the new settings take effect. You can do this by executing the following command in the terminal:

sudo reboot

Now let's dive into the exciting part: setting up Docker on your Raspberry Pi.

1) Update Your Raspberry Pi:

Begin by updating your Raspberry Pi to ensure all your system's packages are up to date. Execute the following commands in the terminal:

sudo apt-get update && sudo apt-get upgrade
sudo reboot

This process updates the package lists, upgrades any outdated packages, and then reboots the system to apply all changes.

2) Install Docker.

Use the following commands to download and run the Docker installation script:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

This script automatically installs Docker on your Raspberry Pi.

3) Optional: Adding a User to the Docker Group:

If you prefer not to use the root user for Docker commands, you can add a non-root user to the Docker group. First, create a new user (if you haven't already), then add this user to the Docker group with the following command, replacing newlyCreatedUser with your new user's username:

sudo usermod -aG docker newlyCreatedUser

This step allows the specified user to execute Docker commands without needing root privileges. Remember to log in with the new user to apply these changes.

4) Verify Docker Installation:

To ensure Docker is installed and running correctly on your Raspberry Pi, execute the following command:

docker run hello-world

This command downloads a test image and runs it in a container. If Docker is set up properly, you will see a message that includes "Hello from Docker!" This confirms that Docker is functioning correctly on your system.