我正在尝试使用本教程https://realpython.com/development-and-deployment-of-cookiecutter-django-via-docker/,将Cookie-cutter与Docker一起使用来设置Django Project。我一步一步地遵循了说明,并且能够成功运行所有命令,直到需要运行该步骤为止:docker-compose -f local.yml run django python manage.py makemigrations
。此命令给我一个错误:python: can't open file 'manage.py': [Errno 2] No such file or directory
。我在网上搜索了这个问题,问题似乎是Django项目的源文件未复制到docker的app目录中。我尝试运行以下命令来检查文件是否存在:
docker-compose -f local.yml run django sh
ls -la
确实,文件不存在,特别是manage.py
。为什么呢?我有什么想念的吗?这是屏幕截图:
这是django文件夹中Dockerfile的代码:
FROM python:3.6-alpine
ENV PYTHONUNBUFFERED 1
RUN apk update \
# psycopg2 dependencies
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql-dev \
# Pillow dependencies
&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
# CFFI dependencies
&& apk add libffi-dev py-cffi \
# Translations dependencies
&& apk add gettext \
# https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
&& apk add postgresql-client
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt
COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint
COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
local.yml:
version: '3'
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: test_local_django
depends_on:
- postgres
volumes:
- .:/app
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: test_production_postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data
- local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres