[root@test32 ~]# docker run nginx /bin/sh -c "while true; do echo hello world; sleep 1; done" hello world hello world hello world hello world
[root@test32 ~]# docker run -d nginx /bin/sh -c "while true; do echo hello world; sleep 1; done" 2939156e31bb2913453aaa424214376c382aabef2bf1903e723e2ad9f6330e35 [root@test32 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2939156e31bb nginx "/bin/sh -c 'while..." 17 seconds ago Up 15 seconds 80/tcp youthful_hodgkin
此時用 docker logs 來查看日誌python
[root@test32 ~]# docker logs -f -t 293915 2018-12-26T10:34:40.558068000Z hello world 2018-12-26T10:34:41.559143000Z hello world 2018-12-26T10:34:42.560398000Z hello world 2018-12-26T10:34:43.561626000Z hello world 2018-12-26T10:34:44.562831000Z hello world 2018-12-26T10:34:45.564119000Z hello world
-f 跟蹤實時日誌
--since string 顯示自某個timestamp以後的日誌,或相對時間,如42m(即42分鐘)
--tail string 從日誌末尾顯示多少行日誌, 默認是all
-t 顯示時間戳
--until string 顯示自某個timestamp以前的日誌,或相對時間nginx
[root@test32 ~]# docker logs -f -t --tail=10 293915 [root@test32 ~]# docker logs -t --since="2018-12-26T10:48Z" 293915 2018-12-26T10:48:00.605556000Z hello world 2018-12-26T10:48:01.607088000Z hello world 2018-12-26T10:48:02.608282000Z hello world 2018-12-26T10:48:03.609575000Z hello world 2018-12-26T10:48:04.610942000Z hello world
stopweb
[root@test32 ~]# docker stop 293915 293915 [root@test32 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2939156e31bb nginx "/bin/sh -c 'while..." 16 minutes ago Exited (137) 14 seconds ago youthful_hodgkin
經過docker的兩個參數 -i -t,讓docker運行的容器實現"對話"的能力docker