Skip to main content

🚀 Hermes Agent + Surfshark VPN 部署與優化指南

今次成個過程由 Gemini 幫手除錯同提出解決方法,前前後後攪咗大約兩日就可以順利執行。

AI 已經變成幫你更快速完成你想要做嘅嘢嘅工具。

呢份筆記都係喺成功安裝之後,叫 Gemini 比返個紀錄我,我再做修正同 update 返啲自己試到出嚟嘅 settings。

以下係紀錄低點樣透過 Docker 建立一個受 VPN 保護嘅 Nous Research Hermes Agent,並將佢同 Open WebUI 成功對接嘅完整過程。

19/06/2026 更新

叫 Hermes Agent 自己由 v0.9.0 更新到 v0.16.0 果陣不停咁失敗,最後係放棄自訂 Dockerfile 改成直接使用官方 docker image。
將 data path 改返啱就可以用返舊 settings 同 data 照常使用。

Warning

下列內容並未更新。


🛠️ 1. 系統層級優化 (Swap)

由於 Hermes Agent 在編譯與執行 AI 任務時需要較多記憶體,若實體 RAM 不足,必須加大 Swap 空間,有必要時就用。

# 1. 停止舊 Swap
sudo swapoff -a

# 2. 建立 4GB 的 Swap 空間
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

# 3. 設定權限與格式化
sudo chmod 600 /swapfile
sudo mkswap /swapfile

# 4. 啟用 Swap
sudo swapon /swapfile

# 5. 驗證
free -h

註:如需永久生效,請在 /etc/fstab 加入 /swapfile none swap sw 0 0


📦 2. Docker 環境建置

2.1 修正版 Dockerfile

解決官方環境缺少 git 以及 Python 等依賴套件的問題。

FROM node:20-slim

# 1. 安裝系統工具與 Python (加入 python3-venv 是為了更穩定的環境)
RUN apt-get update && apt-get install -y \
    git \
    python3 \
    python3-pip \
    make \
    g++ \
    curl \
    socat \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /opt/hermes

# 2. 下載源碼
RUN git clone https://github.com/NousResearch/hermes-agent.git .

# 3. 安裝 Node.js 依賴
RUN npm install

# 4. 安裝 Python 依賴 (解決 ModuleNotFoundError: No module named 'yaml')
# 這裡直接安裝 hermes 需要的常用包,或者如果目錄下有 requirements.txt 就用它
RUN pip3 install --no-cache-dir pyyaml --break-system-packages || \
    pip3 install --no-cache-dir pyyaml

# 如果源碼中有 requirements.txt,建議也跑一次
RUN if [ -f requirements.txt ]; then pip3 install --no-cache-dir -r requirements.txt --break-system-packages; fi

# 5. 安裝 Playwright 瀏覽器
RUN npx playwright install --with-deps ffmpeg

## 5.1 安裝 Dashboard 的 dependency
RUN pip3 install --no-cache-dir ".[web]" --break-system-packages || \
    pip3 install --no-cache-dir "." --break-system-packages


# 6. 賦予權限並啟動
RUN chmod +x /opt/hermes/hermes
CMD ["python3", "/opt/hermes/hermes"]

2.2 docker-compose.yml (側車模式)

services:
  # VPN 閘道 (Surfshark)
  vpn:
    image: qmcgaw/gluetun
    container_name: hermes_surfshark_vpn
    ports:
      - 8642:8642
      - 9229:9229
    cap_add:
      - NET_ADMIN
    devices:
      - /dev/net/tun:/dev/net/tun
    environment:
      - VPN_SERVICE_PROVIDER=surfshark
      - VPN_TYPE=openvpn
      - OPENVPN_USER=surfshark_user_string  # 注意:不是登入電郵
      - OPENVPN_PASSWORD=surfshark_password_string
      - SERVER_COUNTRIES=Japan  # 或其他你喜歡的地區
    restart: always

  # Nous Research Hermes Agent
  hermes:
    build: .
    container_name: hermes_agent
    network_mode: "service:vpn" # 關鍵:共用 VPN 網絡
    depends_on:
      - vpn
    volumes:
      - ./hermes_data:/root/.hermes # 持久化存儲記憶與設定
      - ./hermes_skills:/root/.hermes/skills # skills
      - /var/run/docker.sock:/var/run/docker.sock # 若你想讓 Hermes 在宿主機啟動沙盒
    environment:
      - TERM=xterm-256color
    tty: true
    stdin_open: true
    command: sh -c  "socat TCP-LISTEN:9229,fork,reuseaddr TCP:127.0.0.1:9119 &
                     sleep 15 && python3 /opt/hermes/hermes gateway &
                     python3 /opt/hermes/hermes dashboard"
                     # socat 用作將本身只監聽 127.0.0.1:9119 嘅 dashboard,
                     # "轉駁" 到 0.0.0.0:9229 令任何 IP 都可以進入。
                     # 而 Port 9119 似乎喺 Surfshark 果邊本身己經有嘢用緊,所以轉用 9229
    restart: always

驗證指令sudo docker exec -it hermes_surfshark_vpn netstat -tulpn | grep 9229

註:由於設定咗 hermes_agent 係經由 hermes_shurfshark_vpn 容器作網絡出入口,所以檢查時係要檢查 vpn 容器而唔係 agent 容器


📡 3. 網絡與 API 連通性除錯

3.1 監聽地址 (0.0.0.0)

  • 解決:修改 hermes_data/config/.envAPI_SERVER_HOST 改為 0.0.0.0
API_SERVER_ENABLED=true
API_SERVER_KEY=********************************
API_SERVER_PORT=8642
API_SERVER_HOST=0.0.0.0
  • 驗證指令sudo docker exec -it hermes_surfshark_vpn netstat -tulpn | grep 8642

3.2 跨容器連線 (Open WebUI)

  • API URL: http://172.17.0.1:8642/v1 (使用 Docker Bridge Gateway IP)
    唔得就用 host ip http://192.168.123.456:8642/v1

🤖 4. Hermes 常用操作

  • 啟動 Hermes Agent CLI Chat mode: sudo docker exec -it hermes_agent python3 /opt/hermes/hermes
  • 設定: sudo docker exec -it hermes_agent python3 /opt/hermes/hermes setup
  • 檢查出口 IP: sudo docker exec -it hermes_agent curl https://ifconfig.me