DEV Community

vishwasnarayanre
vishwasnarayanre

Posted on

3 3

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

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay