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

执行Docker Compose命令时Dockerfile-dev找不到错误的解决方法

Fixing "Cannot locate specified Dockerfile: Dockerfile-dev" Error in Docker Compose

Looks like Docker Compose can’t find your Dockerfile-dev file—let’s walk through the most common fixes step by step:

1. Double-check the Dockerfile’s Name & Path

First, confirm the file actually exists in your project, and watch out for case sensitivity (critical on Linux/macOS). Dockerfile-dev is not the same as dockerfile-dev or Dockerfile-Dev.

Next, open your docker-compose-dev.yml and look at the build section for your service. It should look something like this if you’re specifying a custom Dockerfile:

services:
  your-app-service:
    build:
      context: .  # This is the root directory Docker uses for building
      dockerfile: Dockerfile-dev  # Path relative to the context

If Dockerfile-dev is in a subdirectory (like ./docker), update the dockerfile path to match: dockerfile: docker/Dockerfile-dev.

2. Verify Your Working Directory When Running Commands

If you’re executing docker-compose from outside your debug_project root folder, you might be pointing to the wrong context. For example:

  • If you’re in debug_project’s parent folder, running docker-compose -f docker-compose-dev.yml up will use your current folder as the context (not debug_project), so Docker can’t find the file inside debug_project.

Fix this by either:

  • Navigating directly to debug_project first: cd debug_project then run your docker-compose command
  • Or, update the context in your docker-compose-dev.yml to the absolute path of debug_project, or a path relative to where you’re running the command.

3. Fix Your Compose Build Configuration

If your build section is just a single string (e.g., build: .), Docker will default to looking for a file named Dockerfile—not Dockerfile-dev. You need to explicitly define the custom Dockerfile name:

❌ Wrong:

services:
  your-app-service:
    build: .  # Defaults to looking for Dockerfile

✅ Correct:

services:
  your-app-service:
    build:
      context: .
      dockerfile: Dockerfile-dev

4. Confirm the File Exists in the Context Directory

Open your terminal, switch to the directory specified by context in your compose file, and run:

  • Linux/macOS: ls -l Dockerfile-dev
  • Windows (Command Prompt): dir Dockerfile-dev

If the output says the file doesn’t exist, you’ll need to either:

  • Create the Dockerfile-dev file in that location
  • Adjust the dockerfile path in your compose config to point to where the file actually lives

If none of these steps resolve the issue, share your debug_project directory structure (e.g., output from the tree command) and the full content of your docker-compose-dev.yml—that’ll help pinpoint the exact problem.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:30:29