You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用docker-compose部署LangGraph时无法找到agent.py文件的问题

Docker-Compose部署LangGraph Agent路径错误排查方案

问题概述

使用docker-compose部署LangGraph Agent(搭配langgraph-api、Redis、PostgreSQL)时,langgraph build -t aa-image和langgraph-dev执行正常,但启动容器时出现错误:

找不到文件'/deps/__outer_src/src/agent\agent.py'

项目结构包含:.env、langgraph.json、docker-compose.yml、src/agent/agent.py,尝试将源码移至根目录未解决问题。

排查与解决步骤

1. 统一路径分隔符

错误路径中同时出现正斜杠和反斜杠(src/agent\agent.py),属于跨平台路径解析问题。检查langgraph.json的entrypoint配置,确保全程使用正斜杠:

{
  "entrypoint": "src/agent/agent.py",
  // 其他配置项
}

2. 修正Docker卷挂载映射

检查docker-compose.yml中的卷挂载规则,确保本地代码目录正确映射到容器内的/deps/__outer_src:

services:
  langgraph-api:
    image: aa-image
    volumes:
      # 本地当前目录映射到容器内的/deps/__outer_src
      - ./:/deps/__outer_src
    env_file: .env
    depends_on:
      - redis
      - postgres
  # Redis、PostgreSQL配置保持原有逻辑

3. 确保构建上下文包含源码

执行langgraph build时,明确指定当前目录为构建上下文,避免遗漏源码文件:

langgraph build -t aa-image .

4. 清理缓存与旧镜像

Docker缓存可能保留错误的路径配置,清理后重新构建:

# 删除旧镜像
docker rmi aa-image
# 清理无用容器、镜像、缓存
docker system prune -f
# 重新构建并启动
langgraph build -t aa-image
docker-compose up --build

内容的提问来源于stack exchange,提问作者Lovro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 09:24:55