Install Docker CE on Raspberry Pi

Install Docker CE on Raspberry Pi

Docker is an open-source platform designed for developing, testing, and running applications. It enables the packaging and execution of applications within containers - self-contained environments that include all the necessary components for the application to function.

This tutorial shows how to install Docker Community Edition (CE) on Raspberry Pi.

Install Docker CE

Download the GPG key and save it to the specified directory:

sudo wget -qO /etc/apt/keyrings/docker.asc https://download.docker.com/linux/debian/gpg

Add the Docker CE repository:

echo "deb [arch=arm64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(lsb_release -sc) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Install the Docker CE:

sudo apt update
sudo apt install -y docker-ce

By default, Docker can be used by the root user and users with sudo privileges. During installation, a docker group is created. To allow non-root users to use Docker, simply add them to the docker group.

Add the current user to the docker group:

sudo usermod -a -G docker $USER

To apply the changes, log out and log back into your Raspberry Pi. Once reconnected, verify the Docker version:

docker version

Use the following command to check if the Docker service is running:

sudo service docker status

The Docker service can also be stopped, started, or restarted as needed:

sudo service docker stop
sudo service docker start
sudo service docker restart

Testing Docker CE

To verify that Docker was installed successfully, run the hello-world image.

docker run hello-world

This command downloads a test image, runs it in a container, displays a message, and then exits.

Uninstall Docker CE

To completely uninstall Docker CE along with its dependencies, execute the following command:

sudo apt purge --autoremove -y docker-ce

Once it's complete, remove the docker group:

sudo groupdel docker

A network interface, docker0, is created during installation. You can remove it using the following command:

sudo ip link delete docker0

Remove GPG key and repository:

sudo rm -rf /etc/apt/keyrings/docker.asc
sudo rm -rf /etc/apt/sources.list.d/docker.list

You can also delete Docker configurations, images, containers, and other related directories:

sudo rm -rf /etc/docker
sudo rm -rf /var/lib/docker
sudo rm -rf /run/docker
sudo rm -rf /var/run/docker.sock
sudo rm -rf /var/lib/containerd
sudo rm -rf /opt/containerd

Leave a Comment

Cancel reply

Your email address will not be published.