Install Kali Linux Using Docker

Share This:

Kali Linux Docker

Docker is a great alternative to virtualization, especially in the case of Linux if you don’t need a GUI. Most of the popular Kali Linux pentest tools are command-line based and don’t require a GUI, which makes Docker an excellent alternative. If you’re running Docker on Linux or macOS, it requires less resources than a full blown virtual machine. You can still run it on Windows, but it will use more overhead than Linux and macOS. Offensive Security has created a kalilinux/kali-linux-docker bare bones image, which is what we’ll use to get started.

Install Kali Linux Using Docker

This article assumes you already have Docker installed and running. You can find more information at Docker.com.

Run the following commands to pull the most recent Kali Linux Docker Image, create the Docker Container and start /bin/bash in that container:

docker pull kalilinux/kali-linux-docker
docker run -ti kalilinux/kali-linux-docker /bin/bash

Update Kali Linux

After running the commands above, you’ll be at the /bin/bash prompt. You’ll want to run the following commands to update the Kali packages:

apt update
apt full-upgrade
apt autoremove
apt clean

Install Kali Metapackages

Since the image we used above is bare bones, you’ll want to install some Kali Metapackages to get the tools you need. Kali keeps a list of common Metapackages here: https://www.kali.org/news/kali-linux-metapackages/.

Let’s get started by installing these common Metapackages:

apt install kali-linux-top10
apt install kali-linux-wireless
apt install man-db
apt install exploitdb

Create Local Docker Image After Updates Install

Once you get your updates and packages installed, you’ll want to create a local Docker image.

Type exit to exit the /bin/bash shell.

To get a list of all your Docker containers, run this command:

docker ps -a

Copy the CONTAINER ID, which will look similar to this: 0dd01659d8dd

Now we’ll want to run to create a Docker imaged names my-kali (change it to what you want):

docker commit CONTAINER_ID my-kali

Depending on what you installed, this step could take a while.

Docker Persistance

You’ll probably want to save the data in the /root and /var/lib/postgresql directories so that you can save any data in those directories if your container is deleted.

To start a new Kali Docker container using the image we just created, you’ll want to use this command:

docker run -ti --rm --mount src=kali-root,dst=/root --mount src=kali-postgres,dst=/var/lib/postgresql my-kali

  • This will create (or re-use them if they’re already created) two volumes named kali-root and kali-postgres and map them to the created container.
  • The –rm switch makes Docker delete the container once you exit the shell. This is preferred so that you don’t waste storage on a bunch of stopped containers.

You can put this command into a script to run so that you don’t have to type the whole thing every time you want to start your Docker container.

Docker Cleanup

Use the following command to delete all stopped containers:

docker container prune

You can use docker rm CONTAINER_ID to delete individual containers.


Share This:

 

Leave a Reply