Skip to main content

How to Install Docker on Debian 9 Stretch / Debian 8

Docker is a free and open-source containerization software that helps to deploy, run applications in a container. The containers are similar to a virtual machine but consume fewer resource, easy to manage and can run anywhere regardless of operating environment it is running in.
Docker uses cgroups and namespace to allow the independent containers to run within a single Linux instance.
This guide will help you installing Docker on Debian 9 Stretch. This guide should also work on the previous version, i.e., Debian 8 (Jessie)
Note: Docker needs a 64-bit version of Debian OS and Kernel version should be at least 3.10.

Docker Editions

Docker is now available in two editions, namely.
  • Community Edition (CE)
  • Enterprise Edition (EE)
Here, we will install Docker Comunity Edition (CE) from Docker repository.

Prerequisites

Uninstall older versions of Docker called docker” or “docker-engine along with associated dependencies. If your system does not have a Docker package, skip the below step.
sudo apt-get -y remove docker docker-engine docker.io
Contents such as volumes, images, and networks under /var/lib/docker/ directory are preserved.

Setup Docker Repository

Install the below packages to have “apt” get the support of https method.
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates wget software-properties-common
Add the GPG key for Docker repository on your system.
wget https://download.docker.com/linux/debian/gpg 
sudo apt-key add gpg
Add the official Docker repository to the system by running below command in the terminal.
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list
Update the apt database.
sudo apt-get update
Make sure you are installing Docker from the official repository, not from the default Debian repository.
sudo apt-cache policy docker-ce
You should see the output like below with the Docker repository details.
docker-ce:
  Installed: (none)
  Candidate: 17.06.0~ce-0~debian
  Version table:
     17.06.0~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.2~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.1~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.0~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages

Install Docker

Install Docker using the “apt-get” command.
sudo apt-get -y install docker-ce

Control Docker service

To start Docker, run:
sudo systemctl start docker
To stop Docker service, run:
sudo systemctl stop docker
To restart Docker service, run:
sudo systemctl restart docker
To check the status of Docker service, run:
sudo systemctl status docker
To enable Docker service to autostart on system boot, run:
sudo systemctl enable docker

Verify Docker Installation

To test the Docker installation, we will run “hello-world” container.
sudo docker run hello-world
Below output confirms that we have correctly installed Docker on Debian OS.
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete 
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Allow Non-root user to run Docker

By default, to run Docker commands, the user should have root privileges or equivalent privileges via sudo. Sometimes we may need to allow non-root users to run Docker containers, so follow the below steps to allow them to run containers.
Create a group “docker“, if it does not exist.
sudo groupadd docker
Add your user to docker group, replace “raj” with your username.
sudo useradd raj
Add a user to docker group.
sudo usermod -aG docker raj
Log out and log back in. You should now be able to run Docker commands without prefixing sudo.
docker run hello-world

Comments

Popular posts from this blog

CKA Simulator Kubernetes 1.22

  https://killer.sh Pre Setup Once you've gained access to your terminal it might be wise to spend ~1 minute to setup your environment. You could set these: alias k = kubectl                         # will already be pre-configured export do = "--dry-run=client -o yaml"     # k get pod x $do export now = "--force --grace-period 0"   # k delete pod x $now Vim To make vim use 2 spaces for a tab edit ~/.vimrc to contain: set tabstop=2 set expandtab set shiftwidth=2 More setup suggestions are in the tips section .     Question 1 | Contexts Task weight: 1%   You have access to multiple clusters from your main terminal through kubectl contexts. Write all those context names into /opt/course/1/contexts . Next write a command to display the current context into /opt/course/1/context_default_kubectl.sh , the command should use kubectl . Finally write a second command doing the same thing into ...

OWASP Top 10 Threats and Mitigations Exam - Single Select

Last updated 4 Aug 11 Course Title: OWASP Top 10 Threats and Mitigation Exam Questions - Single Select 1) Which of the following consequences is most likely to occur due to an injection attack? Spoofing Cross-site request forgery Denial of service   Correct Insecure direct object references 2) Your application is created using a language that does not support a clear distinction between code and data. Which vulnerability is most likely to occur in your application? Injection   Correct Insecure direct object references Failure to restrict URL access Insufficient transport layer protection 3) Which of the following scenarios is most likely to cause an injection attack? Unvalidated input is embedded in an instruction stream.   Correct Unvalidated input can be distinguished from valid instructions. A Web application does not validate a client’s access to a resource. A Web action performs an operation on behalf of the user without checkin...