Docker is a well-liked and open-source framework that is universally used to develop, run, and ship applications and software in a containerized environment. In a containerized environment, the applications are encapsulated in containers along with required dependencies, packages, and source code. These containers are platform-independent and can be executed and shipped on any system such as Windows, MacOS, Debian, Ubuntu, and so on.
This blog will demonstrate:
- How to Install Docker on Debian 12?
- How to Add Docker to User Group in Debian?
- Bonus Tip: Uninstall Docker From Debian 12
- Conclusion
How to Install Docker on Debian 12?
Debian is a well-known Linux distribution that consists of free and open-source software and packages. To install Docker on Debian, users are required to have a 64-bit OS of any Debian version such as Debian 12 (Bookworm). To install the Docker on Debian 12, go through the following illustration.
Step 1: Launch “Software & Updates” App
First, launch the “Activity” menu of Debian through the “Window/Super +A” shortcut key. After that, open the “Software & Updates” settings:
Step 2: Enable Search and Download From Internet Options
Mark all the below-highlighted checkboxes under the “Debian Software” menu. Next, choose the “Main server” option from the “Download from” dropdown menu:
Step 3: Launch Debian Terminal
Next, again open the Activity menu and launch the Debian terminal. Users can also use the “CTRL+ALT+T” shortcut key to launch the terminal:
Step 4: Update APT Repository
Next, update the APT official linux repository using the below command:
Step 5: Install Required Dependencies
Install all the required dependencies such as curl and gnupg through the “sudo apt-get install” command:
Step 6: Download Docker GPG Key
Create a new folder, and set the permissions as “0755” code which means this file or folder is executable and readable by others but writable by the user only. For this purpose, run the below command:
Now, download the gpg key for Docker and overwrite it in the “/etc/apt/keyrings/” directory using the “-o” option:
Step 7: Change the File Permissions
Next, change the gpg file permissions using the “sudo chmod” command. In the below command, “a” is used to grant permission to all users, and “r” is used to make the file readable:
Step 8: Add Repository to APT Source
Add the updated repository along with the gpg key to the official APT source with the help of the given command:
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Now, again execute the “sudo apt-get update” command to update the APT repository:
Step 9: Install Docker, Docker Compose, Buildx Plugin
Install the Docker along with other essential components such as Docker cli, containerd, buildx plugin, and docker compose:
The below output confirms that all the above-mentioned components are installed successfully on Debian 12:
Step 10: Check Docker Status
Now, check whether the Docker is running or active on Debian or not using the “systemctl” command:
Step 11: Run Docker
For verification, fire up the first Docker container by executing “hello-world” Docker image:
The below output shows that we have successfully started the Docker container on Debian:
How to Add Docker to User Group in Debian?
In Linux, all docker commands are executable with sudo rights and if users execute them directly without root privileges, they may encounter a “permission denied” error as shown below:
To resolve the stated error, users are required to add Docker to the root user group. To do so, follow the below instructions.
Step 1: Add Docker to the User Group
To add Docker to the user group, utilize the below command. Here, the “-aG” option is used to append and add the user to supplementary groups:
After adding the “docker” user to supplemental groups, reboot the system to implement the changes.
Step 2: User Docker Command Without Sudo Privileges
Now, execute any Docker command without sudo privileges. The below command is used to list down the running containers:
The output shows that we have successfully executed the “docker ps” command without root privileges:
Bonus Tip: Uninstall Docker From Debian 12
Sometimes, users are required to uninstall Docker from Debian for different reasons such as to install the latest or stable version of Docker. For this purpose, follow the below instructions and uninstall Docker completely from the Debian system.
Step 1: Uninstall Docker Installed Packages
The “sudo apt-get purge” command is utilized to remove programs along with configuration files. To completely remove Docker from the system, utilize the given command.
The above command will remove Docker, Docker CLI, Buildx plugin and Docker compose:
The below output shows that we have successfully removed the Docker from Debian:
Step 2: Remove Stored Containers, Images, and Volumes
Now, remove the directories where Docker images, volume, and containers are stored using the “rm -rf” command:
Remove the “containerd” directory that is used to manage the lifecycle of containers and images through Docker daemon as the host system:
That is all about installing and removing the Docker on Debian 12.
Conclusion
To install the Docker on Debian, first, download the Docker official gpg key. After that, add it to the APT source repository. Now, install the Docker and other essential components through the “sudo apt install” command. In order to run the Docker commands without root privileges, add the “docker” to the root user group using the “sudo usermod -aG” command. This blog has illustrated the procedure to install Docker on Debian 12.