Welcome to our guide on how to install Docker and Docker Compose on Kali Linux. We will install 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. Use Kubernetes to easily ship it from a Developer machine to a production environment.
Here are the terms commonly used in the Docker ecosystem.
- Docker daemon: This is also called Docker Engine, it is a background process that runs on the host system responsible for building and running the container.
- Roustabout client: This is a command line tool that users use to interact with the Docker daemon.
- Docker image: An image is an immutable file, essentially a snapshot of a container. Docker images have the file system and application dependencies needed to run the application.
- 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 is isolated from other containers. The only content shared by the container is the kernel.
- Docker registry: This is an application responsible for managing the storage and delivery of Docker container images. It can be private or public.
So let’s start installing Docker on Kali Linux.
Step 1: Install dependent packages
Begin the installation by ensuring that all packages that docker uses as dependencies are installed.
sudo apt update sudo apt -y install curl gnupg2 apt-transport-https software-properties-common ca-certificates
Step 2: Import the Docker GPG key:
Import the Docker GPG key used to sign the Docker package:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Step 3: Add the Docker repository to Kali Linux
Add a Docker repository containing the latest stable version 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 adds the repository URL to /etc/apt/sources.list.d/docker.list.
Step 4: Install Docker on Kali Linux
apt The 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 following command:
sudo apt install docker-ce docker-ce-cli containerd.io
hit ÿ The key to getting started with 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 a system without any users. Add your user account to the group and run the docker command as an unprivileged user.
sudo usermod -aG docker $USER newgrp docker
Check the installed Docker version.
$ 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 following guide to install the latest Docker Compose on Kali Linux.
How to install the latest Docker Compose on Linux
After installation, check that the installation was successful by checking the 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 the Docker installation.
Run the 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 your Docker Compose installation.
Create a test Docker Compose file.
$ vim docker-compose.yml
Add the following data to the file.
version: '3' services: web: image: nginx:latest ports: - "8080:80" links: - php php: image: php:7-fpm
Start the service container.
$ 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 the container:
$ 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 application development and run with Docker and Docker Compose on Kali Linux.