Docker on Mac: Solving the CLI Connection Error & Understanding the 64GB VM
The Problem
You open your terminal, ready to hack, and type docker ps or try to start a container. Instead of a list of containers, you get this error:
1
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I ran into this recently while setting up my Kali Linux environment on my MacBook Pro M3. I tried to start it like a service (systemctl start docker), but that didn’t work either.
The Explanation: Mac vs. Linux
The confusion comes from how Docker works on different operating systems.
- Linux: Docker runs natively. The Docker daemon interacts directly with the Linux kernel. You can start/stop it as a system service.
- macOS & Windows: Docker cannot run natively because these OSs don’t have the Linux kernel features (cgroups, namespaces) that containers need.
To solve this, Docker Desktop creates a lightweight Linux Virtual Machine (VM) in the background.
- The
dockercommand in your terminal is just a client (remote control). - It sends commands to the daemon running inside that hidden Linux VM.
- Key Takeaway: If the Docker Desktop app isn’t running, the VM isn’t running, and your terminal has no one to talk to.
The “Scary” 64GB File
While investigating, I found a massive file that looked concerning:
1
/Users/ranger/Library/Containers/com.docker.docker/Data/vms/0/data/docker.raw
It showed a size of 64GB!
Don’t Panic
I learned that this is a Sparse File.
- 64GB is just the maximum capacity limit set by Docker.
- The actual disk space used is only what you’ve written to it (in my case, about 8GB).
- It grows as you add images/containers but won’t eat 64GB of your drive unless you actually fill it up.
The Solution
Manual Way
You must launch the Docker Desktop application before using the terminal commands.
- Press
Cmd + Space. - Type “Docker”.
- Wait for the whale icon to stop animating.
The “Ranger Way” (Automated)
I didn’t want to manually open the app and wait every time. So, I created a smart alias in my .zshrc that:
- Launches Docker Desktop.
- Waits for it to initialize (with a cool countdown).
- Automatically starts and enters my Kali Linux container.
Add this to your ~/.zshrc:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Kali Linux Docker Launcher
function kali-up() {
echo "🚀 Launching Docker Desktop..."
open -a Docker
echo "⏳ Waiting for Docker to initialize..."
# Wait loop with visual feedback (max 40s)
for i in {1..40}; do
if docker info >/dev/null 2>&1; then
echo -e "\n✅ Docker is ready!"
break
fi
echo -ne " $((40-i))s... \r"
sleep 1
done
echo "🐳 Starting Kali Container..."
# Replace 'kali-mcp' with your container name
docker start kali-mcp && docker exec -it kali-mcp bash
}
Now, I just type kali-up and I’m in.
Rangers lead the way! 🚀