To deploy, manage, and run the application without any hassle of an operating system, Docker is the best option. An open-source application known as Docker offers containers for managing applications and due to their light-weight, these containers can be used on any OS and machine.
Similar to virtual machines, the containers are used for virtualization but due to their lightweight nature, they are easy to use. In this tutorial, we will go through how to install and use Docker on Debian 12.
What are the Methods to Install Docker on Debian 12?
Docker can be installed on Debian 12 using one of the mentioned methods:
Method 1: Install Docker on Debian 12 Using the Default Repository
Below-mentioned steps should be used to install Docker from the default repository of Debian 12 with an apt package manager.
Step 1: Update the Packages
Update the packages to ensure the installation of Docker from its updated package:
$ sudo apt update
Step 2: Install Docker
Now install the Docker on Debian after updating the packages:
$ sudo apt install docker.io -y
Docker has been installed on Debian 12 using the package from its default repository.
What is the Method to Remove the Docker on Debian 12?
To remove and uninstall the package of Docker, execute the command:
$ sudo apt purge docker.io -y
Method 2: Install Docker on Debian 12 Using the Docker Repositories
Another method of installing Docker is by using its official repository. The advantage of this method is that the latest release of “Docker” is installed on the computer by the next-mentioned steps.
Step 1: Store the Keyrings
First store the keyrings by creating the directory of “keyrings” at /etc/apt/ path:
$ sudo install -m 0755 -d /etc/apt/keyrings
Step 2: Download the GPG Key
Next download the GPG key to the newly created directory using the curl command utility:
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Step 3: Enable the GPG Keys for Execution
Now make the downloaded GPG key executable by running the command:
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
Step 4: Addition of the Docker Repository
In this step, we will add the official repository to the default repository of Debian 12:
$ echo "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
Step 5: Update the Repository
Now update the Debian’s repository:
$ sudo apt update
Step 6: Install Docker on Debian 12
Finally, install Docker on Debian 12:
$ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Step 7: Verify the Installation
To verify the installation of the Docker, display its installed version:
$ docker --version
How to Configure the Docker on Debian 12?
After the successful installation of the Docker on Debian 12, execute the below steps to configure the Docker.
Step 1: Add the Group
To configure the Docker, first create the “docker” group:
$ sudo groupadd docker
Step 2: Add the User
Now add the user to the “docker” group. For example, add the user “john” to the “docker” group:
$ sudo usermod -aG docker john
Step 3: Start the Docker
After adding the user to the “docker” group, start the docker:
$ sudo systemctl start docker
Step 4: Enable the Docker
Enable the docker with the execution of the command:
$ sudo systemctl enable docker
Step 5: Display the Status
After starting and enabling the “Docker”, confirm its status:
$ sudo systemctl status docker
How to Use Docker on Debian 12?
The basic usage of the docker has been explained with commands in the next section.
Run Docker:
To run the new containers, use the “docker run” command, for example, run the “hello-world” container:
$ sudo docker run hello-world
Display Running Containers:
Use the command for displaying the running containers:
$ sudo docker ps
Display all the Container:
Run the command to display both, running and not running containers:
$ sudo docker ps -a
Display the Docker Images:
To display the docker images that are available on the machine:
$ sudo docker images
Download Docker Image:
To download the docker images from the Docker hub to the local machine, use the pull command, for example, download the docker image of Ubuntu’s latest version:
$ sudo docker pull ubuntu
Stop Container:
To stop the running container, run the command:
$ sudo docker stop [container name]
Start Container:
To start the stopped container again, execute the command:
$ sudo docker start [container name]
Restart the Container:
If the container is supposed to be restarted:
$ sudo docker restart [container name]
Remove Docker Image:
If the docker image is supposed to be removed, then use the command:
$ sudo docker rm [container name]
This is all about the installation and usage of Docker on Debian 12.
Conclusion
After updating Debian packages, execute the command “sudo apt install docker.io -y” to install Docker on Debian 12. Also, docker can be installed by adding its official repository from its website. This post explains both the installation method of Docker on Debian 12 and its basic configuration. The basic usage of Docker has also been explained with its commands.