Docker Container Running But it throws the error Template does not Exist
Hi I'm New In Docker I Have Created A Django Application Its Running in Local machine Good But When I try To run In docker Container its Run Properly But When I sent Request The Found The Error Template Does Not Exist
Dockerfile
#syntax=docker/dockerfile:1
#FROM ubuntu:latest
FROM ubuntu:latest
FROM python:3.8-slim-buster
WORKDIR /app
#COPY requirements.txt requirements.txt
#RUN pip3 install -r requirements.txt
#
#CMD python . /manage.py runserver 0.0.0.0:8000"""
# pull the official base image
# set work directory
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN apt-get update&& \
apt-get -y install sudo
RUN apt-get install -y tesseract-ocr
RUN apt-get install -y build-essential libpoppler-cpp-dev pkg-config python-dev mupdf
RUN apt-get install ffmpeg libsm6 libxext6 -y
RUN apt-get install -y default-jre
RUN apt-get install -y default-jdk
RUN apt-get update
RUN apt-get install -y python3-pip
RUN pip3 install --upgrade pip
#RUN pip3 install virtualenv
#RUN python3 -m virtualenv env
#RUN source env/bin/activate
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
# copy project
COPY . /app
EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
#
My Docker File Look Like that
docker-cpmpose.yml
version: "3"
services:
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
ports:
- 8000:8000
Folder Structure
Directory: E:\djangoproject\blogproject
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 22-12-2022 19:39 Blog
d----- 22-12-2022 19:39 Blogproject
d----- 22-12-2022 19:40 venv
-a---- 22-12-2022 19:46 192512 db.sqlite3
-a---- 21-12-2022 18:02 153 docker-compose.yml
-a---- 22-12-2022 15:51 1097 Dockerfile
-a---- 24-12-2021 13:00 689 manage.py
-a---- 20-12-2022 13:09 578 requirements.txt
My Template folder Is in Blog app templates/blog/templtes.html
when i run #docker-compose up then my image server is start but then i sent request from my brouser the i get the error page
TemplateDoesNotExist at /
blog/pages.html
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 3.2.8
Exception Type: TemplateDoesNotExist
Exception Value:
blog/pages.html
Exception Location: /usr/local/lib/python3.8/site-packages/django/template/backends/django.py, line 84, in reraise
Python Executable: /usr/local/bin/python3
Python Version: 3.8.16
Python Path:
['/app',
'/usr/local/lib/python38.zip',
'/usr/local/lib/python3.8',
'/usr/local/lib/python3.8/lib-dynload',
'/usr/local/lib/python3.8/site-packages']
Server time: Fri, 23 Dec 2022 05:53:42 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
This engine did not provide a list of tried templates.
Error during template rendering
In template /app/Blog/templates/blog/base.html, error at line 0
some one can help me to fix this error
According to your Dockerfile, you must copy your django project from one folder to another and you didn't set workdir.
Instead of this:
COPY . /app #here only you copied but didn't set where to copy
Try this way:
COPY ./app /app #here copied Django project from one folder to another.
WORKDIR /app
Note: Don't forget to re-build this Dockerfile.