Docker-compose file says failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory, but there is a Dockerfile

I have tried looking through the forum and found these posts, 1, and others on the same problem, but there was no posted answer.

I looked through a StackOverflow post on the issue, but it is for Dockerfiles not docker-compose files. I followed the answer for this post, but it did not work.

This is what my docker-compose file looks like:

version: "3.8"
services:
  routes:
    image: golang
    container_name: "routes"
    build:
      context: ./scraper
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    depends_on:
      - scraper
    networks:
      - fullstack
  scraper:
    image: docker.io/chromedp/headless-shell:latest
    container_name: "scraper"
    build: .
    networks:
      - fullstack
  nginx:
    image: nginx
    container_name: "proxy"
    build: .
    networks:
      - fullstack

networks:
  fullstack:
    driver: bridge

This is what the Dockerfile looks like:

FROM golang:latest

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 go build -o scraper

CMD ["scraper"]

This is what my file structure looks like:
scraper
┣ Dockerfile
┣ README.md
┣ default.conf
┣ go.mod
┣ go.sum
┣ helper.go
┣ justfile
┣ main.go
┣ scraper.go
┣ server.go
┗ type.go
docker-compose.yaml

Running docker-compose up --build is what caused this error to appear and running docker-compose up results in the routes image to exit with code 0. How would I fix this issue, and is there a way to use the docker-compose file without the Dockerfile?

edit: running docker build --file Dockerfile . in the scraper directory does work.

Then first try docker compose up --build

And make sure you use an official Docker installation: Which Docker variant am I using and where is the daemon running? - DEV Community

Share which one you think you are using and how you installed it.

I got the same issue with docker compose up --build. I am running docker version 27.4.1 on docker desktop. The link you have doesn’t lead to any article.

I installed through homebrew or docker desktop. I don’t remember.

Which operating system and which terminal? Linux Shel, Powershell, CMD, bash in WSL2 or Git Bash? Or anything else?

I am on Mac M1, and I am currently using the default terminal

Then I moved the topc to the Docker Desktop category. I’m not sure the issue is related to Docker Desktop and not just compose, but untl we find out, it seemed better then “General”. Since I have Mac too, I created a smaller test project. Please, try this too

.
├── compose.yml
└── scraper
    └── Dockerfile

Compose file

services:
  test:
    build:
      context: ./scraper
      dockerfile: Dockerfile

Dockerfile

FROM ubuntu:22.04

RUN echo "HELLO"

Then run this from the root directory where the compose file is:

docker compose up --build

This is the output I got from the terminal:

WARN[0003] Found orphan containers ([routes proxy scraper]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up. 
[+] Running 1/0
 ✔ Container backend-test-1  Created                                                                                                                                       0.0s 
Attaching to test-1
test-1 exited with code 0

I have just noticed you have the build keywords for two compose services. The one I tested is the one that works, but you have no Dockerfile in the root directory. So the other service will fail.

The failing service should be shown above the error message

I commented out those services. Should I restart the docker container?

How would restarting a container solve en error during building an image? Just run what you wanted originally. But if the other image was already built properly, you don’t even need to do anything.

I am confused. Are the other services not the issue? I thought restarting the container might fix it.
If I ran what I wanted originally, which was docker compose up, I would get an exit 0 for the routes service. How would I fix that?

Thank you for the help.

exit 0 is not an error. It is a normally exiting process. That is somthing you have to figure out. Docker will not automatically keep processes alive.

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