June 17, 2019

Docker Container(입력된 명령어) 로그 - docker logs

Docker logs - 도커 컨테이너에 입력된 명령어 로그 확인

Docker logs는 입력된 명령어와 출력된 값을 확인 할 수 있다.

docker logs <옵션> 컨테이너명 또는
docker container logs <옵션> 컨테이너명




dongdonge@dongdonge$ sudo docker logs --help

Usage:  docker logs [OPTIONS] CONTAINER

Fetch the logs of a container

Options:
      --details        Show extra details provided to logs
  -f, --follow         Follow log output
      --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for
                       42 minutes)
      --tail string    Number of lines to show from the end of the logs (default "all")
  -t, --timestamps     Show timestamps
      --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m
                       for 42 minutes)

1. --details : 로그 세부정보 표시

2. -f, --follow : 로그 출력

3. -t, --timestamps : 타임스탬프 출력

아래는 컨테이너에서 실행했던 로그를 출력 해본다.




dongdonge@dongdonge$ sudo docker logs --details 754503a85e20

root@754503a85e20:/# ls
 bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  root@754503a85e20:/# id
 uid=0(root) gid=0(root) groups=0(root)
 root@754503a85e20:/# ip addr
 bash: ip: command not found
 root@754503a85e20:/# ifconfig
 bash: ifconfig: command not found
 root@754503a85e20:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [857 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1250 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [968 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [19.1 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7942 B]
Get:15 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8532 B]
Get:16 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
95% [16 Packages 2713 B/12.7 kB 21%]                                                             2513 kB95% [Waiting for headers]                                                                        2513 kB

Get:17 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [557 kB]
95% [17 Packages 1509 B/557 kB 0%]                                                               2513 kB95% [16 Packages store 0 B] [17 Packages 1509 B/557 kB 0%]                                       2513 kB96% [17 Packages 1509 B/557 kB 0%]                                                               2513 kB97% [17 Packages 114 kB/557 kB 20%]                                                              2513 kB97% [17 Packages 223 kB/557 kB 40%]                                                              2513 kB98% [17 Packages 331 kB/557 kB 59%]                                                              2513 kB98% [17 Packages 442 kB/557 kB 79%]                                                              2513 kB99% [17 Packages 556 kB/557 kB 100%]                                                             2513 kB99% [Waiting for headers]                                                                        2513 kB

Get:18 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6121 B]
99% [18 Packages 1673 B/6121 B 27%]                                                              2513 kB99% [17 Packages store 0 B] [18 Packages 1673 B/6121 B 27%]                                      2513 kB99% [17 Packages store 0 B]                                                                      2513 kB99% [Working]                                                                                    2513 kB99% [18 Packages store 0 B]                                                                      2513 kB100% [Working]                                                                                   2513 kB

Fetched 15.8 MB in 8s (1820 kB/s)
Reading package lists... Done

도커 컨테이너에서 실행했던 명령어를 확인 할 수 있다.
현재 ls, id, ip addr, ifconfig, apt-get update 명령을 수행한 로그가 기록되어 있다.