✨This is simple web application using python flask and docker image
There are two ways in which we can run webapp server.
By installing all the dependences packages
Or by creating and inherit in docker files
By installing all the dependences packages
We will create a directory in server as shown below and will create filename app.py
mkdir docker-webapp
cd docker-webapp
touch app.py
Now we will execute below command Ubuntu images starts and it runs the bash command and it takes or it attaches input to terminal
docker run -it ubuntu bash
apt-get update
apt-get install -y python-is-python3
python apt-get install python3-pip
Install and configure web-server
pip install flask
Now will vi visual editor in app.py file
import os
from flask import Flask
app = Flask(name)
@app.route("/")
def main():
return "Swagat aahe!"
@app.route('/kai mhanta shet')
def hello():
return 'Bas Nivant Tumhi bolla?'
if name == "main":
app.run(host="0.0.0.0", port=8080)
Once above steps are done will start the web-server by running command as below.
FLASK_APP=app.py flask run --host=0.0.0.0
After this web-server will start running and to test use command as shown
http://:5000 => Swagat aahe!
http://:5000/kai%20mhanta%20shet => Bas Nivant Tumhi bolla?
Or by creating and inherit in docker files
You need to be in docker-webapp directory and create below image
Create a docker image will all dependencies inherit in it
FROM ubuntu
RUN apt-get update
RUN apt-get install -y python-is-python3 python3-pip
RUN pip3 install flask
COPY app.py /opt/app.py
ENTRYPOINT FLASK_APP=/opt/app.py flask run --host=0.0.0.0
You need to build the docker images
docker build . -t docker-webapp
Then once build is completed run the container
docker run docker-webapp
After this web-server will start running and to test use command as shown
http://:5000 => Swagat aahe!
http://:5000/kai%20mhanta%20shet => Bas Nivant Tumhi bolla?
If you liked what you read, do follow and Any feedback for further improvement will be highly appreciated!
Thank you and Happy Learning!👏