'jinja2.exceptions.TemplateNotFound (while creating via docker-compose) (flask)

i am trying to connect & build two docker file with docker-compose. I am new to docker & then its getting confused while connecting with docker-compose. Main purpose: connecting frontend & backend (of flask application) via docker-compose.

If my Dockerfile & docker-compose.yml file wrong. please correct me

  • like front end in one frontend folder with Dockerfile.
  • back end in another folder with Dockerfile. (connecting this 2, via doc-comp)

here's my file structure (inside template folder - loginpage.html) enter image description here

app.py


from flask import Flask, render_template, flash, redirect, url_for, session, logging, request

app = Flask(__name__)
app.secret_key = 'hello'

@app.route("/", methods=["GET", "POST"])
def login():
    if request.method == "POST":
        uname = request.form["uname"]
        return render_template("loginpage.html", uname=uname)
    else:
        return render_template("loginpage.html")


if __name__ == "__main__":
    app.run(debug=True, port=5048,host='0.0.0.0')

backend/Dockerfile

FROM python:3.7-slim
ADD ./requirements.txt /backend/requirements.txt
WORKDIR /backend
RUN pip install -r requirements.txt
ADD . /backend
ENTRYPOINT ["python"]
CMD ["/backend/app.py"]
EXPOSE 5048

frontend/Dockerfile

FROM python:3.7-slim
COPY templates /backend/
COPY . /backend
WORKDIR /backend

docker-compose.yml

version: '2'
services:
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    restart: always
    ports:
     - "5048:5048"
    

  frontend:
    build: ./frontend



Solution 1:[1]

you can write docker-compose file something like this ..

version: "3.7"
    services:
      frontend:
        build:
          context: ./frontEnd
        container_name: frontend
        depends_on: [backend]
        ports: 
          - "5000:5000"
        networks:
          - my_own_network
        links:
          - "backend:backend"
      backend:
        build:
          context: ./backend
        container_name: backend
        ports:
          - "5048:5048"
        networks:
          - my_own_network
      networks:
          my_own_network:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1