This application has tree files, our application directory structure will look like this:
flask-docker
├── app.py
├── Dockerfile
├── requirements.txt
Let's add the following lines of code to our app.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_geek():
return '<h1>Hello from Flask & Docker</h2>'
if __name__ == "__main__":
app.run(debug=True)
Let's add the following lines of code to our Dockerfile:
FROM ubuntu
RUN apt update
RUN apt install python3 -y
RUN apt -y install python3-pip
WORKDIR src
COPY . .
RUN pip install -r requirements.txt --break-system-packages
EXPOSE 5000
CMD ["flask", "run", "--host", "0.0.0.0"]
Let's add the following lines of code to our requirements.txt:
flask
docker build -t <TAG-NAME> .
docker run -d -p 5000:5000 <TAG-NAME>