Step-by-Step Guide to Managing and Uninstalling Docker on Raspberry Pi
Table Of Contents
- Table Of Contents
- Introduction
- Check Installed Docker Packages
- Remove Docker Packages
- Remove All Docker-Related Data
- Deactivate Docker Network Interface and Ethernet Bridge
- Conclusion
Introduction
Docker is a lightweight containerization platform that works exceptionally well on devices like the Raspberry Pi. However, there may be situations where you need to identify installed Docker packages, completely remove them, or clean up associated resources.
This guide is tailored for Raspberry Pi users and provides a comprehensive approach to:
- Checking installed Docker packages on your Raspberry Pi.
- Fully removing Docker and its related packages.
- Cleaning up residual data, such as images, containers, and volumes.
- Deactivating Docker-related network interfaces.
Whether you’re troubleshooting, performing a clean uninstall, or switching to a different container solution, these steps will ensure no traces of Docker remain on your Raspberry Pi.
Check Installed Docker Packages
Command
dpkg -l | grep -i docker
Possible Results
You may encounter any combination of the following packages:
dockerdocker-cedocker-composedocker-docdocker-enginedocker.iopodman-docker
Remove Docker Packages
Commands
To completely remove Docker packages from your Raspberry Pi, use the following commands:
apt-get purge
apt-get autoremove
Execution Methods
You can execute these commands in the following ways:
- Sequential Execution for Each Package
apt-get purge -y <package-name>... apt-get autoremove -y <package-name>... - Single Command for Multiple Packages
apt-get purge -y <packageA-name> <packageB-name> <packageC-name>... apt-get autoremove -y <packageA-name> <packageB-name> <packageC-name>... - Using a For-Loop
for pkg in <packageA-name> <packageB-name> <packageC-name>...; do apt-get purge -y $pkg apt-get autoremove -y $pkg done
Additional Notes
1. Recommended Packages to Remove
The official Docker documentation for Raspberry Pi OS suggests removing the following packages to completely clean up Docker installations:
containerdrunc
2. Use of sudo
If you are not logged in as a root user on your Raspberry Pi, prepend all commands with sudo. For example:
sudo apt-get purge -y <package-name>
3. Difference Between remove and purge
The Docker documentation suggests using apt-get remove. However, it is preferable to use apt-get purge in combination with apt-get autoremove as this ensures removal of both the package and its associated system-wide configuration files.
Remove All Docker-Related Data
To remove Docker-related images, containers, volumes, and configurations from your Raspberry Pi, execute the following commands:
sudo umount /var/lib/docker/
sudo rm -rf /var/lib/docker
sudo rm -rf /etc/docker
sudo rm /etc/apparmor.d/docker
sudo rm -rf /var/lib/containerd
sudo rm -rf /var/run/docker.sock
sudo rm -rf /usr/bin/docker-compose
sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /etc/apt/keyrings/docker.asc
sudo groupdel docker
Deactivate Docker Network Interface and Ethernet Bridge
Disable docker0 Network Interface
To deactivate the docker0 network interface on your Raspberry Pi, run:
sudo ifconfig docker0 down
Delete the docker0 Ethernet Bridge
To remove the docker0 Ethernet bridge, run:
sudo ip link delete docker0
Conclusion
By following the steps outlined in this guide, you can thoroughly identify, remove, and clean up all Docker-related packages, configurations, and data from your Raspberry Pi. This ensures no residual files or configurations are left behind, which is essential for troubleshooting, fresh installations, or switching to alternative containerization tools.
Key Considerations for Raspberry Pi Users:
- Ensure your Raspberry Pi user has adequate administrative privileges for these commands (
sudomay be required). - Be cautious about other applications that may depend on Docker before proceeding with the removal.
For further assistance, refer to the official Docker documentation for Raspberry Pi OS or consult the Docker community forums.