Installing Docker on Debian 10

Installing Docker on Debian 10
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.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *