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 is my file structure
Here is my file structure
Here is my docker-compose.yml
version: '3'
services:
frontend:
build: ./frontend
ports:
- 5000:80
volumes:
- .:/usr/share/nginx/htm
backend:
build: ./backend
depends_on:
- frontend
ports:
- 5001:80
volumes:
- /home/doc-tryy-2/frontend:/usr/src/app
volumes:
asset-volume4:
driver: local
Here is my frontend/Dockerfile
FROM nginx:alpine
COPY . /usr/share/nginx/htm
WORKDIR /usr/share/nginx/htm
EXPOSE 5000
Here is my backend/Dockerfile
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 80
CMD [ "python", "app.py" ]
Here is my backend/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=80,host='0.0.0.0')
Here is my templates/loginepage.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Logg</title>
</head>
<body>
<h2>HTML Forms</h2>
<form action="/" method="post">
<label for="fname">First name:</label><br>
<input type="text" id="uname" name="uname" value="John"><br>
<input type="submit" value="Submit">
</form>
<h1>hi {{uname}}</h1>
</body>
</html>