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

构建Docker镜像时遇文件/目录不存在错误,请求协助

Troubleshooting Docker COPY Failed Error for Nginx Web Server

Alright, let's figure out why your Docker COPY command is failing and get it fixed. The error message clearly states Docker can't locate /fecode/dist in the ams-fe build stage or image—here are the most likely reasons and step-by-step checks to resolve this:

1. Verify the ams-fe build stage actually generates /fecode/dist

The --from=ams-fe flag pulls files from a previous build stage (defined with AS ams-fe in your Dockerfile) or a pre-existing image. First, confirm this stage is properly creating the dist directory:

  • Check your Dockerfile for the ams-fe stage definition. It should look something like this (adjust based on your frontend stack):
    FROM node:18 AS ams-fe
    WORKDIR /fecode  # Sets the working directory to /fecode
    COPY package*.json ./
    RUN npm install
    COPY . .
    RUN npm run build  # This command should generate the dist folder
    
  • Ensure the build command (like npm run build) actually runs successfully and outputs the dist directory into /fecode. If this command fails silently or outputs to a different path, the dist folder won't exist where Docker expects it.

2. Double-check the path in the COPY command

It’s easy to mix up paths. Here’s how to confirm:

  • Temporarily add a debug step to your ams-fe stage to list the contents of /fecode:
    RUN ls -la /fecode  # Add this right after your build command
    
  • Rebuild the image and look at the output—you should see the dist directory listed. If it’s missing, your build command isn’t generating it. If it’s in a different location (like /dist instead of /fecode/dist), update your COPY command to match the correct path.

3. Confirm the build stage name is correct

Docker is case-sensitive when referencing build stages. Make sure:

  • The name in COPY --from=ams-fe exactly matches the AS ams-fe definition in your Dockerfile. For example, if you wrote AS ams_fe (underscore instead of hyphen), the COPY command will fail because it can’t find the stage.

4. Rule out Docker cache issues

Sometimes Docker uses cached build stages, which might skip steps that generate the dist directory. Try rebuilding with no cache to force a fresh build:

docker build --no-cache -t project/test:v1 .

5. Test the ams-fe stage independently

To isolate the problem, build just the ams-fe stage and inspect it directly:

# Build only the ams-fe stage
docker build --target ams-fe -t ams-fe-test .

# Run a temporary container to check for the dist directory
docker run --rm -it ams-fe-test ls /fecode/dist

If this command returns "No such file or directory", you know the issue is entirely within the ams-fe stage—focus on fixing the build steps there to generate the dist folder.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:38:58