Installing Docker on Debian 10

29/12/2020
In this article, I am going to show you how to install the latest Docker CE (Community Edition) on Debian 10 Buster. So, let’s get started.

Installing Required Dependencies:

First, you have to install some dependency packages on Debian 10. All of these packages are available in the official package repository of Debian 10.

Now, update the APT package repository cache with the following command:

$ sudo apt update

The APT package repository cache should be updated.

Now, install all the required packages with the following command:

$ sudo apt install apt-transport-https ca-certificates curl
gnupg2 software-properties-common

Now, press Y and then press <Enter> to confirm the installation.

All the required dependency packages should be installed.

Adding Docker Package Repository:

Now, Docker uses HTTPS protocol to serve the Docker packages over the internet. So, you must add the GPG key of the Docker package repository in order to use it.

$ curl -fsSL https://download.docker.com/linux/debian/gpg
| sudo apt-key add

The GPG key should be added.

Now, run the following command to add the Docker package repository to your Debian 10 machine.

$ echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs)
stable"
| sudo tee /etc/apt/sources.list.d/docker-ce.list

The Docker package repository should be added.

Now, update the APT package repository cache with the following command:

$ sudo apt update

APT package repository cache should be added.

Installing Docker:

Now, install Docker CE with the following command:

$ sudo apt install docker-ce docker-ce-cli containerd.io

Now, to confirm the installation, press Y and then press <Enter>.

The APT package manager will download and install all the required packages.

At this point Docker CE should be installed.

Now, add your login user to the docker group with the following command:

$ sudo usermod -aG docker $(whoami)

Now, restart your computer with the following command:

$ sudo reboot

Once your computer starts, run the following command to check whether Docker is working correctly.

$ docker version

As you can see, everything is working great. At the time of this writing, Docker CE 19.03.1 is the latest version of Docker Community Edition.

Docker Basics:

In this section, I am going to show you how to use Docker to set up a basic HTTP web server. This way, you will learn,

  • how to search Docker images
  • how to download Docker images
  • how to list local Docker images
  • how to use Docker images to create containers
  • how to list Docker containers
  • how to stop and remove Docker containers

Let’s say, you want to host your static webpages on a Docker container. To do that, you need an HTTP server Docker image.

To search for a http server Docker image, run the following command:

$ docker search ‘http server’

As you can see, a lot of Docker images are listed in the search result. Here, NAME column contains the name of the Docker image, DESCRIPTION column contains a short description of the Docker image, the STARS column represents how popular that Docker image is, the OFFICIAL column if [OK] it means the Docker image is officially maintained by the company/organization responsible for the product/service.

Now, let’s say, you like the Apache HTTP Server. The NAME of the Docker image is httpd.

To download the httpd Docker image, you can run the following command:

$ docker pull httpd

As you can see, Docker is downloading the httpd image from the internet.

At this point, the Docker image is downloaded.

When a Docker image is downloaded for the first time, it is cached on the local filesystem. So, when you use it later, you won’t have to re download the same Docker image. Thus, it saves you a lot of time and bandwidth.

You can list all the local cached Docker images with the following command:

$ docker image list

As you can see, the Docker image httpd is cached locally.

Now, let’s say, you have a directory website/ on your users HOME directory where all your html project files are.

Now, you can tell Docker to create a container from the httpd image, run the container, map the $HOME/website directory to the webroot (/usr/local/apache2/htdocs) of the httpd container and forward the port 80 of the container to the port 8080 of your computer with the following command:

$ docker run -d -v $HOME/website:/usr/local/apache2/htdocs -p 8080:80 httpd

A new container should be created.

Now, go to a web browser and visit http://localhost:8080

As you can see, the httpd Docker container is serving webpages from the mapped directory $HOME/website

You can list all the running containers with the following command:

$ docker container ls

As you can see, I have only one running container at the moment. You can find CONTAINER ID, IMAGE, STATUS, PORTS, NAMES etc. of each of the running containers from here. The most important one is the NAMES of the containers. Here, the name is randomly generated as I haven’t specified any when I created the container. The name in my case is vigorous_bardeen. Remember the name of your container as you will need it shortly.

Now, if you want to stop the container vigorous_bardeen, run the following command:

$ docker container stop vigorous_bardeen

You can also start a stopped container (let’s say vigorous_bardeen) with the following command:

$ docker container start vigorous_bardeen

If you need to restart a container (let’s say vigorous_bardeen), you can run the following command:

$ docker container restart vigorous_bardeen

If you want to permanently remove a container (let’s say vigorous_bardeen), you can run the following command:

$ docker container rm vigorous_bardeen

So, that’s how you install Docker on Debian 10 and use Docker. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Run Consul Server using Docker

Consul is an open-source service discovery tool which is based and built on Golang. It helps you discovering services application...
29/12/2020

Using Dockerfile to Expose Ports

It is really easy to create a custom Docker image from existing Docker images using Dockerfile. Usually people uses a minimal...
29/12/2020

A Beginner’s Guide To Docker Compose

Docker Compose is one of the most useful tools for Software Developers and System Administrators. Many jobs require someone...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024