Docker Cookbook


Packaging a Flask Application Inside a Container | 43



Download 6,31 Mb.
Pdf ko'rish
bet45/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   41   42   43   44   45   46   47   48   ...   260
Bog'liq
Docker Cookbook

2.4 Packaging a Flask Application Inside a Container | 43


#!/usr/bin/env python
from
flask
import
Flask
app
=
Flask
(
__name__
)
@app.route
(
'/hi'
)
def
hello_world
():
return
'Hello World!'
if
__name__
==
'__main__'
:
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
)
To get this application running inside a Docker container, you need to write a Dock‐
erfile that installs the prerequisites for running the application by using the 
RUN
key
and exposes the port that the application runs on by using the 
EXPOSE
key. You also
need to move the application inside the container filesystem by using the 
ADD
key.
This Dockerfile will be as follows:
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y python
RUN apt-get install -y python-pip
RUN apt-get clean all
RUN pip install flask
ADD hello.py /tmp/hello.py
EXPOSE 5000
CMD ["python","/tmp/hello.py"]
This Dockerfile is not optimized intentionally; when you understand the basic princi‐
ples, see 
Recipe 2.5
to build images following best practices to write Dockerfiles. The
RUN
command allows you to execute specific shell commands during the container
image build time. Here you update the repository cache, install Python as well as Pip,
and install the Flask micro-framework.
To copy the application inside the container image, you use the 
ADD
command. It
copies the file 
hello.py
in the 
/tmp/
directory.
The application uses port 5000, and you expose this port on the Docker host.
Finally, the 
CMD
command specifies that the container will run 
python /tmp/
hello.py
at runtime.
What is left to do is to build the image:
$ docker build -t flask .

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   41   42   43   44   45   46   47   48   ...   260




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish