An Interest In:
Web News this Week
- May 1, 2024
- April 30, 2024
- April 29, 2024
- April 28, 2024
- April 27, 2024
- April 26, 2024
- April 25, 2024
Containerzing our python application
Flask is a Python-based micro web platform. It is known as a microframework because it does not necessitate the use of any specific resources or libraries. It lacks a database abstraction layer, type validation, or any other components that rely on pre-existing third-party libraries to perform basic functions.
this is just a boiler plate hello world program in python
#write this in "flask_code,py"from flask import Flaskapp = FLask(__name__)@app.route("/")def hello_world_for_flask(): return "first flask project"app.run(port = 8090) #make it run in 8090 port
pip freeze
on your command prompt will give all the installed packages on your enviroement thus you can go and add them and this command also give the version of the installed.After they list in the terminal put all the text here to the requirements.txt
and save it in the directory that has Dockerfile
.
FROM python:3#make the workdir command to appWORKDIR /app#install depedencies from hereCOPY requirements.txt .RUN pip install -r requirements.txt#we have the copy our source codeCOPY /app .#to run our applicationCMD ["python", "flask_code.py"]
Then after building the docker file please do use the below command to build the docker file.
docker build -t docker_built_file
After building the docker image do go and run it with the command that I have stated here(you can use any port that you wish to use).
docker run -p 8090:8090 docker_built_file
Then go to the browser and type localhost:8090
and then you will find this as the output.(if you have worked as stated here).
Thank you all hope this helps you all in learning new thing.
Original Link: https://dev.to/vishwasnarayan5/containerzing-our-python-application-14nc
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To