Docker Cookbook


Listening to Docker Events on Your Docker Hosts



Download 6,31 Mb.
Pdf ko'rish
bet217/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   213   214   215   216   217   218   219   220   ...   260
Bog'liq
Docker Cookbook

9.3 Listening to Docker Events on Your Docker Hosts
Problem
You want to monitor Docker events on your host. You are interested in image untag‐
ging and deletion and container life-cycle events (e.g., create, destroy, kill).
9.3 Listening to Docker Events on Your Docker Hosts | 277


Solution
Use the 
docker events
command. It will return a stream of events as they happen on
your Docker host. The command takes a few optional arguments if you want to select
events for a specific time range:
$ docker events --help
Usage: docker events [OPTIONS]
Get real time events from the server
-f, --filter=[] Provide filter values (i.e., 'event=stop')
--help=false Print usage
--since="" Show all events created since timestamp
--until="" Stream events until this timestamp
Although 
docker events
will work and block until you Ctrl-C the stream, you can
use the 
--since
or 
--until
options like so:
$ docker events --since 1427890602
2015-04-01T12:17:04....9393146cb55e5bc9f04e20eb5a0622b3e26aae7: untag
2015-04-01T12:17:09....d5266f8777bfba4974ac56e3270e7760f6f0a81: untag
2015-04-01T12:17:22....d5266f8777bfba4974ac56e3270e7760f6f0a85: untag
2015-04-01T12:17:23....66f8777bfba4974ac56e3270e7760f6f0a81253: delete
2015-04-01T12:17:23....e9b5a793523481a0a18645fc77ad53c4eadsfa2: delete
2015-04-01T12:17:23....878585defcc1bc6f79d2728a13957871b345345: delete
Just as a reminder, you can get the current timestamp in Epoch
with 
date +"%s"
.
Discussion
This 
events
command is also available as an API call, and you can use 
curl
to access
it (see 
Recipe 9.2
). Let’s leave this as an exercise and give an example of using 
docker-
py
to get the list of events.
Recipe 9.2
reconfigured the Docker daemon to access the remote API over TCP. You
can also use 
docker-py
to access the Unix Docker socket. A sample Python script that
would do this and save you some time to reconfigure the Docker daemon looks like
this:
#!/usr/bin/env python

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   213   214   215   216   217   218   219   220   ...   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