我是Docker的新手,正在尝试使用Django部署django项目。但是在构建docker-compose之后,我得到了这个错误:
错误:无法打开需求文件:[Errno 2]没有此类文件或 目录:“ requirements.txt”错误:服务“网络”生成失败: 命令'/ bin / sh -c pip install -r requirements.txt'返回了 非零代码:1
我可能会设置正确的路径,所以这是我的项目结构
~/Desktop/Projects/ToDoApp
ToDoApp
settings.py
docker-compose.yml
Dockerfile
manage.py
requirements.txt
这是我的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"]
这是我的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
答案 0 :(得分:1)
我看到了几个问题:
ToDoApp/ToDoApp
的文件,甚至不会创建子目录。 生成的Dockerfile如下:
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"]
答案 1 :(得分:0)
尝试一下:
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"]