Unfortunately Kali devs only offer a docker container for amd64 architecture. That means if you want to run a Kali container in a Raspberry or any other ARM system that won't be possible.
I opened an issue in the Kali official repo, but I got no answer so far. Maybe I didn't open it in the right repo. In any case, all that was left to us was to build our own container. We'll be using the same steps the official docker images follows and the scripts used here are a slightly modified version of the originals.
Note that the building process bellow was created having Android in mind, meant to be executed inside the Termux app. You'll also need to already have docker running in your phone, since an auxiliary Ubuntu container will be used.
The first step is to create the minimal rootfs. This step will be executed inside an Ubuntu container, because running debootstrap directly on Termux would involve some additional steps and extra configuration.
Start the container with a shared volume with the host:
$ sudo docker run \
-it \
--rm \
-w /root \
-v $TMPDIR/docker-share:/root/docker-share \
ubuntu
This will start a container with the same architecture of your phone. If instead, you have a 64 bit system and want to build a 32 bit Kali image, you can start a 32 bit Ubuntu container using the command bellow:
$ sudo docker run \
-it \
--rm \
-w /root \
-v $TMPDIR/docker-share:/root/docker-share \
--platform=linux/arm \
arm32v7/ubuntu
Now from within the container install the prerequisite tools and build the rootfs:
# echo 'APT::Sandbox::User "root";' > /etc/apt/apt.conf
# apt update
# apt install debootstrap wget binutils xz-utils
# wget https://gist.githubusercontent.com/FreddieOliveira/634354725b5c32b214292cf5402ca214/raw/3020ff7f3f7ce5250c3f1461041ab2a08b8e72d7/build-rootfs.sh
# wget https://http.kali.org/pool/main/k/kali-archive-keyring/kali-archive-keyring_2020.2_all.deb
# ar x kali-archive-keyring_2020.2_all.deb
# tar xf data.tar.xz -C /
# chmod +x build-rootfs.sh
# ./build-rootfs.sh
If everything went well, a kali-rolling.tar.xz
file should exist in the working directory. Just copy it to the shared volume (cp kali-rolling.tar.xz ~/docker-share
) so we can use it from outside the container to finish the process. You can now exit from the container and it will be automatically deleted.
Note: if you're getting the
Required key not available
error when copying the kali-rolling.tar.xz file to the shared volume, check here on how to proceed.
Now that we have the compressed rootfs, it's just a matter of building the docker image with it. Inside Termux terminal let's structure the working directory and run the docker-build.sh
script:
$ sudo mkdir -p $TMPDIR/docker-share/kali-image
$ cd $TMPDIR/docker-share/kali-image
$ sudo mv ../kali-roling.tar.xz .
$ sudo wget https://gist.githubusercontent.com/FreddieOliveira/634354725b5c32b214292cf5402ca214/raw/3020ff7f3f7ce5250c3f1461041ab2a08b8e72d7/Dockerfile
$ sudo wget https://gist.github.com/FreddieOliveira/634354725b5c32b214292cf5402ca214/raw/3020ff7f3f7ce5250c3f1461041ab2a08b8e72d7/docker-build.sh
$ sudo chmod +x docker-build.sh
$ sudo ./docker-build.sh
And that's it. The image should've been created and stored under /data/docker/lib/docker
(or whatever directory you configured it). You can now delete the $TMPDIR/docker-share/kali-image
dir if desired.
Running sudo docker image ls
shows the newly created image:
REPOSITORY TAG IMAGE ID CREATED SIZE
kalilinux/kali-rolling 2021-01-25 1f1a7238f21e 2 minutes ago 135MB
You can chage the metadata like REPOSITORY, TAG, etc by modifying the docker-build.sh
before running it to build the image.
To run a container of your image use REPOSITORY:TAG
:
$ sudo socker run -it kalilinux/kali-rolling:2021-01-25
or the IMAGE ID
:
$ sudo docker run -it 1f1a7238f21e