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:
sudo apt update && sudo apt upgrade -y
Install the required packages:
sudo apt install -y \
ca-certificates \
curl \
gnupg \
lsb-release
Install keyrings:
sudo install -m 0755 -d /etc/apt/keyrings
Add the Docker GPG key:
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:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Add the Docker repository:
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:
sudo apt update
Install Docker Engine:
sudo apt install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
Verify the Docker installation:
sudo docker run hello-world
Allow the user to run Docker:
sudo usermod -aG docker user-name
Force refresh:
newgrp docker
Verify the user can access Docker:
docker ps
Enable Docker on boot:
sudo systemctl enable docker
sudo systemctl enable containerd
Confirm Docker is active and running:
systemctl status docker
Configuration
Enable logging:
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:
sudo systemctl restart docker