1

I run docker-compose build command to set up the environment. But I had a following error.


=> ERROR [3/5] COPY ../requirements.txt /code/
failed to compute cache key: "/requirements.txt" not found: not found
ERROR: Service 'web' failed to build : Build failed

What is the problem here. My folder structure is wrong ?

.
├── backend/
│   └── api/
│       ├── __init__.py
│       ├── main.py
│       └── Dockerfile
├── .dockerignore
├── docker-compose.yml
└── requirements.txt

This is the Dockerfile in backend folder

FROM python:3.10.8-slim-buster

WORKDIR /code

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

COPY ../requirements.txt /code/

RUN pip3 install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./api /code/api

CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "80"]

This is the docker-compose.yml in root directory

version: "3.8"

services:
  web:
    container_name: "sukeba_api"
    build: ./backend
    volumes:
      - ./backend/api:/code/api
    ports:
      - "8000:80"
    depends_on:
      - db
  db:
    image: postgres:latest
    container_name: "sukeba_db"
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=sukeba

volumes:
  postgres_data:

I changed the folder structure but it dindt work.

Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53
  • 1
    The issue here is that you're trying to copy a file from a parent directory. See [this answer](https://stackoverflow.com/a/34300129/11612918) – M.O. Feb 17 '23 at 08:17
  • I might move the `Dockerfile` up to the top-level directory next to `docker-compose.yml`, and change the `build:` context dixectory to match, and make the paths in the Dockerfile consistent with that. – David Maze Feb 17 '23 at 11:29

0 Answers0