How to Install Docker on Debian 12: A Step-by-Step Guide

docker hello world

Docker is a powerful platform that simplifies the deployment and management of containerized applications. In this guide, we’ll walk you through the steps required to install Docker on Debian 12.


Prerequisites

  • A system running Debian 12 (Bookworm)
  • A user account with sudo privileges
  • Internet connection to download Docker packages

Step 1: Update Your System

Before installing Docker, it’s essential to update the package index and upgrade existing packages to the latest versions.

  1. Open a terminal and run the following command to update your system:
sudo apt update && sudo apt upgrade -y
  1. Once the update and upgrade are complete, reboot your system if necessary:
sudo reboot

Step 2: Install Required Packages

You’ll need to install some packages that allow apt to use packages over HTTPS.

  1. Run the following command to install the necessary dependencies:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

Step 3: Add Docker’s Official GPG Key

  1. Import Docker’s GPG key using curl:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Step 4: Add Docker’s Official APT Repository

  1. Add the Docker repository to your sources.list.d directory:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  1. Update the package index to include Docker’s repository:
sudo apt update

Step 5: Install Docker Engine

  1. To install Docker Engine, run the following command:
sudo apt install docker-ce docker-ce-cli containerd.io -y
  1. Once the installation is complete, check the status of the Docker service:
sudo systemctl status docker

You should see that Docker is active and running. To stop or start the service in the future, use:

sudo systemctl start docker
sudo systemctl stop docker

Step 6: Verify Docker Installation

  1. Check the installed version of Docker:
docker --version
  1. Run a test container to ensure Docker is functioning correctly:
sudo docker run hello-world

If everything is set up properly, you’ll see a message from the Docker Engine confirming that the installation is successful.


Step 7: Manage Docker as a Non-Root User (Optional)

By default, the Docker command can only be run by the root user or by a user in the docker group. To avoid using sudo with every Docker command, you can add your user to the docker group.

  1. Add your user to the docker group:
sudo usermod -aG docker $USER
  1. To apply the group changes, either log out and log back in or run:
newgrp docker
  1. Verify that you can run Docker commands without sudo:
docker run hello-world

Step 8: Enable Docker to Start on Boot

  1. To ensure Docker starts automatically at boot, run:
sudo systemctl enable docker

Conclusion

Congratulations! You have successfully installed Docker on your Debian 12 system. You’re now ready to start using Docker to deploy and manage containerized applications. For more information on how to use Docker, refer to the official Docker documentation.

Happy containerizing!

Leave a Reply

Your email address will not be published. Required fields are marked *