Docker logs コマンド

 Docker 命令大全Docker コマンド大全


docker logsこのコマンドは、コンテナのログ出力を取得および表示するために使用されます。

docker logsこのコマンドは、実行中のコンテナのデバッグや監視に役立つため、非常に便利です。

構文

docker logs [OPTIONS] CONTAINER

一般的なオプション:

  • -f, --follow: ログ出力を追跡します(~と同様tail -f)。
  • --since: 指定した時刻からログを表示します。
  • -t, --timestamps: ログのタイムスタンプを表示します。
  • --tail: ログの最後の部分のみを表示します。例:--tail 10最後の10行を表示します。
  • --details: ログに提供された追加の詳細情報を表示します。
  • --until: 指定した時刻までのログを表示します。

例

コンテナのログを表示する

docker logs my_container

名前に my_container を持つコンテナのすべてのログを表示します。出力内容:

hello world
hello world
hello world
...

ログ出力を追跡する

docker logs -f my_container

my_container のログ出力を継続的に表示します。出力内容:

hello world
hello world
hello world
...

タイムスタンプ付きのログを表示する

docker logs -t my_container

タイムスタンプを含むログを表示します。出力内容:

2023-07-22T15:04:05.123456789Z hello world
2023-07-22T15:04:06.123456789Z hello world
2023-07-22T15:04:07.123456789Z hello world
...

指定した時刻からログを表示する


docker logs --since="2023-07-22T15:00:00" my_container

2023-07-22T15:00:00 以降のログを表示します。

最後の10行のログを表示する

docker logs --tail 10 my_container

my_container の最後の10行のログを表示します。

追加の詳細情報を含むログを表示する

docker logs --details my_container

my_container のログを表示し、追加の詳細情報を含めます。

指定した時刻までのログを表示する

docker logs --until="2023-07-22T16:00:00" my_container

2023-07-22T16:00:00 以前のログを表示します。


 Docker 命令大全Docker コマンド大全

その他の拡張