github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/docs/reference/commandline/events.md (about) 1 --- 2 title: "events" 3 description: "The events command description and usage" 4 keywords: "events, container, report" 5 --- 6 7 <!-- This file is maintained within the docker/cli GitHub 8 repository at https://github.com/docker/cli/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # events 17 18 ```markdown 19 Usage: docker events [OPTIONS] 20 21 Get real time events from the server 22 23 Options: 24 -f, --filter value Filter output based on conditions provided (default []) 25 --format string Format the output using the given Go template 26 --help Print usage 27 --since string Show all events created since timestamp 28 --until string Stream events until this timestamp 29 ``` 30 31 ## Description 32 33 Use `docker events` to get real-time events from the server. These events differ 34 per Docker object type. 35 36 ### Object types 37 38 #### Containers 39 40 Docker containers report the following events: 41 42 - `attach` 43 - `commit` 44 - `copy` 45 - `create` 46 - `destroy` 47 - `detach` 48 - `die` 49 - `exec_create` 50 - `exec_detach` 51 - `exec_die` 52 - `exec_start` 53 - `export` 54 - `health_status` 55 - `kill` 56 - `oom` 57 - `pause` 58 - `rename` 59 - `resize` 60 - `restart` 61 - `start` 62 - `stop` 63 - `top` 64 - `unpause` 65 - `update` 66 67 #### Images 68 69 Docker images report the following events: 70 71 - `delete` 72 - `import` 73 - `load` 74 - `pull` 75 - `push` 76 - `save` 77 - `tag` 78 - `untag` 79 80 #### Plugins 81 82 Docker plugins report the following events: 83 84 - `enable` 85 - `disable` 86 - `install` 87 - `remove` 88 89 #### Volumes 90 91 Docker volumes report the following events: 92 93 - `create` 94 - `destroy` 95 - `mount` 96 - `unmount` 97 98 #### Networks 99 100 Docker networks report the following events: 101 102 - `create` 103 - `connect` 104 - `destroy` 105 - `disconnect` 106 - `remove` 107 108 #### Daemons 109 110 Docker daemons report the following events: 111 112 - `reload` 113 114 #### Services 115 116 Docker services report the following events: 117 118 - `create` 119 - `remove` 120 - `update` 121 122 #### Nodes 123 124 Docker nodes report the following events: 125 126 - `create` 127 - `remove` 128 - `update` 129 130 #### Secrets 131 132 Docker secrets report the following events: 133 134 - `create` 135 - `remove` 136 - `update` 137 138 #### Configs 139 140 Docker configs report the following events: 141 142 - `create` 143 - `remove` 144 - `update` 145 146 ### Limiting, filtering, and formatting the output 147 148 #### Limit events by time 149 150 The `--since` and `--until` parameters can be Unix timestamps, date formatted 151 timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed 152 relative to the client machine’s time. If you do not provide the `--since` option, 153 the command returns only new and/or live events. Supported formats for date 154 formatted time stamps include RFC3339Nano, RFC3339, `2006-01-02T15:04:05`, 155 `2006-01-02T15:04:05.999999999`, `2006-01-02Z07:00`, and `2006-01-02`. The local 156 timezone on the client will be used if you do not provide either a `Z` or a 157 `+-00:00` timezone offset at the end of the timestamp. When providing Unix 158 timestamps enter seconds[.nanoseconds], where seconds is the number of seconds 159 that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap 160 seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a 161 fraction of a second no more than nine digits long. 162 163 #### Filtering 164 165 The filtering flag (`-f` or `--filter`) format is of "key=value". If you would 166 like to use multiple filters, pass multiple flags (e.g., 167 `--filter "foo=bar" --filter "bif=baz"`) 168 169 Using the same filter multiple times will be handled as a *OR*; for example 170 `--filter container=588a23dac085 --filter container=a8f7720b8c22` will display 171 events for container 588a23dac085 *OR* container a8f7720b8c22 172 173 Using multiple filters will be handled as a *AND*; for example 174 `--filter container=588a23dac085 --filter event=start` will display events for 175 container container 588a23dac085 *AND* the event type is *start* 176 177 The currently supported filters are: 178 179 * config (`config=<name or id>`) 180 * container (`container=<name or id>`) 181 * daemon (`daemon=<name or id>`) 182 * event (`event=<event action>`) 183 * image (`image=<repository or tag>`) 184 * label (`label=<key>` or `label=<key>=<value>`) 185 * network (`network=<name or id>`) 186 * node (`node=<id>`) 187 * plugin (`plugin=<name or id>`) 188 * scope (`scope=<local or swarm>`) 189 * secret (`secret=<name or id>`) 190 * service (`service=<name or id>`) 191 * type (`type=<container or image or volume or network or daemon or plugin or service or node or secret or config>`) 192 * volume (`volume=<name>`) 193 194 #### Format 195 196 If a format (`--format`) is specified, the given template will be executed 197 instead of the default 198 format. Go's [text/template](http://golang.org/pkg/text/template/) package 199 describes all the details of the format. 200 201 If a format is set to `{{json .}}`, the events are streamed as valid JSON 202 Lines. For information about JSON Lines, please refer to http://jsonlines.org/ . 203 204 ## Examples 205 206 ### Basic example 207 208 You'll need two shells for this example. 209 210 **Shell 1: Listening for events:** 211 212 ```bash 213 $ docker events 214 ``` 215 216 **Shell 2: Start and Stop containers:** 217 218 ```bash 219 $ docker create --name test alpine:latest top 220 $ docker start test 221 $ docker stop test 222 ``` 223 224 **Shell 1: (Again .. now showing events):** 225 226 ```none 227 2017-01-05T00:35:58.859401177+08:00 container create 0fdb48addc82871eb34eb23a847cfd033dedd1a0a37bef2e6d9eb3870fc7ff37 (image=alpine:latest, name=test) 228 2017-01-05T00:36:04.703631903+08:00 network connect e2e1f5ceda09d4300f3a846f0acfaa9a8bb0d89e775eb744c5acecd60e0529e2 (container=0fdb...ff37, name=bridge, type=bridge) 229 2017-01-05T00:36:04.795031609+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 230 2017-01-05T00:36:09.830268747+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=15) 231 2017-01-05T00:36:09.840186338+08:00 container die 0fdb...ff37 (exitCode=143, image=alpine:latest, name=test) 232 2017-01-05T00:36:09.880113663+08:00 network disconnect e2e...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 233 2017-01-05T00:36:09.890214053+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) 234 ``` 235 236 To exit the `docker events` command, use `CTRL+C`. 237 238 ### Filter events by time 239 240 You can filter the output by an absolute timestamp or relative time on the host 241 machine, using the following different time syntaxes: 242 243 ```bash 244 $ docker events --since 1483283804 245 2017-01-05T00:35:41.241772953+08:00 volume create testVol (driver=local) 246 2017-01-05T00:35:58.859401177+08:00 container create d9cd...4d70 (image=alpine:latest, name=test) 247 2017-01-05T00:36:04.703631903+08:00 network connect e2e1...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 248 2017-01-05T00:36:04.795031609+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 249 2017-01-05T00:36:09.830268747+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=15) 250 2017-01-05T00:36:09.840186338+08:00 container die 0fdb...ff37 (exitCode=143, image=alpine:latest, name=test) 251 2017-01-05T00:36:09.880113663+08:00 network disconnect e2e...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 252 2017-01-05T00:36:09.890214053+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) 253 254 $ docker events --since '2017-01-05' 255 2017-01-05T00:35:41.241772953+08:00 volume create testVol (driver=local) 256 2017-01-05T00:35:58.859401177+08:00 container create d9cd...4d70 (image=alpine:latest, name=test) 257 2017-01-05T00:36:04.703631903+08:00 network connect e2e1...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 258 2017-01-05T00:36:04.795031609+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 259 2017-01-05T00:36:09.830268747+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=15) 260 2017-01-05T00:36:09.840186338+08:00 container die 0fdb...ff37 (exitCode=143, image=alpine:latest, name=test) 261 2017-01-05T00:36:09.880113663+08:00 network disconnect e2e...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 262 2017-01-05T00:36:09.890214053+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) 263 264 $ docker events --since '2013-09-03T15:49:29' 265 2017-01-05T00:35:41.241772953+08:00 volume create testVol (driver=local) 266 2017-01-05T00:35:58.859401177+08:00 container create d9cd...4d70 (image=alpine:latest, name=test) 267 2017-01-05T00:36:04.703631903+08:00 network connect e2e1...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 268 2017-01-05T00:36:04.795031609+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 269 2017-01-05T00:36:09.830268747+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=15) 270 2017-01-05T00:36:09.840186338+08:00 container die 0fdb...ff37 (exitCode=143, image=alpine:latest, name=test) 271 2017-01-05T00:36:09.880113663+08:00 network disconnect e2e...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 272 2017-01-05T00:36:09.890214053+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) 273 274 $ docker events --since '10m' 275 2017-01-05T00:35:41.241772953+08:00 volume create testVol (driver=local) 276 2017-01-05T00:35:58.859401177+08:00 container create d9cd...4d70 (image=alpine:latest, name=test) 277 2017-01-05T00:36:04.703631903+08:00 network connect e2e1...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 278 2017-01-05T00:36:04.795031609+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 279 2017-01-05T00:36:09.830268747+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=15) 280 2017-01-05T00:36:09.840186338+08:00 container die 0fdb...ff37 (exitCode=143, image=alpine:latest, name=test) 281 2017-01-05T00:36:09.880113663+08:00 network disconnect e2e...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 282 2017-01-05T00:36:09.890214053+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) 283 284 $ docker events --since '2017-01-05T00:35:30' --until '2017-01-05T00:36:05' 285 2017-01-05T00:35:41.241772953+08:00 volume create testVol (driver=local) 286 2017-01-05T00:35:58.859401177+08:00 container create d9cd...4d70 (image=alpine:latest, name=test) 287 2017-01-05T00:36:04.703631903+08:00 network connect e2e1...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 288 2017-01-05T00:36:04.795031609+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 289 ``` 290 291 ### Filter events by criteria 292 293 The following commands show several different ways to filter the `docker event` 294 output. 295 296 ```bash 297 $ docker events --filter 'event=stop' 298 299 2017-01-05T00:40:22.880175420+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) 300 2017-01-05T00:41:17.888104182+08:00 container stop 2a8f...4e78 (image=alpine, name=kickass_brattain) 301 302 $ docker events --filter 'image=alpine' 303 304 2017-01-05T00:41:55.784240236+08:00 container create d9cd...4d70 (image=alpine, name=happy_meitner) 305 2017-01-05T00:41:55.913156783+08:00 container start d9cd...4d70 (image=alpine, name=happy_meitner) 306 2017-01-05T00:42:01.106875249+08:00 container kill d9cd...4d70 (image=alpine, name=happy_meitner, signal=15) 307 2017-01-05T00:42:11.111934041+08:00 container kill d9cd...4d70 (image=alpine, name=happy_meitner, signal=9) 308 2017-01-05T00:42:11.119578204+08:00 container die d9cd...4d70 (exitCode=137, image=alpine, name=happy_meitner) 309 2017-01-05T00:42:11.173276611+08:00 container stop d9cd...4d70 (image=alpine, name=happy_meitner) 310 311 $ docker events --filter 'container=test' 312 313 2017-01-05T00:43:00.139719934+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 314 2017-01-05T00:43:09.259951086+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=15) 315 2017-01-05T00:43:09.270102715+08:00 container die 0fdb...ff37 (exitCode=143, image=alpine:latest, name=test) 316 2017-01-05T00:43:09.312556440+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) 317 318 $ docker events --filter 'container=test' --filter 'container=d9cdb1525ea8' 319 320 2017-01-05T00:44:11.517071981+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 321 2017-01-05T00:44:17.685870901+08:00 container start d9cd...4d70 (image=alpine, name=happy_meitner) 322 2017-01-05T00:44:29.757658470+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=9) 323 2017-01-05T00:44:29.767718510+08:00 container die 0fdb...ff37 (exitCode=137, image=alpine:latest, name=test) 324 2017-01-05T00:44:29.815798344+08:00 container destroy 0fdb...ff37 (image=alpine:latest, name=test) 325 326 $ docker events --filter 'container=test' --filter 'event=stop' 327 328 2017-01-05T00:46:13.664099505+08:00 container stop a9d1...e130 (image=alpine, name=test) 329 330 $ docker events --filter 'type=volume' 331 332 2015-12-23T21:05:28.136212689Z volume create test-event-volume-local (driver=local) 333 2015-12-23T21:05:28.383462717Z volume mount test-event-volume-local (read/write=true, container=562f...5025, destination=/foo, driver=local, propagation=rprivate) 334 2015-12-23T21:05:28.650314265Z volume unmount test-event-volume-local (container=562f...5025, driver=local) 335 2015-12-23T21:05:28.716218405Z volume destroy test-event-volume-local (driver=local) 336 337 $ docker events --filter 'type=network' 338 339 2015-12-23T21:38:24.705709133Z network create 8b11...2c5b (name=test-event-network-local, type=bridge) 340 2015-12-23T21:38:25.119625123Z network connect 8b11...2c5b (name=test-event-network-local, container=b4be...c54e, type=bridge) 341 342 $ docker events --filter 'container=container_1' --filter 'container=container_2' 343 344 2014-09-03T15:49:29.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) 345 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) 346 2014-05-10T17:42:14.999999999Z07:00 container die 7805c1d35632 (imager=redis:2.8) 347 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) 348 349 $ docker events --filter 'type=volume' 350 351 2015-12-23T21:05:28.136212689Z volume create test-event-volume-local (driver=local) 352 2015-12-23T21:05:28.383462717Z volume mount test-event-volume-local (read/write=true, container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, destination=/foo, driver=local, propagation=rprivate) 353 2015-12-23T21:05:28.650314265Z volume unmount test-event-volume-local (container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, driver=local) 354 2015-12-23T21:05:28.716218405Z volume destroy test-event-volume-local (driver=local) 355 356 $ docker events --filter 'type=network' 357 358 2015-12-23T21:38:24.705709133Z network create 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, type=bridge) 359 2015-12-23T21:38:25.119625123Z network connect 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, container=b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e, type=bridge) 360 361 $ docker events --filter 'type=plugin' 362 363 2016-07-25T17:30:14.825557616Z plugin pull ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/sample-volume-plugin:latest) 364 2016-07-25T17:30:14.888127370Z plugin enable ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/sample-volume-plugin:latest) 365 366 $ docker events -f type=service 367 368 2017-07-12T06:34:07.999446625Z service create wj64st89fzgchxnhiqpn8p4oj (name=reverent_albattani) 369 2017-07-12T06:34:21.405496207Z service remove wj64st89fzgchxnhiqpn8p4oj (name=reverent_albattani) 370 371 $ docker events -f type=node 372 373 2017-07-12T06:21:51.951586759Z node update 3xyz5ttp1a253q74z1thwywk9 (name=ip-172-31-23-42, state.new=ready, state.old=unknown) 374 375 $ docker events -f type=secret 376 377 2017-07-12T06:32:13.915704367Z secret create s8o6tmlnndrgzbmdilyy5ymju (name=new_secret) 378 2017-07-12T06:32:37.052647783Z secret remove s8o6tmlnndrgzbmdilyy5ymju (name=new_secret) 379 380 $ docker events -f type=config 381 2017-07-12T06:44:13.349037127Z config create u96zlvzdfsyb9sg4mhyxfh3rl (name=abc) 382 2017-07-12T06:44:36.327694184Z config remove u96zlvzdfsyb9sg4mhyxfh3rl (name=abc) 383 384 $ docker events --filter 'scope=swarm' 385 386 2017-07-10T07:46:50.250024503Z service create m8qcxu8081woyof7w3jaax6gk (name=affectionate_wilson) 387 2017-07-10T07:47:31.093797134Z secret create 6g5pufzsv438p9tbvl9j94od4 (name=new_secret) 388 ``` 389 390 ### Format the output 391 392 ```bash 393 $ docker events --filter 'type=container' --format 'Type={{.Type}} Status={{.Status}} ID={{.ID}}' 394 395 Type=container Status=create ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 396 Type=container Status=attach ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 397 Type=container Status=start ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 398 Type=container Status=resize ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 399 Type=container Status=die ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 400 Type=container Status=destroy ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 401 ``` 402 403 #### Format as JSON 404 405 ```none 406 $ docker events --format '{{json .}}' 407 408 {"status":"create","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. 409 {"status":"attach","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. 410 {"Type":"network","Action":"connect","Actor":{"ID":"1b50a5bf755f6021dfa78e.. 411 {"status":"start","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f42.. 412 {"status":"resize","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. 413 ```