How To Install Docker On Ubuntu, Debian, Mint, Kali? – POFTUT

How To Install Docker On Ubuntu, Debian, Mint, Kali?


Docker is a container technology used to run containers in Linux, Windows systems with little system resources. In this tutorial, we will examine how to install Docker and run containers in deb or apt based distros like Ubuntu, Debian, Mint, Kali, etc.

Update Apt Repository Information

The best practice before installing a package from a package repository is updating the repository information and getting the latest changes. We will start updating the repository with apt update or  apt-get update command like below.

$ sudo apt update

OR

$ sudo apt-get update
Update Apt Repository Information
Update Apt Repository Information

Install Docker From Ubuntu Repository

Rpm or Yum based distributions like RedHat, CentOS, Fedora uses docker as package names without a problem. Because there is no collusion with the name docker . But deb or apt based distributions like Ubuntu, Debian, Mint, Kali have some restriction because docker package name is used by other application. So we need to use docker.io as package name while installing the Docker.

$ sudo apt install docker.io

OR

$ sudo apt-get install docker.io

Install Docker From Official Docker Repository

Docker is also provided as Ubuntu packages from the official Docker repository. Docker repository provides the latest version as it is the creator of the Docker packages. First, we will add GPG keys for the official Docker repository to the current system. We will use curl and apt-key commands like below.

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
Add Docker Repository GPG Keys
Add Docker Repository GPG Keys

Now we can add official Docker Ubuntu repository with the add-apt-repository command like below.

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Add Official Docker Repository to Ubuntu
Add Official Docker Repository to Ubuntu

Now everything is ready to install Docker on Ubuntu. Before installing the official Docker we can print some information about it with the apt show command like below. The package name provided by Docker will be docker-ce which is different from the Ubuntu provided Docker which is docker.io. But most of the things are the same.

$ apt show docker-ce
docker-ce Package Information
docker-ce Package Information

We can see that information like the package name, version, installed-size, etc is provided.

LEARN MORE  How To Create, Start, Stop, Manage Docker Containers In Linux?

We can install the Docker package with the following command. We will use sudo command in order to install the package.

$ sudo apt install docker-ce
Install docker-ce
Install docker-ce

Start Docker Service

Docker works as a service that is named docker for all Docker installation. We can start the Docker service in order to use Docker, create containers, etc. We can start the Docker service with the following command. Docker service start will require root privileges which can be provided with the sudo command or current user password will be asked.

$ sudo systemctl start docker

OR

$ systemctl start docker
Start Docker Service
Start Docker Service

Stop Docker Server

We can stop the Docker server if we do not want to use or to reload it by stopping and starting. We will use the following command.

$ sudo systemctl stop docker

OR

$ systemctl stop docker
Stop Docker Server
Stop Docker Server

Print Docker Service Status

As Docker runs as a service if there is a problem by creating, running, saving docker containers we generally look to the Docker service status. We can print Docker service status with the following command.

$ systemctl status docker
Print Docker Service Status
Print Docker Service Status

We can see that Docker service is currently active or running from the given time. Information like Process ID, Task count, Memory usage, and last logs about the service is also provided.

Print Docker Version

Some features are provided upward from the given version. So if we want o use a feature with a given version number we need to know the current version of the Docker installation. We can print the Docker version with the --version option like below.

$ docker --version
Print Docker Version
Print Docker Version

Search Docker Images

Generally, the first actions after installing Docker is searching for some images in order to download. We will use the command docker for most of the operations like search. In this example, we will search the images named or tagged with the term centos.

$ docker search centos
Search Docker Images
Search Docker Images

Download Docker Image

We can download or pull specific image before using it. We will use the pull command which will download the image but do not start any container. In this example, we will pull the image named centos.

$ docker pull centos
Download Docker Image
Download Docker Image

List Docker Images

Before downloading an image or in order to learn locally existing images we can use docker images command which will list currently downloaded and existing images.

$ docker images
List Docker Images
List Docker Images

Create and Run Sample CentOS Container

Creating a container is the same for all distributions. We will use docker command for this. We do not use docker.io because it is not a command just a package name. In this example, we will run a bash shell in CentOS container interactively. We need to be in docker group or have root privileges in order to run Docker containers. So

$ sudo docker run -t -i centos bash
Create and Run Sample CentOS Container
Create and Run Sample CentOS Container

List Running Docker Containers

We can run multiple Docker containers at the same time. If we want to list currently running Docker containers we can use docker ps command which will list only running Docker containers.

$ docker ps
List Running Docker Containers
List Running Docker Containers

Stop Running Docker Container

In the end, we want to stop a container we do not need for now. We can use stopcommand of the Docker like below. We also need to provide Docker ID which can be obtained with the Docker running container list command.

$ sudo docker stop 1e4adf4c3c84

Leave a Comment