This error is caused by docker-compose
not being able to find a Dockerfile in your build context. Fix it by making sure your Dockerfile exists in that directory, and that there’s no typo in the name. It has to be named exactly “Dockerfile”.
I came across this error when while working on a guide to build a GraphQL API with FastAPI.
Here was my docker-compose.yaml
file:
services:
backend:
image: backend
build:
context: backend
args:
project-name: ${PROJECT_NAME}
volumes:
- ./backend:/opt/${PROJECT_NAME}
frontend:
image: frontend
build:
context: frontend
args:
project-name: ${PROJECT_NAME}
volumes:
- ./frontend:/opt/${PROJECT_NAME}
entrypoint: ["npm", "start"]
docker-compose.yamlAnd here was my directory structure:
See the problem? There’s no Dockerfile
in my frontend
directory, which was specified as the build context for the frontend
container here:
frontend:
image: frontend
build:
context: frontend
args:
project-name: ${PROJECT_NAME}
volumes:
- ./frontend:/opt/${PROJECT_NAME}
entrypoint: ["npm", "start"]
Adding the Dockerfile to the directory fixed the issue. Keep in mind, the same error will occur if you don’t capitalize the “D” in “Dockerfile”, or if you misspell it. It has to be named exactly “Dockerfile”.
Hope that helps.
John is a professional software engineer who has been solving problems with code for 15+ years. He has experience with full stack web development, container orchestration, mobile development, DevOps, Windows and Linux kernel development, cybersecurity, and reverse engineering. In his spare time, he’s researching the potential business applications of AI.