Containerzing our python application

Docker (11 Part Series)

1 Docker : Part 1 : A brief concept for firing the containers.
2 Docker : Part 2 : A deep dive with my might shark (the Docker Engine)
7 more parts…
3 Docker in making the world more unique in terms of the development
4 learn docker in the right form
5 Static website on Docker with the NGINX server
6 Docker Must know commands and tricks
7 Docker for setting the developer Environnement
8 Containerzing our python application
9 nodejs and docker
10 docker and java
11 Reason to learn docker as a web developer

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

<span>#write this in "flask_code,py" </span><span>from</span> <span>flask</span> <span>import</span> <span>Flask</span>
<span>app</span> <span>=</span> <span>FLask</span><span>(</span><span>__name__</span><span>)</span>
<span>@app.route</span><span>(</span><span>"</span><span>/</span><span>"</span><span>)</span>
<span>def</span> <span>hello_world_for_flask</span><span>():</span>
<span>return</span> <span>"</span><span>first flask project</span><span>"</span>
<span>app</span><span>.</span><span>run</span><span>(</span><span>port</span> <span>=</span> <span>8090</span><span>)</span> <span>#make it run in 8090 port </span>
<span>#write this in "flask_code,py" </span><span>from</span> <span>flask</span> <span>import</span> <span>Flask</span>
<span>app</span> <span>=</span> <span>FLask</span><span>(</span><span>__name__</span><span>)</span>

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

<span>app</span><span>.</span><span>run</span><span>(</span><span>port</span> <span>=</span> <span>8090</span><span>)</span> <span>#make it run in 8090 port </span>
#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.

<span>FROM</span><span> python:3</span>
<span>#make the workdir command to app</span>
<span>WORKDIR</span><span> /app</span>
<span>#install depedencies from here</span>
<span>COPY</span><span> requirements.txt .</span>
<span>RUN </span>pip <span>install</span> <span>-r</span> requirements.txt
<span>#we have the copy our source code</span>
<span>COPY</span><span> /app .</span>
<span>#to run our application</span>
<span>CMD</span><span> ["python", "flask_code.py"]</span>
<span>FROM</span><span> python:3</span>

<span>#make the workdir command to app</span>
<span>WORKDIR</span><span> /app</span>

<span>#install depedencies from here</span>
<span>COPY</span><span> requirements.txt .</span>
<span>RUN </span>pip <span>install</span> <span>-r</span> requirements.txt

<span>#we have the copy our source code</span>

<span>COPY</span><span> /app .</span>

<span>#to run our application</span>
<span>CMD</span><span> ["python", "flask_code.py"]</span>
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).

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

Docker (11 Part Series)

1 Docker : Part 1 : A brief concept for firing the containers.
2 Docker : Part 2 : A deep dive with my might shark (the Docker Engine)
7 more parts…
3 Docker in making the world more unique in terms of the development
4 learn docker in the right form
5 Static website on Docker with the NGINX server
6 Docker Must know commands and tricks
7 Docker for setting the developer Environnement
8 Containerzing our python application
9 nodejs and docker
10 docker and java
11 Reason to learn docker as a web developer

原文链接:Containerzing our python application

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
Flat rich prosperous time in vain to develop a group of coward, hardship is the mother of strong forever.
平富足的盛世徒然养成一批懦夫,困苦永远是坚强之母
评论 抢沙发

请登录后发表评论

    暂无评论内容