Reputation: 405
I am new to Docker and trying to deploy a django project with the same. But after building the docker-compose I am getting this error:
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt' ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
I might be messing up in setting the correct path so here is my project structure
~/Desktop/Projects/ToDoApp
ToDoApp
settings.py
docker-compose.yml
Dockerfile
manage.py
requirements.txt
Here is my dockerfile
#pull official base image
FROM python:3
#set envionment variables
ENV PYTHONUNBUFFERED 1
# Adding requirements file
ADD requirements.txt ToDoApp/ToDoApp
#set work directory
WORKDIR /ToDoApp
#install dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
CMD ["python", "./ToDoApp/manage.py runserver 0.0.0.0:8000"]
and this is my docker-compose.yml
version: '3'
services:
web:
build: .
command: python /ToDoApp/manage.py runserver 0.0.0.0:8000
volumes:
- .:/Desktop/Projects/ToDoApp
ports:
- "8000:8000"
environment:
- SECRET_KEY = please_change_me
Upvotes: 4
Views: 24482
Reputation: 264986
Several issues I'm seeing:
ToDoApp/ToDoApp
, it doesn't even create a sub directory. The resulting Dockerfile looks like:
FROM python:3
#set envionment variables
ENV PYTHONUNBUFFERED 1
# run this before copying requirements for cache efficiency
RUN pip install --upgrade pip
#set work directory early so remaining paths can be relative
WORKDIR /ToDoApp
# Adding requirements file to current directory
# just this file first to cache the pip install step when code changes
COPY requirements.txt .
#install dependencies
RUN pip install -r requirements.txt
# copy code itself from context to image
COPY . .
# run from working directory, and separate args in the json syntax
CMD ["python", "./manage.py", "runserver", "0.0.0.0:8000"]
Upvotes: 11
Reputation: 141
Try this:
FROM python:3
#set envionment variables
ENV PYTHONUNBUFFERED 1
#set work directory
WORKDIR /ToDoApp
# Adding requirements file
ADD requirements.txt /ToDoApp/
#install dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
CMD ["python", "./ToDoApp/manage.py runserver 0.0.0.0:8000"]
Upvotes: 0