docker log

이상민·2023년 4월 13일
0

docker

목록 보기
3/19
$ docker run -d nginx
$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                               NAMES
55f63b24b52b   nginx     "/docker-entrypoint.…"   5 seconds ago   Up 4 seconds   80/tcp                              confident_banzai

log 확인

$ docker logs confident_banzai
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/04/13 05:55:59 [notice] 1#1: using the "epoll" event method
2023/04/13 05:55:59 [notice] 1#1: nginx/1.23.4
2023/04/13 05:55:59 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/04/13 05:55:59 [notice] 1#1: OS: Linux 5.19.0-1022-aws
2023/04/13 05:55:59 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/04/13 05:55:59 [notice] 1#1: start worker processes
2023/04/13 05:55:59 [notice] 1#1: start worker process 29
2023/04/13 05:55:59 [notice] 1#1: start worker process 30

log 확인 - tail

$ docker logs --tail 5 confident_banzai
2023/04/13 05:55:59 [notice] 1#1: OS: Linux 5.19.0-1022-aws
2023/04/13 05:55:59 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/04/13 05:55:59 [notice] 1#1: start worker processes
2023/04/13 05:55:59 [notice] 1#1: start worker process 29
2023/04/13 05:55:59 [notice] 1#1: start worker process 30

log 확인 - 실시간

$ docker logs -f confident_banzai
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/04/13 05:55:59 [notice] 1#1: using the "epoll" event method
2023/04/13 05:55:59 [notice] 1#1: nginx/1.23.4
2023/04/13 05:55:59 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/04/13 05:55:59 [notice] 1#1: OS: Linux 5.19.0-1022-aws
2023/04/13 05:55:59 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/04/13 05:55:59 [notice] 1#1: start worker processes
2023/04/13 05:55:59 [notice] 1#1: start worker process 29
2023/04/13 05:55:59 [notice] 1#1: start worker process 30

log 확인 - 실시간 + timestamp

$ docker logs -t -f confident_banzai
2023-04-13T05:55:59.225609946Z /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
2023-04-13T05:55:59.225667714Z /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
2023-04-13T05:55:59.227141850Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
2023-04-13T05:55:59.232826584Z 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
2023-04-13T05:55:59.240784572Z 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
2023-04-13T05:55:59.240926429Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
2023-04-13T05:55:59.243207266Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
2023-04-13T05:55:59.244384930Z /docker-entrypoint.sh: Configuration complete; ready for start up
2023-04-13T05:55:59.248930467Z 2023/04/13 05:55:59 [notice] 1#1: using the "epoll" event method
2023-04-13T05:55:59.248950889Z 2023/04/13 05:55:59 [notice] 1#1: nginx/1.23.4
2023-04-13T05:55:59.248955649Z 2023/04/13 05:55:59 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023-04-13T05:55:59.248959848Z 2023/04/13 05:55:59 [notice] 1#1: OS: Linux 5.19.0-1022-aws
2023-04-13T05:55:59.248963916Z 2023/04/13 05:55:59 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023-04-13T05:55:59.248968062Z 2023/04/13 05:55:59 [notice] 1#1: start worker processes
2023-04-13T05:55:59.249164491Z 2023/04/13 05:55:59 [notice] 1#1: start worker process 29
2023-04-13T05:55:59.249463645Z 2023/04/13 05:55:59 [notice] 1#1: start worker process 30

log 저장 경로

log driver가 저장 경로일때만 확인 가능

$ sudo su

# cat /var/lib/docker/containers/49976b0b105d71cc622b389cce448edcb2c503dca33776bf71ac6232051b2f78/\
49976b0b105d71cc622b389cce448edcb2c503dca33776bf71ac6232051b2f78-json.log
{"log":"/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration\n","stream":"stdout","time":"2023-04-13T03:16:03.595424964Z"}
{"log":"/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/\n","stream":"stdout","time":"2023-04-13T03:16:03.595488825Z"}
{"log":"/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh\n","stream":"stdout","time":"2023-04-13T03:16:03.598292852Z"}
{"log":"10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf\n","stream":"stdout","time":"2023-04-13T03:16:03.612591471Z"}
{"log":"10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf\n","stream":"stdout","time":"2023-04-13T03:16:03.620318735Z"}
{"log":"/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh\n","stream":"stdout","time":"2023-04-13T03:16:03.620774205Z"}
{"log":"/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh\n","stream":"stdout","time":"2023-04-13T03:16:03.624861818Z"}
{"log":"/docker-entrypoint.sh: Configuration complete; ready for start up\n","stream":"stdout","time":"2023-04-13T03:16:03.627034291Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: using the \"epoll\" event method\n","stream":"stderr","time":"2023-04-13T03:16:03.634143548Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: nginx/1.23.4\n","stream":"stderr","time":"2023-04-13T03:16:03.634162981Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) \n","stream":"stderr","time":"2023-04-13T03:16:03.634167787Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: OS: Linux 5.19.0-1022-aws\n","stream":"stderr","time":"2023-04-13T03:16:03.634172166Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576\n","stream":"stderr","time":"2023-04-13T03:16:03.634176459Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: start worker processes\n","stream":"stderr","time":"2023-04-13T03:16:03.634190266Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: start worker process 29\n","stream":"stderr","time":"2023-04-13T03:16:03.636215716Z"}
{"log":"2023/04/13 03:16:03 [notice] 1#1: start worker process 30\n","stream":"stderr","time":"2023-04-13T03:16:03.636248485Z"}

해당 container의 json 파일중 파일 이름이 가장 긴 값을 선택하여 확인

log 용량 제한하기

컨테이너 단위로 로그 용량 제한이 가능하며, 도커 엔진에서 기본 설정 진행도 가능함.

container

$ docker run\
  -d\
  --log-driver=json-file\
  --log-opt max-size=3m\
  --log-opt max-file=5\
  nginx

한 로그 파일 당 최대 크기를 3MB로 제한하고, 최대 로그 파일 3개로 로테이팅

0개의 댓글