\section{How to Install Docker on Debian 12 (Bookworm)\protect\footnote{https://linuxiac.com/how-to-install-docker-on-debian-12-bookworm/}}

\textbf{Learn step-by-step how to install Docker on Debian 12 and unlock the power of containerization. Get started
with our comprehensive guide.}

Docker has revolutionized software development and deployment, providing a lightweight and efficient containerization
solution.

In this article, we’ll walk you through the step-by-step process of installing Docker on Debian 12 (Bookworm),
empowering you to take advantage of its powerful features.

Whether you’re a beginner or an experienced user, our easy-to-follow instructions will ensure a smooth installation. So
let’s dive in!

\subsection{Installing Docker on Debian 12}
There are several ways you can install Docker on your Debian 12 system. It is available in the official Debian
repositories, where it can be easily installed with a single APT command. However, one disadvantage to this approach is
that the version available is not always the most recent.

For this reason, I will show you how to install Docker on Debian 12 from the official Docker repository. This approach
guarantees you always get the latest up-to-date version and will automatically receive all future software updates as
they become available. So, let’s get started.

\subsubsection{Step 1: Install Prerequisites}
First, run the two commands below to update the package index and install the prerequisite necessary to add and use a
new HTTPS repository.

\begin{verbatim}
# apt update
# apt install apt-transport-https ca-certificates curl gnupg
\end{verbatim}

\subsubsection{Step 2: Add Docker’s GPG Repo Key}
Next, import the Docker GPG repository key to your Debian system. This security feature ensures that the software
you’re installing is authentic.

\begin{verbatim}
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
\end{verbatim}

Notice that the command produces no output.


\subsubsection{Step 3: Add the Docker Repo to Debian 12}
After importing the GPG keys, we’ll add the official Docker repository to our Debian 12 system. This implies that the
update package will be made available with the rest of your system’s regular updates if a new version is released.

\begin{verbatim}
# echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] \
https://download.docker.com/linux/debian bookworm stable" | \
    tee /etc/apt/sources.list.d/docker.list > /dev/null
\end{verbatim}

As with the previous command, its execution produces no output.

Next, refresh the package list.

\begin{verbatim}
# apt update
\end{verbatim}

As you can see, our new Docker repository is now available and ready to be used.

\subsubsection{Step 4: Install Docker on Debian 12 (Bookworm)}
To install the latest up-to-date Docker release on Debian, run the below command.

\begin{verbatim}
# apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin
\end{verbatim}

This installs the following Docker components:

\begin{itemize}
	\item docker-ce: The Docker engine itself.\\
	\item docker-ce-cli: A command line tool that lets you talk to the Docker daemon.
	\item containerd.io: A container runtime that manages the container’s lifecycle.
	\item docker-buildx-plugin: A CLI plugin that extends the Docker build with many new features.
\end{itemize}

That’s all! Docker should now be installed; the service started and enabled to start automatically on boot.

In addition, you can check the Docker service status using the following:

\begin{verbatim}
# systemctl is-active docker
\end{verbatim}

\subsubsection{Step 5: Verify the Docker Installation}
Now let’s check if everything with our new Docker installation works properly. For this purpose, we will run a simple application called \emph{"hello-world"}.

\begin{verbatim}
# docker run hello-world
\end{verbatim}

Congratulations! As we can see, everything works as expected!

\subsection{Enabling Non-root Users to Run Docker Commands}
So far, we have successfully installed Docker on your Debian 12 system.

However, only root and users with sudo privileges can execute Docker commands by default. In other words, if you
attempt to run the \verb|docker| command without prefixing it with \verb|sudo|, you’ll get an error message like this:

\begin{verbatim}
$ docker ps
permission denied while trying to connect to the Docker daemon socket at
unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json":
dial unix /var/run/docker.sock: connect: permission denied
\end{verbatim}

So, to run Docker commands as a non-root user, you must add your user to the “docker” group. To do that, type in the
following:

\begin{verbatim}
# usermod -aG docker ${USER}
\end{verbatim}

In the above command, \verb|${USER}| is an environment variable that holds your username. To apply for the new group
membership, reboot your Debian system.

You can then execute Docker commands without prefixing them with \verb|sudo|.

\begin{verbatim}
$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
\end{verbatim}

\subsection{Conclusion}
hroughout this article, we have explored the step-by-step process of installing Docker on Debian 12 (Bookworm).

It is worth noting that Docker is continuously evolving, with new features, improvements, and updates being introduced
regularly. As such, it is recommended to stay up to date with the latest releases and security patches to ensure a
smooth and secure Docker experience.

To learn more about Docker, check out the official Docker documentation. Additionally, we recommend our detailed guide
to expand your skills with Docker and learn how to run and manage multi-container applications using Docker Compose.
Happy dockering!
