Cannot start container with docker compose up

Advertisements

I am trying to Dockerize an application and it’s my first time. Have a Docker file inside the working directory:

# syntax=docker/dockerfile:1
FROM ubuntu:22.04

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /

RUN apt-get update && apt-get install -y python3.10 python3-pip
RUN apt-get update && apt-get install -y git
RUN apt-get update && apt-get install -y libpq-dev python3-dev


COPY requirements.txt .

RUN pip install -r requirements.txt

COPY . .

and I have this docker-compose.yml file:

version: "1.1"

services:
  db:
    image: postgres:15-alpine
    volumes:
      - ./db:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
  backend:
    build: /
    ports:
      - "8000:8000"
    volumes:
      - ./:/backend
    env_file: .env
    command: python manage.py runserver 0.0.0.0:8000
    depends_on:
      - db
    restart: on-failure
  frontend:
    build: frontend/
    ports:
      - "3000:3000"
    volumes:
      - ../frontend/src:/frontend/src
    environment:
      - CHOKIDAR_USEPOLLING=true
    command: npm run dev
    depends_on:
      - backend

Every time I try and run docker compose build or docker compose up I get the following error:

failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount3961901539/Dockerfile: no such file or directory

Why is it looking for the Dockerfile in that location if it is right here in the WORKDIR?

Is there a way to clear it and just start over with the dockerfile in the current directory?

>Solution :

For your backend service, you’re telling docker compose that the dockerfile is in the root directory with

build: /

It should be in the current directory, so change it to

build: .

Leave a ReplyCancel reply