How to Install Docker on Debian 12?
Docker is one of the most powerful open-source platforms that facilitates developers to build, ship and run applications in containers. It simplifies software deployment by packaging applications with their dependencies, which promises consistency across systems. If you are using Debian 12, it could work wonders in the development and deployment of your projects.
In this guide, we will take you through the step-by-step method of installing Docker on Debian 12. It does not matter whether you are still a student or a proficient developer; this guide will help you in quickly getting started with the installation of Docker on Debian 12!!
Why Install Docker on Debian 12?
Debian 12 is one of the stable and lightweight Linux distributions and is the perfect choice for running Docker. There are multiple reasons why you may want to install Docker on Debian 12. Let’s examine some of them!
- Easy application deployment: Docker simplifies application deployment using lightweight, portable containers.
- Isolation: This provides independence for each container, thereby isolating applications from potential conflicts.
- Resource efficiency: Containers consume comparatively less resources than virtual machines.
- Cross-platform compatibility: One can very easily run applications on different environments without changing them.
- Scalability: Docker makes it easy to scale applications up or down to meet production workloads.
Now, let’s navigate to the installation process!
Pre-requisites Before Installing Docker
Before installing Docker, we need to ascertain that:
- You have a system that runs Debian 12.
- You have an active user account with sudo privileges.
- You have a proper internet connection.
Step-Wise Guide for Installing Docker on Debian 12
Docker installation on Debian 12 is simple and can be carried out within a few simple steps listed below!
Step 1: System Updations
It is a pre-requisite step to update your system packages to the latest versions before installing Docker.
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
Docker requires certain packages and needs to be installed.
sudo apt install -y ca-certificates curl gnupg
Step 3: Add Docker’s Official GPG Key
Run the following command to add Docker’s GPG key:
sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg | sudo tee /etc/apt/keyrings/docker.asc > /dev/null sudo chmod a+r /etc/apt/keyrings/docker.asc
Step 4: Add Docker repository
To add the Docker repository, make sure that you run the following command.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Install Docker Engine
Ensure that you update the package index and run the command to install Docker.
sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 6: Verify Docker Installation
Verify if Docker is installed and running.
docker --version Docker version 24.0.2, build 1234567
Check the Docker service status.
sudo systemctl status docker
If the docker service is running, it will show output indicating that it is active.
Step 8: Add User to Docker Group (Optional)
Add your user to the Docker group if you want to run Docker commands without using sudo:
sudo usermod -aG docker $USER
To apply these changes, log out and log back in, or run:
newgrp docker
Commands to Manage the Docker system service
Docker runs as a system service and can be managed by using systemctl commands.
To Start the Docker:
sudo systemctl start docker
To Stop the Docker:
sudo systemctl stop docker
To Restart the Docker:
sudo systemctl restart docker
To Check the Docker Status:
sudo systemctl status docker
To Disable the Docker on Startup:
sudo systemctl disable docker
How to Deploy Containerized Applications Using Docker?
After installing the Docker, one can easily deploy containerized applications. For instance, let’s say running an NGINX web server inside a Docker container.
Step 1: Pull the NGINX Image
docker pull nginx
Step 2: Run the NGINX Container
docker run -d -p 8080:80 --name mynginx nginx
Here,
-d runs the container in detached mode.
-p 8080:80 maps port 8080 on the host to port 80 in the container.
–name mynginx names the container “mynginx”.
nginx is the image name.
Step 3: Verify Running Containers
docker ps
You should see an active NGINX container in the output.
Step 4: Access the Application
Open a browser and navigate to http://localhost:8080. You should see the default NGINX welcome page.
Step 5: Stop and Remove the Container
If you no longer need the container, stop and remove it.
docker stop mynginx docker rm mynginx
Conclusion
Docker is easy to install on Debian 12; it will easily help you deploy applications in isolated environments known as containers. With the steps in this guide, you will be able to install Docker and manage its service easily alongside the deployment of containerized applications. As the developer or system admin, you will find it useful to ease your workflows and improve your deployment strategies.
Frequently Asked Questions
How do I check if Docker is running on Debian 12?
Type the following command to verify if the Docker is running on Debian 12,
sudo systemctl status docker
If Docker is up and running, it will show the status as “running”.
Can I install Docker without root privileges?
Docker needs root access, but you can run sudo-less commands if you add your user to the Docker group.
How do I uninstall Docker from Debian 12?
To uninstall Docker from Debian 12, run the following command:
sudo apt remove --purge docker-ce docker-ce-cli containerd.io sudo rm -rf /var/lib/docker
What is the difference between a Docker and a virtual machine?
Docker is lightweight since it shares the host OS kernel in its containerization applications, while a virtual machine starts an entire operating system and takes up more resources.
Can I use Docker Compose on Debian 12?
Yes, Docker Compose is installed as a Netflix plugin together with Docker in this case. You can check its version with:
docker compose version