Access Docker Container IPs Directly on macOS with Colima (Just Like Linux)
If you’ve ever tried to reach a container by its internal IP (like 172.17.0.2) on macOS, you’ve probably noticed it just doesn’t work —…
Access Docker Container IPs Directly on macOS with Colima (Just Like Linux)
If you’ve ever tried to reach a container by its internal IP (like 172.17.0.2) on macOS, you’ve probably noticed it just doesn’t work — even though it works perfectly on Linux.
Click this link 👇 if are not a Medium member :
Here’s why, and how to make it work cleanly using Colima.
🧠 Why It Doesn’t Work on macOS
On Linux, Docker runs natively and creates a real bridge interface (docker0) on the host.
The host can directly access container IPs such as 172.17.0.2.
On macOS, Docker (via Colima or Docker Desktop) runs inside a lightweight Linux VM.
The docker0 network exists inside that VM, not on your host — so macOS has no route to it.
In short:
macOS → Colima VM → Docker bridge → Container
Your Mac can’t see the bridge network unless we teach it how.
⚙️ Step 1 — Find Colima’s VM IP
Run:
colima ssh "ip -4 addr show col0"
You’ll get something like:
inet 192.168.106.3/24 brd 192.168.106.255 scope global dynamic col0
192.168.106.3→ IP of Colima VM192.168.106.1→ IP of your Mac on that same lin
🛠️ Step 2 — Add a Route on macOS
Tell macOS to route Docker network traffic via the Colima VM:
sudo route -n add 172.17.0.0/16 192.168.106.3
Now packets destined for 172.17.x.x will be sent to Colima.
🔁 Step 3 — Enable IP Forwarding Inside Colima
SSH into Colima:
colima ssh
Then run:
sudo sysctl -w net.ipv4.ip_forward=1
Check:
sysctl net.ipv4.ip_forward
# net.ipv4.ip_forward = 1
🌉 Step 4 — Allow Forwarding Between Interfaces
Add these iptables rules inside Colima:
sudo iptables -t nat -A POSTROUTING -s 172.17.0.0/16 -o col0 -j MASQUERADE
sudo iptables -A FORWARD -i col0 -o docker0 -j ACCEPT
sudo iptables -A FORWARD -i docker0 -o col0 -m state --state RELATED,ESTABLISHED -j ACCEPT
This allows traffic from macOS (col0) to reach containers (docker0) and back.
✅ Step 5 — Test It
From macOS:
ping 172.17.0.2
curl http://172.17.0.2
If your container runs a web service, you’ll get a direct response. No more port mappings, just pure bridge-level access.
⚡ Optional: Make It Persistent
Inside Colima:
colima ssh "sudo tee /etc/rc.local >/dev/null" <<'EOF'
#!/bin/bash
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -s 172.17.0.0/16 -o col0 -j MASQUERADE
iptables -A FORWARD -i col0 -o docker0 -j ACCEPT
iptables -A FORWARD -i docker0 -o col0 -m state --state RELATED,ESTABLISHED -j ACCEPT
EOF
colima ssh "sudo chmod +x /etc/rc.local"
Then re-add your macOS route whenever Colima starts:
sudo route -n add 172.17.0.0/16 192.168.106.3
🧩 Summary
[embed]
✅ macOS → Colima (col0) → Docker (docker0) → Container
🧠 TL;DR
# On macOS
sudo route -n add 172.17.0.0/16 192.168.106.3
# Inside Colima
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -s 172.17.0.0/16 -o col0 -j MASQUERADE
sudo iptables -A FORWARD -i col0 -o docker0 -j ACCEPT
sudo iptables -A FORWARD -i docker0 -o col0 -m state --state RELATED,ESTABLISHED -j ACCEPT
That’s it. You can now access container IPs on macOS exactly like on Linux. No port mapping, no magic — just clean routing. 🧭
✨ Bonus
You can wrap this in a small script and hook it into your colima start lifecycle for automatic setup.
👋 Wrap-up
This approach makes Colima feel native for advanced debugging, internal service communication, and observability setups — especially if you’re working on networking, Kubernetes, or multi-container environments.
🔗 Tags:
#colima #docker #devops #macos #networking #kubernetes
메타데이터
- post_id
- 39fd64f2b21d
- slug
- access-docker-container-ips-directly-on-macos-with-colima-just-like-linux-39fd64f2b21d
- url
- https://medium.com/@arjundandagi/access-docker-container-ips-directly-on-macos-with-colima-just-like-linux-39fd64f2b21d
- canonical_url
- https://medium.com/@arjundandagi/access-docker-container-ips-directly-on-macos-with-colima-just-like-linux-39fd64f2b21d
- author_url
- https://medium.com/@arjundandagi
- status
- ok
- fetched_at
- 2026-07-15 15:40:31