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

Dockerfile中ADD与COPY命令失效问题求助

Troubleshooting Missing Files in Heroku Docker Container

Let’s break down the common issues that cause files copied via COPY/ADD to disappear in Heroku’s container environment, plus actionable fixes to resolve them:

  • Set your working directory explicitly
    Heroku defaults to /app as the container’s working directory, but declaring this at the top of your Dockerfile eliminates relative path confusion. Add this line before any COPY/ADD commands:

    WORKDIR /app
    

    Now all subsequent copy commands will target /app by default. For example, COPY . . copies everything from your local project root into /app—exactly the directory you land in when running heroku run bash.

  • Audit your .dockerignore file
    This is one of the most overlooked culprits. If your .dockerignore lists the files/directories you’re trying to copy (e.g., luup/, config/, or even a misplaced .), Docker will skip copying them entirely. Open your .dockerignore and remove any lines that exclude the content you need in the container.

  • Validate your COPY syntax with the working directory
    With WORKDIR /app set, use clean, reliable syntax:

    • Copy your entire local project to /app: COPY . .
    • Copy the local luup directory to /app/luup: COPY luup ./luup/
    • Copy requirements.txt directly to /app: COPY requirements.txt .
      Stick to relative paths here—absolute paths are unnecessary and can introduce unexpected behavior.
  • Test locally first to rule out Heroku-specific issues
    Before deploying, build and run your image locally to confirm files are present:

    # Build the image
    docker build -t my-heroku-app .
    # Run a temporary container and open bash
    docker run -it --rm my-heroku-app bash
    

    If files are missing locally, the problem is in your Dockerfile or build context—not Heroku. If they’re present locally but missing on Heroku, double-check that you’re pushing the correct image tag to Heroku.

  • Check Heroku’s build logs
    When you run heroku container:push web, scan the logs for lines related to COPY commands. You should see entries like:

    Step 5/10 : COPY . .
    ---> Using cache
    ---> abc123def456
    

    If these lines are missing or show errors (e.g., "no such file or directory"), your files aren’t available in the build context when Heroku processes your image.

  • Don’t overwrite /app later in your Dockerfile
    Ensure you don’t have commands that delete or replace the /app directory after copying files. For example, a RUN rm -rf /app or VOLUME /app command would wipe out your copied content.

If you’ve tried all these steps and still have issues, sharing your full Dockerfile and .dockerignore content can help pinpoint the problem.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:39:49