Localhost Bridge
/install localhost-bridge
localhost-bridge — Connect containers to host localhost services
⚠️ Security & Privileges
This skill requires host-level privileges. It must be reviewed and executed manually by an administrator — never autonomously by an agent.
What it does on the host:
- Creates a systemd service (persistent across reboots) that forwards traffic from a Docker bridge IP to localhost
- Adds a UFW firewall rule scoped to a specific Docker bridge interface
- Requires sudo, Docker daemon access, and socat from your distro's official package repository
Before running any command:
- Review the generated
/etc/systemd/system/socat-\x3CSOURCE_NETWORK>-\x3CTARGET_SERVICE>-\x3CPORT>.servicefile — confirmExecStartbinds only to the intended Docker bridge IP (172.x.x.1), never 0.0.0.0 - Review the UFW rule — confirm it targets the correct
br-\x3CID>interface and port - After setup, verify the port is NOT reachable from the public network:
curl --connect-timeout 2 http://\x3CPUBLIC_IP>:\x3CPORT>/must fail - Test from inside a container before deploying widely
Do not grant an automated agent permissions to run these commands without human approval.
The Problem
A service on the host listens on 127.0.0.1 (AI gateway, MCP server, Ollama, database...). A Docker container needs to reach it. localhost inside the container points to the container itself, not the host. Requests either timeout silently (firewall drops packets) or get connection refused.
The Solution
socat listens on the Docker bridge gateway IP and forwards to host loopback. Combined with a scoped firewall rule, this gives containers access without exposing the service externally.
Setup (run manually as admin)
1. Find the Docker bridge gateway IP
# For a specific container
docker inspect \x3Ccontainer_name> --format '{{json .NetworkSettings.Networks}}' \
| python3 -c "
import json,sys
d = json.load(sys.stdin)
for net, info in d.items():
print(f'{net}: gateway={info[\"Gateway\"]}')"
2. Create a systemd service
Replace \x3CGATEWAY_IP>, \x3CPORT>, \x3CSOURCE_NETWORK>, and \x3CTARGET_SERVICE> with your values.
Naming convention: socat-\x3Csource_network>-\x3Ctarget_service>-\x3Cport> — source network is the Docker network (consumer), target service is the host service. Self-documenting.
Examples: socat-bridge-gateway-18789, socat-windmill_default-gateway-18789, socat-bridge-ollama-11434
Review the ExecStart line before enabling — confirm it binds to the Docker bridge IP only.
sudo tee /etc/systemd/system/socat-\x3CSOURCE_NETWORK>-\x3CTARGET_SERVICE>-\x3CPORT>.service > /dev/null \x3C\x3C 'EOF'
[Unit]
Description=Socat bridge: \x3CSOURCE_NETWORK> -> \x3CTARGET_SERVICE>:\x3CPORT>
After=network.target docker.service
[Service]
Type=simple
ExecStart=/usr/bin/socat TCP-LISTEN:\x3CPORT>,bind=\x3CGATEWAY_IP>,fork,reuseaddr TCP:127.0.0.1:\x3CPORT>
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# Review the file before enabling:
cat /etc/systemd/system/socat-\x3CSOURCE_NETWORK>-\x3CTARGET_SERVICE>-\x3CPORT>.service
sudo systemctl daemon-reload
sudo systemctl enable --now socat-\x3CSOURCE_NETWORK>-\x3CTARGET_SERVICE>-\x3CPORT>
3. Add firewall rule (MANDATORY)
Without this, socat listens but packets from the container are silently dropped — causing 30-second timeouts with no error.
Review the bridge ID before applying — a wrong ID can expose services.
# Find the Linux bridge interface for the Docker network
BRIDGE_ID=$(docker network inspect \x3Cnetwork_name> --format '{{.Id}}' | cut -c1-12)
# Verify this is the right bridge
ip link show br-${BRIDGE_ID}
# Allow traffic only on that bridge interface
sudo ufw allow in on br-${BRIDGE_ID} to any port \x3CPORT> proto tcp comment "\x3CSOURCE_NETWORK>-\x3CTARGET_SERVICE>-\x3CPORT>"
4. Verify security
# MUST succeed (from inside a container)
docker exec \x3Ccontainer_name> curl -s --connect-timeout 5 http://\x3CGATEWAY_IP>:\x3CPORT>/
# MUST fail (from the public network)
curl --connect-timeout 2 http://\x3CPUBLIC_IP>:\x3CPORT>/
Multi-Network Workers
A container can be on multiple Docker networks. Each has its own bridge IP. You need a socat instance + firewall rule for each network the container uses. In practice, one network is usually enough.
Check all networks: docker inspect \x3Ccontainer> --format '{{json .NetworkSettings.Networks}}'
Common Use Cases
| Host service | Container client | Default port |
|---|---|---|
| AI gateway (OpenClaw, LiteLLM) | Workflow orchestrator (Windmill, n8n) | 18789 |
| MCP server | Dockerized agent | varies |
| Ollama | RAG pipeline, agent | 11434 |
| PostgreSQL | API server | 5432 |
| Redis | Any containerized app | 6379 |
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| 30s timeout, no error | Firewall dropping packets | Add UFW rule on the bridge interface |
| Connection refused | socat not running | systemctl status socat-\x3CSOURCE_NETWORK>-\x3CTARGET_SERVICE>-\x3CPORT> |
| Works then stops after Docker restart | Bridge IP changed | Check new gateway IP, update socat bind |
| socat won't start after reboot | Docker not ready | Ensure After=docker.service in unit file |
Alternatives
Depending on your security posture, consider:
- Docker host networking (
network_mode: host) — simpler but removes all container network isolation - Running socat inside a minimal privileged container — avoids host-level systemd changes
- Configuring the host service to bind to the Docker bridge IP directly — no socat needed, but the service must support custom bind addresses
host.docker.internal(Docker Desktop) — works on Mac/Windows, not reliably on Linux
Prerequisites
Install socat from your distro's official package repository:
sudo apt-get install -y socat # Debian/Ubuntu
sudo dnf install -y socat # Fedora/RHEL
References
- Blog post: The Localhost Trap — why this problem exists and why it matters for AI infrastructure
- Source: Casys-AI/casys-pml-cloud
- Docker docs: Packet filtering and firewalls
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install localhost-bridge - 安装完成后,直接呼叫该 Skill 的名称或使用
/localhost-bridge触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
Localhost Bridge 是什么?
Bridge Docker containers to host localhost services via socat. Solves the #1 networking issue in containerized AI agent deployments: containers can't reach s... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 504 次。
如何安装 Localhost Bridge?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install localhost-bridge」即可一键安装,无需额外配置。
Localhost Bridge 是免费的吗?
是的,Localhost Bridge 完全免费(开源免费),可自由下载、安装和使用。
Localhost Bridge 支持哪些平台?
Localhost Bridge 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Localhost Bridge?
由 Erwan Lee Pesle(@superworldsavior)开发并维护,当前版本 v2.0.0。