Docker compose up -d --build -> Error: failed to read dockerfile

I’m getting an error trying to use docker compose up with the error failed to read dockerfile: open Dockerfile: no such file or directory

Here is the command I am running:

docker compose up -d --build

Here is the docker-compose.yml file that I am using:

services:
  django:
    container_name: django
    build:
      context: ./dcelery
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./dcelery:/usr/src/app/
    ports:
      - 8001:8000
    environment:
      - DEBUG=1
      - SECRET_KEY=34lkj2345lkj5lk5jl35j2l5j
      - ALLOWED_HOSTS=localhost, 127.0.0.1

The Dockerfile is in the same folder as the docker-compose.yml file and I am running the command from that folder. I had seen suggestions to use the -f argument, but I get the error unknown shorthand flag: ‘f’ in -f.

Any ideas on why I would be getting this error. It seems pretty basic that the Dockerfile is in the same folder as the docker-compose.yml file, yet it can’t find it.

Thanks in advance for any help.

1 Like

This:

and this:

Don’t work like this. Either the Dockerfile must be in the root of whatever you specify as context, e.g. ./decelery/Dockerfile, or you need to specify the dockerfile relative to the build context, see: https://docs.docker.com/reference/compose-file/build/#dockerfile.

Thanks for the response. I’m a bit confused by it though. I mentioned that the Dockerfile is in the same folder, so it IS in the ./dcelery folder, i.e. ./dcelery/Dockerfile.

Are you also suggesting that I should add the line…

dockerfile: Dockerfile

I thought if the filename was Dockerfile then you wouldn’t need to specify it.

Thanks!

Please share the layout of your directory structure, starting from the folder where the docker-compose.yml is located you shared earlier. Things don’t add up.

Here is the directory structure…

So, just following up on this one.

As you can see from the earlier screen capture, the docker-compose.yml file is in the same directory where the Dockerfile is located. If I’m running the yml file and the Dockerfile is in that same directory, why would I be getting Dockerfile: no such file or directory. This doesn’t make sense, and this is a very simple example.

Any help would be greatly appreciated as I am currently stuck on this step.

Thanks!

@meyay answered your question already.

yet your screenshot shows it is not there. You have two folders with the same name. One is your project folder, the other is the context folder. Since you specified in the compose yaml that your context is ./dcelery, it is relative to your compose file and you haven’t shown the content of that folder only where the yaml is. You can probably remove the context definition and just use build: . or just replace the fodler name with a dot: context: . as it seems your source code is also in the same folder as your compose file. If your source code is in the same folder as your yaml, outside the context, you wouldn’t be able to use those in a Dockerfile so you would have another error message next even if you define the dockerfile parameter.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.