执行Docker Compose命令时Dockerfile-dev找不到错误的解决方法
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, runningdocker-compose -f docker-compose-dev.yml upwill use your current folder as thecontext(notdebug_project), so Docker can’t find the file insidedebug_project.
Fix this by either:
- Navigating directly to
debug_projectfirst:cd debug_projectthen run yourdocker-composecommand - Or, update the
contextin yourdocker-compose-dev.ymlto the absolute path ofdebug_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-devfile in that location - Adjust the
dockerfilepath 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

