In this guide, we are going to learn how to install and use Docker on Debian 10 Buster. Docker is a platform that utilizes the OS-level virtualization to provide a way of packaging applications into standardized, isolated and lightweight units called containers complete with all the dependencies and libraries required for their functionality.
Install and Use Docker on Debian 10 Buster
In this tutorial, we are going to learn how to install the Docker Engine – Community on Debian 10.
Update Your System
Update and upgrade your system packages before you can proceed.
sudo apt update
sudo apt upgrade
Install Docker CE Repository
Docker CE is not available on the default Debian 10 Buster repos. Hence, you need to install them so that can be able to install Docker CE.
Run the command below to install the packages required for pulling Docker CE packages over HTTPS.
sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common
Install Docker APT repository signing key.
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Install Docker CE APT repository.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
Run system package update.
sudo apt update
Install Docker CE on Debian 10 Buster
Once you have created the repositories, you can install docker and its required components.
install docker-ce docker-ce-cli containerd.io
Running Docker Service on Debian 10 Buster
After installation, Docker is started and enabled to run on system boot.
systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-08-14 14:11:07 EDT; 22min ago
Main PID: 16977 (dockerd)
└─16977 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
systemctl is-enabled docker
Running Docker as non-root User
By default, docker requires root privileges to run. Hence, if you are running it as an ordinary user with no sudo rights, add that user to docker group.
sudo usermod -aG docker USER
Where USER is your non-privileged user. For example, to add a non-root user called amos to docker group,
sudo usermod -aG docker amos
Next, log out from your system for your new group membership to take effect and login again.
You should now be able to run docker with no 'permission denied while trying to connect to the Docker daemon socket...' errors.
Test Docker installation
Verify that you can run docker without sudo privileges by running a simple Docker image called hello-world.
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
Using Docker on Debian 10 Buster
Docker has a command line interface tool called docker. The command line syntax for docker command is;
docker [OPTIONS] COMMAND
If you run docker with no options nor commands, it displays all the options and command usage.
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
To find more information on a command and its usage, simply run;
docker COMMAND --help
docker build --help
Running Docker Images
While testing our Docker installation above, we ran an image called hello-world. When an image is ran, a container is launched. If the docker image being ran is not available locally, they are pulled from the Docker Hub registry. From Docker hub, you can search and pull and use a Docker container that has been created by the community. Docker Hub is the best place to start Dockering with before you can start to build your own images.
As an example of running a docker image, we are going to learn how to pull, install and run Debian Linux image on our docker.
Search for Docker Image on Docker Hub
Docker Hub has 100,000+ container images from software vendors, open-source projects, and the community. Let us for example search for Debian container image.
docker search debian
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 9821 [OK]
debian Debian is a Linux distribution that's compos… 3187 [OK]
arm32v7/debian Debian is a Linux distribution that's compos… 59
itscaro/debian-ssh debian:jessie 25 [OK]
samueldebruyn/debian-git a minimal docker container with debian and g… 21 [OK]
arm64v8/debian Debian is a Linux distribution that's compos… 20
multiarch/debian-debootstrap multiarch ports of debian-debootstrap 9
i386/debian Debian is a Linux distribution that's compos… 9
To download the Debian container image from the registry, simply run;
docker pull debian
Using default tag: latest
latest: Pulling from library/debian
4ae16bd47783: Pull complete
Status: Downloaded newer image for debian:latest
List Available Docker Images
To list available images, use docker image or docker images ls command.
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
debian latest 85c4fd36a543 19 hours ago 114MB
hello-world latest fce289e99eb9 7 months ago 1.84kB
As you can see, we have two images that we have already pulled from the docker registry.
Running a Docker Container Image
Once you have the Docker container image, you can run it using the docker run command. The syntax for docker run command is;
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
To simply run the Debian container we pulled from the registry, simply execute;
docker run -it debian
The -i and -t options used provides an interactive shell and allocate a pseudo-tty when you run the Debian container image.
You are now inside your Debian container image. You can now run any other task as you would on a virtual machine. For example;
Verify the version of your Debian server;
root@820d3232134b:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
Create Users on your Debian 10 container;
root@f10c8c02e501:/# useradd -m amos
root@f10c8c02e501:/# passwd amos
Retype new password:
passwd: password updated successfully
root@f10c8c02e501:/# usermod -aG sudo amos
To exit your container, just press ctrl+d or exit.
To list all running Docker containers, before you exit a container, open another terminal and execute;
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5afa1afb260 debian "bash" 11 seconds ago Up 10 seconds objective_swirles
The command docker ps is also similar to, docker containers ls.
If you have exited the container, docker ps will not show anything. Therefore, to list all containers including the ones that are not running, simply execute;
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5afa1afb260 debian "bash" 6 minutes ago Exited (0) 5 seconds ago objective_swirles
f10c8c02e501 debian "bash" 13 minutes ago Exited (0) 10 minutes ago cocky_zhukovsky
820d3232134b debian "bash" 21 minutes ago Exited (0) 13 minutes ago charming_heyrovsky
1a960a624a8d hello-world "/hello" About an hour ago Exited (0) About an hour ago goofy_zhukovsky
To start and exited container in an interactive mode, get the container ID or NAME from the docker ps -a command and run;
docker start -i containerID/NAME
To start the container in the background, run the command;
docker start containerID/NAME
To stop the container;
docker stop containerID/NAME
To delete container;
docker rm containerID/NAME
Well, that is just it on our basic guide on how to install and use Docker on Debian 10 Buster.