LoginSignup
0

More than 5 years have passed since last update.

dockerコンテナのログの実体ファイルを取得する方法

Posted at

Dockerコンテナのログをファイルで取得する方法(ただしjson形式)

手順

対象のコンテナのコンテナIDを確認する

Nginxを例として説明します。

$ sudo docker ps | grep nginx
844a92cb5647        quay.io/kubernetes-ingress-controller/nginx-ingress-controller@sha256:46523a0b8b35b082211caa2bebb95c43578f85a51c03a28599b39a13b27965cb   "/usr/bin/dumb-ini..."   6 weeks ago         Up 6 weeks                              k8s_ingress-nginx_ingress-nginx-79f5476fdc-b7jlc_production_f6c71e4b-3360-11e8-9f95-0ace71965bbc_0

コンテナID = 844a92cb5647

Dockerのログの設定を確認する

$ sudo docker info | grep Log
Logging Driver: json-file

デフォルトではドライバが json-file になっているはず。
ファイルであれば、 inspect で確認可能。

実ファイルのPathを確認

$ sudo docker inspect 844a92cb5647 | grep LogPath
        "LogPath": "/var/lib/docker/containers/844a92cb5547b61ed2534f6ff87e81057ae290edd55fe761041205cfc472080c/844a92cb5547b61ed2534f6ff87e81057ae290edd55fe761041205cfc472080c-json.log",

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0