Launching Kali Linux in Docker for Security Testing Workflows

Running Kali Linux inside a lightweight container is a quick way to spin up a disposable penetration-testing lab. The steps below show how to provsiion the distribution with Docker Compose, map useful ports, and persist your tools and findings on the host.

Prerequisites

  • A Linux host with sudo access (Ubuntu 22.04 is used in the examples).
  • Outbound Internet connectivity to pull images.
  1. Install Docker Engine

sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker
  1. Install Docker Compose v2

Ubuntu 22.04 ships the legacy Python-based docker-compose. Prefer the newer plugin:

sudo apt install -y docker-compose-v2

Verify with docker compose version.

  1. Create the Project Directory

mkdir ~/kali-lab && cd ~/kali-lab
  1. Compose File

Save the following as compose.yml:

services:
  kali:
    image: kalilinux/kali-rolling:latest
    container_name: kali-ctf
    stdin_open: true
    tty: true
    ports:
      - "2222:22"   # SSH jump host
      - "8080:8080" # Web proxies (Burp, ZAP, etc.)
      - "4444:4444" # Reverse shells
    volumes:
      - ./workspace:/home/kali/workspace
    working_dir: /home/kali
    command: ["/bin/bash"]
  1. Bring the Lab Online

docker compose up -d

The first run downloads ~3 GB of image layers.

  1. Enter the Container

docker exec -it kali-ctf bash

You now have a root shell in a minimal Kali environment. Install your preferred toolset:

apt update && apt install -y kali-linux-headless
  1. Optional SSH Access

Inside the container:

service ssh start
passwd kali   # set a password for the kali user

From the host:

ssh -p 2222 kali@localhost
  1. Persisting State

The ./workspace directory on the host is mounted at /home/kali/workspace. Scripts, wordlists, and reports placed there survive container restarts and rebuilds.

  1. Tear Down

docker compose down   # stops and removes the container
docker image prune -f # optional: reclaim disk space

This setup gives you a reproducible, isolated Kali instance that can be started in seconds and discarded just as quickly, making it ideal for CTF events, red-team exercises, or ad-hoc vulnerability assessments.

Tags: Kali Linux Docker Compose Penetration Testing containerized security lab CTF environment

Posted on Mon, 31 Aug 2026 16:50:16 +0000 by Aybabtu