i am deploying to docker compose django with postgrest but the problem i have is when trying to deploy an app to django as i get the following output.
[ ] Running 1/0 ⠿ Container proyecto-db-1 Running
0.0s python: can't open file '/code/manage.py': [Errno 2] No such file or directory asterisk@localhost:~/Documentos/Programacion/django/Proyecto>
I get this output by implementing the following code:
docker compose run web python manage.py startapp aplicacion
docker compose run web django-admin startproject proyecto
the docker-compose.yml is:
version: '3.9'
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
environment:
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
depends_on:
- db
The Dockerfile is:
# syntax=docker/dockerfile:1
FROM python:3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
requirements.txt:
Django>=3.0,<4.0
djangorestframework==3.13.1
psycopg2>=2.8
and .env is:
## do not put this file under version control!
SECRET_KEY='c_r-e8v1divj8y hu@-w=n#$xj#ciuejybd3_(k2h789(mcv8$'
DEBUG=False
## Super-User Credentials
SUPER_USER_NAME = 'root'
SUPER_USER_PASSWORD = 'root'
SUPER_USER_EMAIL = '[email protected]'
There is the manage.py file
CodePudding user response:
Your docker image root and manage.py are not in the same directory. The image root is one level above.
Try: python ./<directory_in_which_manage_py_is_located>/manage.py runserver 0.0.0.0:8000
in your docker-compose.yml
file.