• events

    events

    • 用法
    1. Usage: docker events [OPTIONS]
    2. Get real time events from the server
    3. -f, --filter=[] Filter output based on conditions provided
    4. --help=false Print usage
    5. --since= Show all events created since timestamp
    6. --until= Stream events until this timestamp
    • 例子

    第一个窗口用来监听事件

    1. $ docker events

    第二个窗口 起停容器

    1. $ docker start 4386fb97867d
    2. $ docker stop 4386fb97867d
    3. $ docker stop 7805c1d35632

    执行完后,shell窗口会同步打印如下信息:

    1. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start
    2. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    3. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    4. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    5. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop

    使用since参数按时间筛选

    1. $ sudo docker events --since 1378216169
    2. 2014-03-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    3. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    4. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    5. 2014-03-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
    6. $ sudo docker events --since '2013-09-03'
    7. 2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start
    8. 2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    9. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    10. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    11. 2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
    12. $ sudo docker events --since '2013-09-03T15:49:29'
    13. 2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    14. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    15. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    16. 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop

    只保留三分钟内的事件

    1. $ sudo docker events --since '3m'
    2. 2015-05-12T11:51:30.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    3. 2015-05-12T15:52:12.999999999Z07:00 4 4386fb97867d: (from ubuntu-1:14.04) stop
    4. 2015-05-12T15:53:45.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    5. 2015-05-12T15:54:03.999999999Z07:00 7805c1d35632: (from redis:2.8) stop

    也可以使用过滤器筛选

    1. $ docker events --filter 'event=stop'
    2. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    3. 2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
    4. $ docker events --filter 'image=ubuntu-1:14.04'
    5. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start
    6. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    7. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    8. $ docker events --filter 'container=7805c1d35632'
    9. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    10. 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
    11. $ docker events --filter 'container=7805c1d35632' --filter 'container=4386fb97867d'
    12. 2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    13. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    14. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    15. 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
    16. $ docker events --filter 'container=7805c1d35632' --filter 'event=stop'
    17. 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
    18. $ docker events --filter 'container=container_1' --filter 'container=container_2'
    19. 2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
    20. 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
    21. 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
    22. 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
    • 总结

      打印容器实时的系统事件。