Docker is a containerization software that helps to create, deploy, and run applications in a container. It allows the developers to built an application with all required components it needs in a container and then pack it as one package.

The containers are like virtual machines, but lighter than virtual machines and consume fewer resources, easy to manage and can run almost anywhere regardless of operating environment it is running in.

Docker uses Linux kernel’s features such as cgroups and kernel namespace to allow the independent containers to run within a single Linux machine.

This guide will help you install Docker on Debian 9.

Docker supports only a 64-bit version of Debian OS, and Kernel version should be 3.10 and above.

Docker Editions

Docker is available in two editions, namely.

  1. Community Edition (CE)
  2. Enterprise Edition (EE)

Here, we will install Docker CE from the Docker repository.

Prerequisites

Remove Older Version

As a recommended action, you would need to uninstall older versions of Docker called docker or docker-engine along with associated dependencies.

You can skip the below step if your machine does not have a Docker package.

sudo apt -y remove docker docker-engine docker.io containerd runc

Contents such as Docker volumes, images, and networks under /var/lib/docker/ directory are preserved.

Set up Docker Repository

Install the https support packages for apt.

sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

Add the public GPG key for Docker repository on to your system.

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

Add the Docker’s repository to your system by running the command in the terminal.

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

Install Docker

Update the apt repository index.

sudo apt update

The package name for Docker community edition is docker-ce. Install Docker using the apt command.

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

To check the status of Docker service, please run:

sudo systemctl status docker

Output:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-03-19 23:46:21 EDT; 9s ago
     Docs: https://docs.docker.com
 Main PID: 15309 (dockerd)
   CGroup: /system.slice/docker.service
           └─15309 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Mar 19 23:46:18 server dockerd[15309]: time="2019-03-19T23:46:18.141238415-04:00" level=warning msg="Your kernel does not support swap memory limit"
Mar 19 23:46:18 server dockerd[15309]: time="2019-03-19T23:46:18.142299710-04:00" level=warning msg="Your kernel does not support cgroup rt period"
Mar 19 23:46:18 server dockerd[15309]: time="2019-03-19T23:46:18.143213951-04:00" level=warning msg="Your kernel does not support cgroup rt runtime"
Mar 19 23:46:18 server dockerd[15309]: time="2019-03-19T23:46:18.145378260-04:00" level=info msg="Loading containers: start."
Mar 19 23:46:18 server dockerd[15309]: time="2019-03-19T23:46:18.719326772-04:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip
Mar 19 23:46:19 server dockerd[15309]: time="2019-03-19T23:46:19.774761864-04:00" level=info msg="Loading containers: done."
Mar 19 23:46:21 server dockerd[15309]: time="2019-03-19T23:46:21.097531598-04:00" level=info msg="Docker daemon" commit=774a1f4 graphdriver(s)=overlay2 version=18.09.3
Mar 19 23:46:21 server dockerd[15309]: time="2019-03-19T23:46:21.101107317-04:00" level=info msg="Daemon has completed initialization"
Mar 19 23:46:21 server systemd[1]: Started Docker Application Container Engine.
Mar 19 23:46:21 server dockerd[15309]: time="2019-03-19T23:46:21.518199513-04:00" level=info msg="API listen on /var/run/docker.sock"

Test Docker Installation

We will now run a hello-world container to test our Docker installation.

sudo docker run hello-world

Output:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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.
 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/

The above output confirms that we have correctly installed Docker on Debian OS.

Allow Non-root user to run Docker

By default, regular users do not have privileges to run Docker commands and have to prefix sudo for every docker commands. To avoid prefixing the sudo and allow non-root users like developers to run Docker containers, follow the below steps.

Create the docker group, if it does not exist.

sudo groupadd docker

Add a regular user to docker group. Replace linuxbees with your username.

sudo useradd linuxbees -s /bin/bash -m -d /home/linuxbees

Add the user to docker group.

sudo usermod -aG docker linuxbees

Regual user (linuxbees) should now be able to run Docker commands without prefixing sudo.

docker run hello-world

Conclusion

You have successfully installed Docker on Debian 9. As a next step, you can visit command-line reference for important Docker commands and learn how to create Docker containers.

Previous
Next
comments powered by Disqus