Looking for a simple tutorial on how to install Docker on Debian 12? This is it!
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.
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.
In this tutorial, you’ll install and use Docker Community Edition (CE) on Debian 12.
Prerequisites for Installing Docker on Debian 12
- Basic knowledge of the Linux command line.
- An Debian 12 server with a non-root user with
sudo
privileges. You can get affordable, and powerful Debian servers from our website, and you can check out our How to access your server using SSH guide to learn how to access your server and create asudo
user.
Updating the Package Cache and Required Packages
Start by updating the packages in the package manager cache to the latest available versions using the following command:
sudo apt update
Next install a few packages that will allow us to use apt
with HTTPS
in order to add the official docker repository and get the latest version of Docker. To do this, run the following command:
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
Installing Docker
We will use the official Docker repository to install the latest version of Docker.
First, add the GPG key for the official Docker repository to your Debian 12 system:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Next add the official Docker repository to your APT sources:
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
Update your package index:
sudo apt update
Now, with the repository added, install the docker-ce
package, which is the Docker Community Edition package:
sudo apt install docker-ce
Once the installation finishes, check that Docker is running:
sudo systemctl status docker
You should receive output indicating that Docker is active and running, similar to the following:
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-02-18 15:19:06 UTC; 1min 22s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 37609 (dockerd)
Tasks: 9
Memory: 28.9M
CPU: 634ms
CGroup: /system.slice/docker.service
└─37609 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Using Docker
With docker installed, you can now use it to manage Docker images.
To see all available docker subcommands, run the following command:
docker
You should receive a list of docker subcommands and a brief description for each one.
You can use the syntax docker COMMAND --help
to get more information on a specific subcommand. For example, to get more information on the docker rm
command, you can use the --help
flag as follows:
docker rm --help
You should receive output similar to the following:
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Options:
-f, --force Force the removal of a running container (uses SIGKILL)
-l, --link Remove the specified link
-v, --volumes Remove anonymous volumes associated with the container
To view general information on your Docker installation, use docker info
like so:
sudo docker info
This will show you information on your Docker configuration and server properties.
Downloading a Docker Image from Docker Hub
Docker Hub 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.
To test whether you can access Docker Hub, run the hello-world
image:
sudo docker run hello-world
You should receive an output that shows that your installation is working correctly:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:c77be1d3a47d0caf71a82dd893ee61ce01f32fc758031a6ec4cf1389248bb833
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
You can use the docker search
command to search for images hosted on Docker Hub like so:
sudo docker search ubuntu
Here, you search for the Ubuntu image. You should see a list of results like so:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 15357 [OK]
websphere-liberty WebSphere Liberty multi-architecture images … 290 [OK]
ubuntu-upstart DEPRECATED, as is Upstart (find other proces… 112 [OK]
neurodebian NeuroDebian provides neuroscience research s… 97 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 71
...
Images that are officially maintained and supported are labeled as [OK]
under the OFFICIAL
column.
In the results above, you see that ubuntu
is the name of the official Ubuntu image. You can download it using the docker pull
command like so:
sudo docker pull ubuntu
You should receive the following output:
Using default tag: latest
latest: Pulling from library/ubuntu
6e3729cf69e0: Pull complete
Digest: sha256:27cb6e6ccef575a4698b66f5de06c7ecd61589132d5a91d098f7f3f9285415a9
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
You can list the images you've downloaded so far using the following command:
sudo docker images
You should see ubuntu
and hello-world
like so:
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 6b7dfa7e8fdb 9 days ago 77.8MB
hello-world latest feb5d9fea6a5 15 months ago 13.3kB
The reason the image hello-world
was downloaded, is that the docker run
command either runs a container using an image if it has been downloaded, or downloads the image and then runs a container using it.
Running a Docker Container
Docker containers can be run to perform a task in an isolated environment, just like running the hello-world
container performs the task of printing a message. However, containers can also be interactive.
For example, you can run a container using the Ubuntu image you've downloaded previously with an interactive shell using the docker run
and the -it
switches:
sudo docker run -it ubuntu
Your prompt should now be a root shell like so:
root@242d22e1d9da:/#
This is the root user of your Ubuntu container, and you can now manage it just like a virtual machine.
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 apt update
like so:
root@242d22e1d9da:/# apt update
And you can also install any application or package using apt install
. For example, you can install Python 3 like so:
root@242d22e1d9da:/# apt install python3
Once the installation finishes, you can run python like so:
root@242d22e1d9da:/# python3
This should allow you to access the Python REPL inside your Ubuntu container:
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
With this, you can run programs and modify your container in an environment that is isolated from the rest of your server.
Congrats
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.
Check out the Docker guides for more information on Docker.
A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.
If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.