1

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

enter image description here

1
  • Try: python ./<directory_in_which_manage_py_is_located>/manage.py runserver 0.0.0.0:8000. The Dockerfile and manage.py are not on the same level. Commented Nov 29, 2022 at 20:27

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Docker image is trying to find the manage.py file in root directory and your manage.py resides in proyecto directory.

In docker-compose.yml

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
    working_dir: proyecto
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    environment:
      - POSTGRES_NAME=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    depends_on:
      - db

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.