381 words
2 minutes
Installing Docker on Debian
2021-10-21
2025-01-12
An issue with sudo?
Please don’t use the root account

If you configure your server directly as root, don’t forget to remove sudo from each command.
If you set a password for the root account, the sudo command won’t be accepted. Connect directly as root to execute commands.
You can also reinstall your system leaving the root password empty during installation.
sudo will install and work properly.

Installation of dependencies#

Terminal window
sudo apt-get update && sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release

Add the official GPG key#

Terminal window
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Add the stable repo#

Terminal window
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

Install Docker Engine#

Terminal window
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io

O To validate the intervention requests during installation.

Verify our docker installation

Terminal window
sudo docker run hello-world
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.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
TIP

Your installation is successful!

Create an Apache Container#

As an example, we will create an Apache container

Terminal window
docker run -d --name docker-apache -v /var/www/:/usr/local/apache2/htdocs/ -p 3000:80 httpd

Let’s break down the command above:

docker run allows you to launch a container or install it if it doesn’t exist
-d detaches from the container
--name CONTAINER_NAME
-v for “Volume”, path on machine path
-p To specify local_port (http://MACHINE_IP:3000)
httpd the name of the Apache image, could be nginx in case of a nginx installation.

The run command will apply all options to the service installation.

Display Docker Containers#

Terminal window
docker ps

docker ps displays the active containers.

Terminal window
docker -a

docker ps -a displays all containers.

The Docker Hub#

The Docker Hub is like the Android play store.
It allows us to find container installation images, official or not, as well as their documentation.

Home page

Image nginx

Documentation

Installing Docker on Debian
https://xsec.fr/posts/linux/docker/
Author
Xsec
Published at
2021-10-21
License
CC BY-NC-SA 4.0