{"id":7502,"date":"2024-05-16T09:49:38","date_gmt":"2024-05-16T09:49:38","guid":{"rendered":"https:\/\/blog.ssdnodes.com\/blog\/?p=7502"},"modified":"2025-07-16T14:18:55","modified_gmt":"2025-07-16T14:18:55","slug":"how-to-install-and-use-docker-on-debian-12","status":"publish","type":"post","link":"https:\/\/www.ssdnodes.com\/blog\/how-to-install-and-use-docker-on-debian-12\/","title":{"rendered":"How To Install and Use Docker on Debian 12"},"content":{"rendered":"<p>Looking for a simple tutorial on how to install Docker on Debian 12? This is it!<\/p>\n<p>Docker is an open-source platform for developing, shipping, and running applications. It is designed to make it easier to create, deploy, and run applications by using containers. With Docker, developers can package their applications into standardized units called containers, which can then be run on any computer, regardless of the operating system or hardware.<\/p>\n<p>Docker allows developers to quickly and easily deploy their applications in a consistent environment, without having to worry about the underlying infrastructure. Docker also provides a rich set of tools and services for managing and monitoring applications, as well as for building and sharing images with other developers. Docker is an essential tool for modern software development, and it is used by many of the world's leading companies.<\/p>\n<p>In this tutorial, you\u2019ll install and use Docker Community Edition (CE) on Debian 12.<\/p>\n<h2>Prerequisites for Installing Docker on Debian 12<\/h2>\n<ul>\n<li>Basic knowledge of the Linux command line.<\/li>\n<li>An Debian 12 server with a non-root user with <code>sudo<\/code> privileges. You can get affordable, and powerful Debian servers from <a href=\"https:\/\/www.ssdnodes.com\/\">our website<\/a>, and you can check out our <a href=\"https:\/\/www.ssdnodes.com\/blog\/tutorial-setting-up-and-securing-ssh-based-authentication\/\">How to access your server using SSH<\/a> guide to learn how to access your server and create a <code>sudo<\/code> user.<\/li>\n<\/ul>\n<h1>Updating the Package Cache and Required Packages<\/h1>\n<p>Start by updating the packages in the package manager cache to the latest available versions using the following command:<\/p>\n<pre><code>sudo apt update<\/code><\/pre>\n<p>Next install a few packages that will allow us to use <code>apt<\/code> with <code>HTTPS<\/code> in order to add the official docker repository and get the latest version of Docker. To do this, run the following command:<\/p>\n<pre><code>sudo apt -y install apt-transport-https ca-certificates curl software-properties-common<\/code><\/pre>\n<h1>Installing Docker<\/h1>\n<p>We will use the official Docker repository to install the latest version of Docker.<\/p>\n<p>First, add the GPG key for the official Docker repository to your Debian 12 system:<\/p>\n<pre><code>curl -fsSL https:\/\/download.docker.com\/linux\/debian\/gpg | sudo gpg --dearmor -o \/usr\/share\/keyrings\/docker-archive-keyring.gpg<\/code><\/pre>\n<p>Next add the official Docker repository to your APT sources:<\/p>\n<pre><code>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 &gt; \/dev\/null<\/code><\/pre>\n<p>Update your package index:<\/p>\n<pre><code>sudo apt update<\/code><\/pre>\n<p>Now, with the repository added, install the <code>docker-ce<\/code> package, which is the Docker Community Edition package:<\/p>\n<pre><code>sudo apt install docker-ce<\/code><\/pre>\n<p>Once the installation finishes, check that Docker is running:<\/p>\n<pre><code>sudo systemctl status docker<\/code><\/pre>\n<p>You should receive output indicating that Docker is active and running, similar to the following:<\/p>\n<pre><code>\u25cf docker.service - Docker Application Container Engine\r\n     Loaded: loaded (\/lib\/systemd\/system\/docker.service; enabled; vendor preset: enabled)\r\n     Active: active (running) since Sat 2023-02-18 15:19:06 UTC; 1min 22s ago\r\nTriggeredBy: \u25cf docker.socket\r\n       Docs: https:\/\/docs.docker.com\r\n   Main PID: 37609 (dockerd)\r\n      Tasks: 9\r\n     Memory: 28.9M\r\n        CPU: 634ms\r\n     CGroup: \/system.slice\/docker.service\r\n             \u2514\u250037609 \/usr\/bin\/dockerd -H fd:\/\/ --containerd=\/run\/containerd\/containerd.sock<\/code><\/pre>\n<h1>Using Docker<\/h1>\n<p>With docker installed, you can now use it to manage Docker images.<\/p>\n<p>To see all available docker subcommands, run the following command:<\/p>\n<pre><code>docker<\/code><\/pre>\n<p>You should receive a list of docker subcommands and a brief description for each one.<\/p>\n<p>You can use the syntax <code>docker COMMAND --help<\/code> to get more information on a specific subcommand. For example, to get more information on the <code>docker rm<\/code> command, you can use the <code>--help<\/code> flag as follows:<\/p>\n<pre><code>docker rm --help<\/code><\/pre>\n<p>You should receive output similar to the following:<\/p>\n<pre><code>Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]\r\n\r\nRemove one or more containers\r\n\r\nOptions:\r\n  -f, --force     Force the removal of a running container (uses SIGKILL)\r\n  -l, --link      Remove the specified link\r\n  -v, --volumes   Remove anonymous volumes associated with the container<\/code><\/pre>\n<p>To view general information on your Docker installation, use <code>docker info<\/code> like so:<\/p>\n<pre><code>sudo docker info<\/code><\/pre>\n<p>This will show you information on your Docker configuration and server properties.<\/p>\n<h1>Downloading a Docker Image from Docker Hub<\/h1>\n<p><a href=\"https:\/\/hub.docker.com\/\" target=\"_blank\" rel=\"noopener\">Docker Hub<\/a> is a cloud-based service that provides a centralized repository for Docker images. It allows users to store, manage, and share Docker images with other users. It provides a secure and reliable way to share and store Docker images, which can be used to create and deploy applications. Docker Hub also provides a wide range of services, such as private repositories, automated builds, and integration with other services.<\/p>\n<p>To test whether you can access Docker Hub, run the <code>hello-world<\/code> image:<\/p>\n<pre><code>sudo docker run hello-world<\/code><\/pre>\n<p>You should receive an output that shows that your installation is working correctly:<\/p>\n<pre><code>Unable to find image 'hello-world:latest' locally\r\nlatest: Pulling from library\/hello-world\r\n2db29710123e: Pull complete \r\nDigest: sha256:c77be1d3a47d0caf71a82dd893ee61ce01f32fc758031a6ec4cf1389248bb833\r\nStatus: Downloaded newer image for hello-world:latest\r\n\r\nHello from Docker!\r\nThis message shows that your installation appears to be working correctly.<\/code><\/pre>\n<p>You can use the <code>docker search<\/code> command to search for images hosted on Docker Hub like so:<\/p>\n<pre><code>sudo docker search ubuntu<\/code><\/pre>\n<p>Here, you search for the Ubuntu image. You should see a list of results like so:<\/p>\n<pre><code>NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED\r\nubuntu                           Ubuntu is a Debian-based Linux operating sys\u2026   15357     [OK]       \r\nwebsphere-liberty                WebSphere Liberty multi-architecture images \u2026   290       [OK]       \r\nubuntu-upstart                   DEPRECATED, as is Upstart (find other proces\u2026   112       [OK]       \r\nneurodebian                      NeuroDebian provides neuroscience research s\u2026   97        [OK]       \r\nubuntu\/nginx                     Nginx, a high-performance reverse proxy &amp; we\u2026   71                   \r\n\r\n...<\/code><\/pre>\n<p>Images that are officially maintained and supported are labeled as <code>[OK]<\/code> under the <code>OFFICIAL<\/code> column.<\/p>\n<p>In the results above, you see that <code>ubuntu<\/code> is the name of the official Ubuntu image. You can download it using the <code>docker pull<\/code> command like so:<\/p>\n<pre><code>sudo docker pull ubuntu<\/code><\/pre>\n<p>You should receive the following output:<\/p>\n<pre><code>Using default tag: latest\r\nlatest: Pulling from library\/ubuntu\r\n6e3729cf69e0: Pull complete \r\nDigest: sha256:27cb6e6ccef575a4698b66f5de06c7ecd61589132d5a91d098f7f3f9285415a9\r\nStatus: Downloaded newer image for ubuntu:latest\r\ndocker.io\/library\/ubuntu:latest<\/code><\/pre>\n<p>You can list the images you've downloaded so far using the following command:<\/p>\n<pre><code>sudo docker images<\/code><\/pre>\n<p>You should see <code>ubuntu<\/code> and <code>hello-world<\/code> like so:<\/p>\n<pre><code>REPOSITORY    TAG       IMAGE ID       CREATED         SIZE\r\nubuntu        latest    6b7dfa7e8fdb   9 days ago      77.8MB\r\nhello-world   latest    feb5d9fea6a5   15 months ago   13.3kB<\/code><\/pre>\n<p>The reason the image <code>hello-world<\/code> was downloaded, is that the <code>docker run<\/code> command either runs a container using an image if it has been downloaded, or downloads the image and then runs a container using it.<\/p>\n<h1>Running a Docker Container<\/h1>\n<p>Docker containers can be run to perform a task in an isolated environment, just like running the <code>hello-world<\/code> container performs the task of printing a message. However, containers can also be interactive.<\/p>\n<p>For example, you can run a container using the Ubuntu image you've downloaded previously with an interactive shell using the <code>docker run<\/code> and the <code>-it<\/code> switches:<\/p>\n<pre><code>sudo docker run -it ubuntu<\/code><\/pre>\n<p>Your prompt should now be a root shell like so:<\/p>\n<pre><code>root@242d22e1d9da:\/#<\/code><\/pre>\n<p>This is the root user of your Ubuntu container, and you can now manage it just like a virtual machine.<\/p>\n<p>With this shell prompt, you can run any command inside your Ubuntu container. For example, you can update the package index inside the container using <code>apt update<\/code> like so:<\/p>\n<pre><code>root@242d22e1d9da:\/# apt update<\/code><\/pre>\n<p>And you can also install any application or package using <code>apt install<\/code>. For example, you can install Python 3 like so:<\/p>\n<pre><code>root@242d22e1d9da:\/# apt install python3<\/code><\/pre>\n<p>Once the installation finishes, you can run python like so:<\/p>\n<pre><code>root@242d22e1d9da:\/# python3<\/code><\/pre>\n<p>This should allow you to access the Python REPL inside your Ubuntu container:<\/p>\n<pre><code>Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n&gt;&gt;&gt;<\/code><\/pre>\n<p>With this, you can run programs and modify your container in an environment that is isolated from the rest of your server.<\/p>\n<h1>Congrats<\/h1>\n<p>You now have Docker installed on your system, and you've learned how to search for Docker images in the official Docker Hub, how to download an image, and how to use it for a container. You then learned how to run the container's shell and how to manage its packages and how to install programs on it.<\/p>\n<p>Check out the <a href=\"https:\/\/docs.docker.com\/go\/guides\/\" target=\"_blank\" rel=\"noopener\">Docker guides<\/a> for more information on Docker.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Master Docker installation, image management, and container operations on Debian 11! Simplify application development, deployment, and management with our guide.<\/p>\n","protected":false},"author":19,"featured_media":9147,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[18,30],"tags":[],"class_list":["post-7502","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-tutorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/7502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/comments?post=7502"}],"version-history":[{"count":8,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/7502\/revisions"}],"predecessor-version":[{"id":13484,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/7502\/revisions\/13484"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media\/9147"}],"wp:attachment":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media?parent=7502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/categories?post=7502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/tags?post=7502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}