In the evolving cybersecurity landscape, building a reproducible and controlled penetration testing lab is essential. Docker simplifies this by enabling modular, isolated environments. This guide walks you through creating a Docker-based security testbed on Windows using WSL 2, complete with vulnerable apps (DVWA, Metasploitable), Kali Linux, and Snort 3 for IDS testing.
wsl --install
wsl --set-default-version 2
Then restart your machine.
docker --version
docker run hello-world
Here’s a breakdown of the services we’ll be using:
Container | Purpose | Port | Notes |
---|---|---|---|
DVWA | Vulnerable Web App (MySQL-backed) | 8080 | Web-based pentesting |
Kali | Penetration Testing Distro (GUI) | 7002 | Accessible via browser (KasmVNC) |
Metasploitable | Deliberately vulnerable OS | 7003 | Useful for scanning and exploit tests |
Snort 3 | Intrusion Detection System | — | CLI only; test alerting and signatures |
docker-compose.yml
version: ‘3.8’
services:
dvwa:
image: vulnerables/web-dvwa
container_name: dvwa
ports:
– “8080:80”
networks:
– pentest-network
tty: true
stdin_open: true
restart: unless-stopped
depends_on:
– dvwa_dbdvwa_db:
image: mariadb:10.1
container_name: dvwa_db
hostname: dvwa_db
volumes:
– dvwa_db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: dvwa
MYSQL_USER: dvwa
MYSQL_PASSWORD: p@ssw0rd
restart: unless-stopped
networks:
– pentest-networkkali:
build:
context: .
dockerfile: Dockerfile.kali
container_name: kali
shm_size: ‘512m’
ports:
– “7002:6901”
environment:
– VNC_PW=password
user: “root”
networks:
– pentest-network
tty: true
stdin_open: true
restart: unless-stopped
volumes:
– kali_data:/root
command: >
bash -c “apt-get update && apt-get install -y iputils-ping traceroute whois net-tools nmap tshark wireshark hping3 nano && tail -f /dev/null”metasploitable:
build:
context: .
dockerfile: Dockerfile.metasploitable
container_name: metasploitable
networks:
– pentest-network
tty: true
stdin_open: true
restart: unless-stopped
ports:
– “7003:80”
volumes:
– metasploitable_data:/var/lib/metasploitablesnort3:
build:
context: .
dockerfile: Dockerfile.snort3
container_name: snort3
hostname: snort3
user: “snorty”
working_dir: /home/snorty
networks:
– pentest-network
tty: true
stdin_open: true
restart: unless-stopped
volumes:
– snort_data:/etc/snort
command: >
bash -c “apt-get update && apt-get install -y iputils-ping traceroute whois net-tools nmap tshark wireshark hping3 nano && tail -f /dev/null”networks:
pentest-network:
driver: bridgevolumes:
dvwa_db_data:
kali_data:
metasploitable_data:
snort_data:You’ve already got the full config (shared above). Here’s what it does:
pentest-network
Dockerfile.kali
, Dockerfile.metasploitable
, and Dockerfile.snort3
, in a working folder. Then from PowerShell:docker compose up --build -d
This builds and runs all services in detached mode.
A. CLI Access
Use these commands from PowerShell:
docker exec -it kali /bin/sh
docker exec -it dvwa /bin/sh
docker exec -it metasploitable /bin/sh
docker exec -it -u root snort3 bash
Type exit
to leave any session.
B. GUI/Web Access
Container | URL | Credentials |
---|---|---|
DVWA | http://localhost:8080 | admin / password |
Kali | https://localhost:7002 | kasm_user / password |
To remove containers and free space:
docker compose down
docker system prune
Category | Recommendation |
---|---|
Docker Daemon | Use TLS with client certs for remote access. Don’t expose Docker API openly. |
User Privilege | Avoid running containers as root unless required (use user: directive). |
Network | Use isolated bridge networks; limit inter-container communication if needed. |
Volume Storage | Avoid mounting sensitive host folders directly. |
Software | Periodically update Kali, Snort, and other tools inside containers. |
This testbed gives you a powerful, modular, and safe playground for training, research, and enterprise-grade pentesting. With Docker’s flexibility and Windows’ wide availability, you can create robust simulation environments without the overhead of physical labs or full-blown VMs.