How to run Docker on Kali - kdaisho/Blog GitHub Wiki

Setting Up Docker in Kali Linux Using Nix

Steps to Run Docker in Kali:

  1. Install Docker with Nix:

    • Add pkgs.docker_26 to home.packages in home.nix
  2. Configure secure_path in sudoers: This is needed as I installed the docker using nix which defaults to user-level installation, but docker has to run with sudoer privilege.

    • To ensure sudo can access your Nix binaries, edit the sudoers file using visudo:
      sudo visudo
      
    • Add /home/kali/.nix-profile/bin/ to the secure_path:
      Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/kali/.nix-profile/bin"
      
  3. Start the Docker Daemon:

    • To run the Docker daemon (dockerd), execute the following command:
      dockerd --host=unix:///var/run/docker.sock
      
    • This will start the Docker daemon and make it accessible through /var/run/docker.sock.
  4. Fix docker.sock Permissions (if necessary--I didn't do this):

    • If you encounter permission errors for docker.sock, you may need to change the permissions or add your user to the docker group:
      sudo usermod -aG docker $USER
      
  5. Verify Docker Installation:

    • After starting dockerd, check the Docker installation with:
      docker ps
      
  6. Final Result:

    • Docker should now be set up and ready to use. You can use Docker commands both with and without sudo, depending on your configuration.

Future Notes:

  • When using Nix for package management, binaries are located in /home/kali/.nix-profile/bin/. Ensure that secure_path is updated in sudoers so that sudo can find these binaries.
  • Always use visudo to safely edit the sudoers file to avoid breaking your system.
  • To run Docker as a non-root user, make sure you're added to the docker group or use the rootless Docker setup.