Friday, December 27, 2024
Google search engine
HomeGuest BlogsInstall Docker and Docker Compose on Kali Linux

Install Docker and Docker Compose on Kali Linux

Welcome to our guide on how to install Docker and Docker Compose on Kali Linux machine. 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.

install docker docker compose kali

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 full-upgrade
sudo apt install curl gnupg2 apt-transport-https software-properties-common ca-certificates

Check if a reboot is required after the upgrade:

[ -f /var/run/reboot-required ] && sudo reboot -f

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 gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg

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 bullseye 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 bullseye 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 bullseye/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... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  fastjar fonts-roboto-slab gnome-desktop3-data jarwrapper kali-wallpapers-2021.4 libaom0 libcbor0 libcodec2-0.9 libdap27 libdapclient6v5 libdav1d4 libepsilon1 libfluidsynth2 libfmt7 libgdal28
  libgdal29 libgdk-pixbuf-xlib-2.0-0 libgdk-pixbuf2.0-0 libgeos-3.9.1 libgeos3.10.1 libgnome-desktop-3-19 libgupnp-1.2-0 libidn11 libigdgmm11 libnetcdf18 libntfs-3g883 libodbc1 libodbccr2
  libomp-11-dev libomp5-11 libproj19 libqhull8.0 liburcu6 liburing1 libvpx6 libwireshark14 libwiretap11 libwsutil12 libx265-192 libxkbregistry0 libyara4 linux-image-5.10.0-kali9-amd64 maltego
  odbcinst odbcinst1debian2 python3-editor python3-exif python3-ipython-genutils python3-orjson python3-pylnk python3-stem ruby-atomic ruby-thread-safe starkiller zaproxy
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin libslirp0 pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin libslirp0 pigz slirp4netns
0 upgraded, 8 newly installed, 0 to remove and 16 not upgraded.
Need to get 97.1 MB of archives.
After this operation, 409 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:           20.10.23
 API version:       1.41
 Go version:        go1.18.10
 Git commit:        7155243
 Built:             Thu Jan 19 17:36:21 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:34:26 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.15
  GitCommit:        5b842e528e99d4d4c1686467debf2bd4b88ecd86
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Step 5: Install Docker Compose on Kali Linux

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

After installation, confirm successful installation by checking version.

$ docker-compose version
Docker Compose version v2.15.1

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:8-fpm

Start service containers.

$ docker-compose up -d
[+] Running 17/17
 ⠿ php Pulled                                                                                                                                                                                  9.5s
   ⠿ 5eb5b503b376 Pull complete                                                                                                                                                                1.9s
   ⠿ 8b1ad84cf101 Pull complete                                                                                                                                                                2.0s
   ⠿ 38c937dadeb7 Pull complete                                                                                                                                                                6.3s
   ⠿ 6a2f1dc96e59 Pull complete                                                                                                                                                                6.3s
   ⠿ 09f78174268e Pull complete                                                                                                                                                                6.4s
   ⠿ 789f1e9593c6 Pull complete                                                                                                                                                                6.5s
   ⠿ a94c2f1ef4c2 Pull complete                                                                                                                                                                7.2s
   ⠿ 362cd81222e9 Pull complete                                                                                                                                                                7.2s
   ⠿ da7a098ae555 Pull complete                                                                                                                                                                7.3s
   ⠿ 69108a9ecce2 Pull complete                                                                                                                                                                7.3s
 ⠿ web Pulled                                                                                                                                                                                  4.9s
   ⠿ 1ae07ab881bd Pull complete                                                                                                                                                                2.5s
   ⠿ 78091884b7be Pull complete                                                                                                                                                                2.5s
   ⠿ 091c283c6a66 Pull complete                                                                                                                                                                2.6s
   ⠿ 55de5851019b Pull complete                                                                                                                                                                2.6s
   ⠿ b559bad762be Pull complete                                                                                                                                                                2.7s
[+] Running 3/3
 ⠿ Network jkmutai_default  Created                                                                                                                                                            0.2s
 ⠿ Container jkmutai-php-1  Started                                                                                                                                                            1.2s
 ⠿ Container jkmutai-web-1  Started                                                                                                                                                            0.6s

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
[+] Running 2/2
 ⠿ Container jkmutai-web-1  Stopped                                                                                                                                                            0.2s
 ⠿ Container jkmutai-php-1  Stopped                                                                                                                                                            0.2s

$ docker-compose rm
docker-compose rm
? Going to remove jkmutai-web-1, jkmutai-php-1 Yes
[+] Running 2/0
 ⠿ Container jkmutai-php-1  Removed                                                                                                                                                            0.0s
 ⠿ Container jkmutai-web-1  Removed                                                                                                                                                            0.0s

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

RELATED ARTICLES

Most Popular

Recent Comments