How To Set Up Kali In Docker For Hacking

Prinux
CodeX
Published in
4 min readNov 27, 2022

Why Docker

Docker is an amazing technology that helps you run containerized applications. The thing that make docker incredible it that it requires very little ram and CPU power compared to a virtual machine running Kali. Docker does not contain a hypervisor, which is why it’s less resource intensive and fast.

Installing Docker

Set up the repository

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:
$ sudo apt-get update

$ sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

2. Add Docker’s official GPG key:

$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

3. Use the following command to set up the repository:

$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine

  1. Update the apt package index:

Receiving a GPG error when running apt-get update?
Your default umask may be incorrectly configured, preventing detection of the repository public key file. Try granting read permission for the Docker public key file before updating the package index:

$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
$ sudo apt-get update
  1. Install Docker Engine, containerd, and Docker Compose.
  • Latest
  • Specific version

To install the latest version, run:

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

To install a specific version of Docker Engine, start by list the available versions in the repository:

# List the available versions:
$ apt-cache madison docker-ce | awk '{ print $3 }'

5:20.10.16~3-0~ubuntu-jammy
5:20.10.15~3-0~ubuntu-jammy
5:20.10.14~3-0~ubuntu-jammy
5:20.10.13~3-0~ubuntu-jammy

Select the desired version and install:

$ VERSION_STRING=5:20.10.13~3-0~ubuntu-jammy
$ sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-compose-plugin
  1. Verify that the Docker Engine installation is successful by running the hello-world image:
$ sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
If you’re using any other operating system, click here.

Installing Kali

Now, after installing docker, it is time to install Kali on docker. You can visit the official Kali page and navigate to the container section and click on docker. Or you can visit directly their docker page. From here you can select their latest rolling release and copy and run their Docker Pull Command.

After running it, you will see:

The first repository is the one which we have downloaded right now, the rest are other images which I use.

Setting Up Kali

For running the image as a container, run. The image ID might be different for you, hence change it as required:-

sudo docker run -it 3629dd971a7e  /bin/bash

after that, you need to update the repositories:

apt update

See now you have a Kali Linux on your machine, running in docker.

Installing The Tools For The Trade

At first there are only necessary packages required to run the system and there are no hacking tools (No neofetch also, I installed after updating the repository). For installing the all the tools run:-

apt update && apt -y install kali-linux-headless
apt update && apt -y install kali-linux-large

or if you want only a few tools, then you have to install them one by one manually

apt update && apt -y install <package>

I will be writing an article about docker in the future, so follow me to get notified.

If you like this blog , please don’t forget to give a clap . if you want to learn more about privacy,security,technology and Linux, consider following me. Plus, whatever I find interesting and valuable. Follow Me on mastodon

--

--

Prinux
CodeX
Writer for

I Am Linux Enthusiast , Privacy Advocate , Self Taught Programmer, plus a coffee addict. Follow me to learn more about privacy, linux and technology.