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

如何将AWS Copilot的manifest.image.context设为项目根目录?

如何在AWS Copilot清单中正确设置image.context为项目根目录?

项目结构

- project_root
  - src
    - api.py
  - copilot
    - api
      - manifest.yaml
  - requirements.txt
  - requirements
    - base.in
    - base.txt
    - development.in
    - development.txt
    - production.in
    - production.txt
  - dockerfiles
    - api
      - Dockerfile
      - start_agent.sh
      - start_api.sh
  - docker-compose.yaml

服务Dockerfile

FROM python:3.11
RUN mkdir /app
WORKDIR /app
COPY ./requirements/ requirements
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY . /app
COPY ./dockerfiles/services/api/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chmod=755 ./dockerfiles/services/api/start_agent.sh /app/start_agent.sh
COPY --chmod=755 ./dockerfiles/services/api/start_api.sh /app/start_api.sh
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
EXPOSE 8080

原Copilot manifest.yaml配置

name: api
type: Backend Service
image:
  build: ./dockerfiles/services/api/Dockerfile
  context: .
  port: 8080
...
exec: true
network:
  connect: true

已尝试的Context值

  • "."
  • "../.."
  • "../../.."
  • "/path/to/project/repo"

执行命令

# 从project_root目录执行
copilot svc deploy --name api --env staging

错误信息

[+] Building 0.5s (14/14) FINISHED
 => [internal] load build definition from Dockerfile  
 => => transferring dockerfile: 37B
 => [internal] load .dockerignore
 => => transferring context: 2B
 => [internal] load metadata for docker.io/library/python:3.11
 => [internal] load build context
 => => transferring context: 2B
 => [ 1/10] FROM docker.io/library/python:3.11
  ...                                  
 => ERROR [10/10] COPY requirements.txt .
------
 > [10/10] COPY requirements.txt .:
------
failed to compute cache key: "/requirements.txt" not found: not found

解决方案

问题核心是Copilot中image.build路径的相对基准会随context的设置而变化:

  • 当指定context时,build路径是相对于context目录的,而非manifest文件所在目录
  • context路径本身是相对于manifest文件所在目录的

针对你的项目结构,修正manifest.yaml的image配置如下:

name: api
type: Backend Service
image:
  build: dockerfiles/services/api/Dockerfile  # 相对于context(project_root)的Dockerfile路径
  context: ../..  # 从manifest所在的copilot/api目录向上两级,指向项目根project_root
  port: 8080
exec: true
network:
  connect: true

这样配置后:

  1. Copilot会将项目根目录作为Docker构建上下文
  2. Dockerfile中的所有COPY路径(如./requirements/、requirements.txt)都能正确找到对应文件
  3. 构建上下文包含项目根下的所有必要文件,满足Dockerfile的复制需求

另外,确认项目根目录下没有.dockerignore文件排除requirements目录或requirements.txt,否则会导致文件无法被复制到构建上下文中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 22:47:49