How To Install and Use Docker on Debian 10 Linux
4 min read
Docker is a containerization platform that allows you to quickly build, test and deploy applications as portable, self-sufficient containers that can virtually run everywhere.
In this tutorial, we’ll explain how to install Docker on Debian 10 Buster and explore the basic Docker concepts and commands.
Install Docker on Debian
Perform the following steps to install the latest stable Docker version from the Docker’s repositories.
Install the packages necessary to add a new repository over HTTPS:
sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2
Import the repository’s GPG key using the following curl command:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
On success, the command will return
Add the stable Docker APT repository to your system’s software repository list:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$(lsb_release -cs)will return the name of the Debian distribution. In this case, that is
aptpackage list and install the latest version of Docker CE (Community Edition):
sudo apt update sudo apt install docker-ce
Once the installation is completed the Docker service will start automatically. To verify it type in:
sudo systemctl status docker
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-07-30 20:52:00 GMT; 1min 11s ago Docs: https://docs.docker.com ...
At the time of writing, the latest stable version of Docker is
Docker version 19.03.1, build 74b1e89
Executing the Docker Command Without Sudo
By default, only root and user with sudo privileges can execute Docker commands.
If you want to execute Docker commands without prepending
sudo you’ll need to add your user to the docker group which is created during the installation of the Docker CE package. To do that, type in:
sudo usermod -aG docker $USER
$USER is an environment variable that holds your username.
Log out and log back in so that the group membership is refreshed.
Once done to verify that you can run
docker commands without
sudo type in:
docker container run hello-world
The command will download a test image, run it in a container, print a “Hello from Docker” message and exit. The output should look like the following:
Now that you have installed on your Debian 10, let’s go over the basic docker concepts and commands.
A Docker image is made up of a series of filesystem layers representing instructions in the image’s Dockerfile that make up an executable software application. An image is an immutable binary file including the application and all other dependencies such as libraries, binaries, and instructions necessary for running the application.
Most Docker images are available on Docker Hub. It is a cloud-based registry service which among other functionalities is used for keeping the Docker images either in a public or private repository.
To search for an image from the Docker Hub registry, use the
docker search command. For example, to search for a Debian image, you would type:
docker search debian
An instance of an image is called a container. A container represents a runtime for a single application, process, or service.
It may not be the most appropriate comparison but if you are a programmer you can think of a Docker image as class and Docker container as an instance of a class.
To start, stop, remove and manage a container use the
docker container command. For example, the following command will start a Docker container based on the Debian image. If you don’t have the image locally, it will be downloaded first:
docker container run debian
The Debian container will stop immediately after booting up because it does not have a long-running process and no other command is provided. The container booted up, ran an empty command and then exited.
-it allows you to interact with the container through the command line. To start an interactive container type:
docker container run -it debian /bin/bash
As you can see from the output above once the container is started the command prompt is changed which means that you’re now working from inside the container.
To list active Docker containers, use the following command:
docker container ls
If you don’t have any running containers the output will be empty.
To view both active and inactive containers, pass it the
docker container ls -a
To delete one or more containers just copy the container ID (or IDs) and paste them after the
container rm command:
docker container rm c55680af670c
Installing Docker on Debian 10 is a relatively easy task. Docker is de facto standard for container technology and it is an essential tool for DevOps engineers and their continuous integration and delivery pipeline.
For more information check out the official Docker documentation.
If you have any question, please leave a comment below.