Building a docker image based in a DJANGO based app

Goodmorning,

I am new to the form so I hope I am in the write Toppic.

I am struggeling to get my django application project build and run on my docker desktop. I am using Windows 11 as my docker-deksktop.

I create a docker-compose file which looks like this:
services:
db:
image: postgres:latest
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE}
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- “${DATABASE_PORT}:5432”

frontend:
build:
context: .
dockerfile: dockerfile
environment:
DATABASE_USER: ${DATABASE_USER}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
DATABASE: ${DATABASE}
DATABASE_HOST: db
DATABASE_PORT: ${DATABASE_PORT}
DJANGO_SUPERUSER_USERNAME: ${DJANGO_SUPER_USER}
DJANGO_SUPERUSER_EMAIL: ${DJANGO_SUPER_EMAIL}
DJANGO_SUPERUSER_PASSWORD: ${DJANGO_SUPER_PASSWORD}
depends_on:
- db
volumes:
- .:/app
ports:
- “8000:8000”

volumes:
postgres_data:
and created a docker file which look like this:

Use Python base image

FROM python:3.10-slim

Set the working directory to /app

WORKDIR /app

Copy requirements and install dependencies

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

Copy the entire project into the container

COPY . .

Run database migration, create superuser, and start server

CMD [“sh”, “-c”, “python manage.py migrate && python manage.py createsuperuser --no-input && python manage.py runserver 0.0.0.0:8000”]

The database is created but when I want to start the fontend part i am getting the following error:
db-1 | 2024-11-25 08:54:07.494 UTC [1] LOG: database system is ready to accept connections
frontend-1 | python: can’t open file ‘/app/manage.py’: [Errno 2] No such file or directory
frontend-1 exited with code 2

When I look into the frontend container I in the woking dir /app I see a folder frontend but i don’t see the files like manage.py, wait_for_db.py. It look like that I am doing something wrong in my copy but I am running in circles and keep getting the error that Files arrend found.

Hope you can help me. Thanks in advance.
Roel Knippen

Are the dockerfile and manage.py in the same directory on your host machine?

Yes they are. My folder stcuture looks like this:
project/
├── docker-compose.yml
├── dockerfile
├── frontend/
│ ├── init.py
│ ├── pycache/
│ │ ├── init.cpython-313.pyc
│ │ ├── admin.cpython-313.pyc
│ │ ├── apps.cpython-313.pyc
│ │ ├── models.cpython-313.pyc
│ │ ├── urls.cpython-313.pyc
│ │ └── views.cpython-313.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── migrations/
│ │ ├── init.py
│ │ └── pycache/
│ │ └── init.cpython-313.pyc
│ ├── models.py
│ ├── templates/
│ │ └── frontend/
│ │ └── home.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── project/
│ ├── init.py
│ ├── pycache/
│ │ ├── init.cpython-313.pyc
│ │ ├── settings.cpython-313.pyc
│ │ ├── urls.cpython-313.pyc
│ │ └── wsgi.cpython-313.pyc
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── requirements.txt
└── wait_for_db.py

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.