DEV Community

loading...

Containerzing our python application

vishwasnarayan5 profile image vishwasnarayanre ・2 min read

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 Flask
app = FLask(__name__)

@app.route("/")
def hello_world_for_flask():
    return "first flask project"

app.run(port = 8090) #make it run in 8090 port
Enter fullscreen mode Exit fullscreen mode

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 app
WORKDIR /app

#install depedencies from here
COPY requirements.txt .
RUN pip install -r requirements.txt

#we have the copy our source code

COPY /app .

#to run our application
CMD ["python", "flask_code.py"]
Enter fullscreen mode Exit fullscreen mode

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).

Alt Text

Thank you all hope this helps you all in learning new thing.

Discussion (0)

Forem Open with the Forem app