Skip to content

Instantly share code, notes, and snippets.

@Wemmy0
Created April 9, 2025 23:32
Show Gist options
  • Save Wemmy0/d13f8e891d40167e2b700036a50f29e2 to your computer and use it in GitHub Desktop.
Save Wemmy0/d13f8e891d40167e2b700036a50f29e2 to your computer and use it in GitHub Desktop.
Tutorial on how to get a kali linux container set up for pen testing
# kali linux docker container
alias kali='docker start kali > /dev/null && docker attach kali'
alias re-kali='echo "Creating new kali container...\nYou might want to run de-kali to remove old instances" && cd ~/kali && docker compose up -d'
alias de-kali='echo "Removing old kali instances..." && cd ~/kali && docker compose down --volumes --remove-orphans'

This guide details how to get a kali linux docker container set up with the full kali linux tool suite. It can be

There might be a better way of doing this, but this is pretty rock solid and just requires docker and zsh

Usage

kali starts and attaches to the already existing docker container re-kali (re)creates the container using docker compose de-kali deletes ALL existing kali instances You can use a simple docker rm to remove individual instances

Setting up the kali image

  1. Docker pull the kali linux image
  2. Start the docker container like normal with an interactive bash shell
  3. Run sudo apt install kali-linux-large to download the kali tool suite (~11 GB)
  4. IMPORTANT: Setup a new account (I called mine kali, creative I know) with the SAME uid and gid as your host user otherwise you'll get issues with permissiones on shared volumes.
  5. ALSO: Set a password for both your root and kali accounts. Make sure to add your new user to the sudo group
  6. Exit out and stop the container. Then use docker commit to save the container volume as an image
  7. In your home directory, create a kali folder and put the docker-compose.yml inside there
  8. Copy the aliases into your .zshrc file then use source ~/.zshrc or restart your terminal
  9. Call re-kali then kali and you should have a kali container to start failing at HTB machines with!

Extra bits

If your fancy you can also set the new users home directory as the volume directory but that requires a bit of fiddling with moving all current files intop the data folder, modifying the compose file and finally re-committing the image again

services:
kali:
image: kali-complete
container_name: kali
stdin_open: true
tty: true
cap_add:
- NET_ADMIN
- NET_RAW
user: "1000:1000"
group_add:
- "27"
volumes:
- ./data:/home/kali/data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment