How To Install Docker on Debian 9

 In Dedicated, VPS, Web

Docker is an open-source application that provides lightweight operating-system-level virtualization through the use of containers. It is specially designed to increase the productivity of most IT operations by making virtualization easy to use. Containers are in essence a set of software packages that run as one application that’s isolated from other applications. Developers, System Administrators, and the like take advantage of this feature by spawning containers wherein they can create, deploy, and run applications without needing to create another virtual machine, which greatly affects productivity and cost.

Here are the top reasons why organizations and businesses use Docker:

  • Increased developer productivity
  • Increased deployment velocity
  • Increased IT operation efficiency
  • Faster resolution of issues that may arise
  • Reduction in IT infrastructure cost

Docker is currently developed and maintained by Docker Inc. and is written using the mainstream Go programming language. It is licensed under Apache License 2.0. As of writing, the latest stable version of Docker is 18.09.5.

There are currently two editions of Docker:

  • Docker CE – Community Edition – Open Source Software supported by the community and Docker Inc.
  • Docker EE – Enterprise Edition – certified and supported by Docker Inc.

Let’s start installing Docker.

Prerequisites

For this tutorial, we will be using one of our Debian VPS services. Before continuing, make sure that your server has the root account enabled, or a user with sudo privileges.

The hardware resources required to run Docker optimally usually depends on the number of containers and the platforms inside the container. This means that the hardware requirements still depend on the application that the containers will run, where the number of containers that can be active solely depends on the hardware it runs on.

Step 1: Log into and Update the System

To start with the Docker installation, we first need to log in to our server via SSH:

ssh [username]@[server_ip_address] -p [SSH port]

Modify the [username] ,[server_ip_address], and [SSH port]parameters based on your server details. It is recommended to use the ‘root’ account for Docker installation.

Before starting with the installation, we recommend updating all installed packages to their latest versions which helps to maximize compatibility when installing new software. You can do that by running this next command:

apt-get update
apt-get upgrade

Step 2: Install Required Packages

It is recommended to install the Linux common libraries along with these dependencies to help avoid missing any required packages during the installation process.

apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common build-essential

Step 3: Setting Up Docker Repository

Currently, there are three ways to install Docker on our system: through Docker’s official repository, from a Debian (.deb) package, and from a script created by Docker developers. Also, Docker has three update channels – stable, test, and nightly.

  • Stable – provides the latest stable release of Docker.
  • Test – provides pre-releases for testing purposes.
  • Nightly – provides the latest possible build. This is usually unstable.

For this tutorial, we will install Docker Community Edition (CE) using their official repository. This is the recommended method of installation for both development and production environments due to the fact that we can select an update channel, where the package itself can then be easily updated.

To add the Docker repository to our server, we need to add the GPG keys first with the following commands:

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

Once added, add the repository pointing to ‘stable’ update channel.

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

We can now update our packages, which should include the repository from Docker.

apt-get update

After applying command, you should see the repository link added:

Get:5 https://download.docker.com/linux/debian stretch InRelease [44.8 kB]
Get:7 https://download.docker.com/linux/debian stretch/stable amd64 Packages [8,437 B]

Step 4: Installing Docker CE

After setting up the repository, we can now install the Docker CE, as well as the Docker CLI by running the following command:

apt-get install -y docker-ce docker-ce-cli

This might take some time as it will also install any additional libraries that it requires.

Once the installation is done, verify that the docker service is running by typing:

systemctl status docker

You should see a similar output with the word ‘active (running)’:

 

 

 

 

 

You can also check and verify the Docker version using:

docker -v

Finally, make sure that the docker service will run at boot:

systemctl enable docker

Step 5: Configuring Docker CE

In order to be able to run docker commands, the user being used must have root privileges. If you need a non-root user to be able to run the Docker CLI commands, follow these optional steps:

First, create the docker group:

groupadd docker

Then assign the user to the group, using the usermod command. Modify the variable [user] accordingly:

usermod -aG docker [user]

Finally, to test this new configuration, log out and log in as the assigned user. You should now be able to run a docker command without using sudo.

Step 6: Testing Docker CE

Let’s now test if we can run Docker containers. We can try running a sample container readily available, the classic “Hello World”.

docker run hello-world

You should see the same message which shows the technical steps of what is done in the background after running the command.

 

 

 

 

 

 

 

 

 

 

 

That’s it! – you now have a working Docker installation running on Debian 9.

Recommended Posts

Start typing and press Enter to search