Raspberry Pi Docker Installation

Docker allows you to build, test, and deploy applications using containers. Each container includes everything the application needs to run. Some advantages include reducing environment-specific bugs, avoiding the need for each container to have its own operating system, and keeping each container isolated.

This guide assumes that your Ubuntu Server is already hardened.

Installation

Before starting, make sure your system is up to date:

Terminal
sudo apt update && sudo apt upgrade -y

Install the required packages:

Terminal
sudo apt install -y \
ca-certificates \
curl \
gnupg \
lsb-release

Install keyrings:

Terminal
sudo install -m 0755 -d /etc/apt/keyrings

Add the Docker GPG key:

Terminal
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Provide read permissions for the Docker security key:

Terminal
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Add the Docker repository:

Terminal
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update packages:

Terminal
sudo apt update

Install Docker Engine:

Terminal
sudo apt install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin

Verify the Docker installation:

Terminal
sudo docker run hello-world

Allow the user to run Docker:

Terminal
sudo usermod -aG docker user-name

Force refresh:

Terminal
newgrp docker

Verify the user can access Docker:

Terminal
docker ps

Enable Docker on boot:

Terminal
sudo systemctl enable docker
sudo systemctl enable containerd

Confirm Docker is active and running:

Terminal
systemctl status docker

Configuration

Enable logging:

Terminal
sudo nano /etc/docker/daemon.json

Add the below:

{
 "log-driver": "json-file",
 "log-opts": {
 "max-size": "10m",
 "max-file": "3"
 }
}

Press CTRL+O to save the file, then press CTRL+X to close.

Restart Docker:

Terminal
sudo systemctl restart docker

Loading...