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

基于AWS Lambda Node镜像构建Docker镜像时遇COPY指令错误求助

问题解决:Docker COPY多文件时目标必须为目录并以/结尾

错误原因

你遇到的错误When using COPY with more than one source file, the destination must be a directory and end with a /,是因为Docker的COPY指令在复制多个源文件时,必须明确指定目标为目录(通过路径末尾加/),否则Docker会将目标当作单个文件处理,这与复制多个文件的需求冲突。

修改后的Dockerfile

只需在${LAMBDA_TASK_ROOT}末尾添加斜杠即可:

FROM public.ecr.aws/lambda/nodejs:14

# Assumes your function is named "app.js", and there is a package.json file in the app directory 
COPY app.js package.json  ${LAMBDA_TASK_ROOT}/

# Install NPM dependencies for function
RUN npm install

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ]  

补充说明

  • AWS Lambda的Node.js基础镜像已预定义${LAMBDA_TASK_ROOT}环境变量,指向Lambda函数代码的存放目录,无需担心路径不存在的问题。
  • 添加/后,Docker会将app.js和package.json都复制到该目录下,完全匹配你的需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 09:54:18