首頁·終端機命令

docker logs

套件與執行環境

用法

docker logs [-f] [--tail <n>] <container>

顯示容器主行程寫到 stdout 和 stderr 的內容;如果應用把日誌寫進容器裡的檔案,這裡什麼都看不到,而容器一刪日誌也跟著沒了。

常用選項

選項含義
-ffollow new output as it arrives
--tail <n>only the last n lines
--since <time>from a point in time, e.g. 15m or a timestamp
--until <time>up to a point in time
-tprefix every line with a timestamp

範例

docker logs -f --tail 100 web

the last hundred lines, then follow

docker logs --since 15m web

what happened in the last fifteen minutes

docker logs -t web

the same output with timestamps in front

問題永遠是什麼裝到哪裡:裝進這個專案,還是裝到整台機器上。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. docker logs 是做什麼的?

顯示容器主行程寫到 stdout 和 stderr 的內容;如果應用把日誌寫進容器裡的檔案,這裡什麼都看不到,而容器一刪日誌也跟著沒了。

Q. 怎麼寫?

docker logs [-f] [--tail <n>] <container> —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 5 個,完整列表在 man docker。這條命令屬於套件與執行環境。

相關命令

man 手冊: man docker-logs