Welcome to our guide on how to install Docker and Docker Compose on Kali Linux. We’ll install the Docker CE (Community Edition) on Kali Linux. Docker is the most popular and widely used container runtime. It enables Developers to package, ship and run their applications in isolated containers. Making it easy to ship from Developer machine to Production environment orchestrated with Kubernetes.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/02/echo/install-docker-docker-compose-kali-linux.png" data-ez ezimgfmt="rs rscb7 src ng ngcb7 srcset" src="data:image/svg xml,”>

Below are commonly used terminologies in Docker ecosystem.

  • Docker daemon: This is also called Docker Engine, it is a background process which runs on the host system responsible for building and running of containers.
  • Docker Client: This is a command line tool used by the user to interact with the Docker daemon.
  • Docker Image: An image is an immutable file that’s essentially a snapshot of a container. A docker image has a file system and application dependencies required for running applications.
  • Docker container: This is a running instance of a docker image with an application and its dependencies. Each container has a unique process ID and isolated from other containers. The only thing containers share is the Kernel.
  • Docker registry: This is an application responsible for managing storage and delivery of Docker container images. It can be private or public.

So let’s get started with the installation of Docker on Kali Linux.

Step 1: Install Dependency packages

Start the installation by ensuring that all the packages used by docker as dependencies are installed.

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

Step 2: Import Docker GPG key:

Import Docker GPG key used for signing Docker packages:

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

Step 3: Add the Docker repository to Kali Linux

Add Docker repository which contain the latest stable releases of Docker CE.

echo "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" | sudo tee  /etc/apt/sources.list.d/docker.list

This command will add repository URL to /etc/apt/sources.list.d/docker.list.

Step 4: Install Docker on Kali Linux

Update the apt package index.

$ sudo apt update
gn:1 http://dl.google.com/linux/chrome/deb stable InRelease
Get:3 https://download.docker.com/linux/debian buster InRelease [44.4 kB]                          
Hit:2 http://kali.download/kali kali-rolling InRelease
Hit:4 http://dl.google.com/linux/chrome/deb stable Release
Get:5 https://download.docker.com/linux/debian buster/stable amd64 Packages [10.9 kB]
Fetched 55.3 kB in 1s (45.2 kB/s)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
186 packages can be upgraded. Run 'apt list --upgradable' to see them.

To install Docker CE on Kali Linux, run the command:

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

Hit the y key to start installation of Docker on Kali Linux.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  aufs-dkms aufs-tools cgroupfs-mount dkms linux-compiler-gcc-9-x86 linux-headers-5.4.0-kali3-amd64
  linux-headers-5.4.0-kali3-common linux-headers-amd64 linux-kbuild-5.4 pigz
Suggested packages:
  aufs-dev menu
The following NEW packages will be installed:
  aufs-dkms aufs-tools cgroupfs-mount containerd.io dkms docker-ce docker-ce-cli linux-compiler-gcc-9-x86
  linux-headers-5.4.0-kali3-amd64 linux-headers-5.4.0-kali3-common linux-headers-amd64 linux-kbuild-5.4 pigz
0 upgraded, 13 newly installed, 0 to remove and 186 not upgraded.
Need to get 98.1 MB of archives.
After this operation, 446 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

This installation will add docker group to the system without any users. Add your user account to the group to run docker commands as non-privileged user.

sudo usermod -aG docker $USER
newgrp docker

Check Docker version installed.

$ docker version
Client: Docker Engine - Community
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.16
 Git commit:        369ce74a3c
 Built:             Thu Feb 13 01:27:58 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.16
  Git commit:       369ce74a3c
  Built:            Thu Feb 13 01:26:32 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.12
  GitCommit:        35bd7a5f69c13e1563af8a93431411cd9ecf5021
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Step 5: Install Docker Compose on Kali Linux

Use the guide below to install latest Docker Compose on Kali Linux.

How To Install Latest Docker Compose on Linux

After installation, confirm successful installation by checking version.

$  docker-compose version
docker-compose version 1.25.4, build 8d51620a
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Step 6: Test Docker installation.

Run a test docker container:

$ docker run --rm -it  hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
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/

Step 6: Test Docker Compose installation.

Create a test Docker Compose file.

$ vim docker-compose.yml

Add below data to the file.

version: '3'  
services:
  web:
    image: nginx:latest
    ports:
     - "8080:80"
    links:
     - php
  php:
    image: php:7-fpm

Start service containers.

$ docker-compose up -d
Creating network "jkmutai_default" with the default driver
Pulling php (php:7-fpm)...
7-fpm: Pulling from library/php
bc51dd8edc1b: Pull complete
a3224e2c3a89: Pull complete
be7a066df88f: Pull complete
bfdf741d72a9: Pull complete
0096578ff21c: Pull complete
52b9a3846c51: Pull complete
91c8df69c5cf: Pull complete
ba16a1822680: Pull complete
c137b651214d: Pull complete
a2738b6c9bea: Pull complete
Digest: sha256:022dcc4f1a054584660ce3d77bb0dc1f5084d25f117d4814726518b7f66af47f
Status: Downloaded newer image for php:7-fpm
Pulling web (nginx:latest)...
latest: Pulling from library/nginx
bc51dd8edc1b: Already exists
66ba67045f57: Pull complete
bf317aa10aa5: Pull complete
Digest: sha256:ad5552c786f128e389a0263104ae39f3d3c7895579d45ae716f528185b36bc6f
Status: Downloaded newer image for nginx:latest
Creating jkmutai_php_1 ... done
Creating jkmutai_web_1 ... done

Show running Containers:

$ docker-compose ps
    Name                   Command              State          Ports        
----------------------------------------------------------------------------
jkmutai_php_1   docker-php-entrypoint php-fpm   Up      9000/tcp            
jkmutai_web_1   nginx -g daemon off;            Up      0.0.0.0:8080->80/tcp

Destroy containers:

$ docker-compose stop
Stopping jkmutai_web_1 ... done
Stopping jkmutai_php_1 ... done

$ docker-compose rm
Going to remove jkmutai_web_1, jkmutai_php_1
Are you sure? [yN] y
Removing jkmutai_web_1 ... done
Removing jkmutai_php_1 ... done

Enjoy your containerized applications development and running with Docker and Docker Compose on Kali Linux.