서버 운영 관리 [ Tip ]

Docker 컨테이너, 서비스에 대한 로그 확인

1. 컨테이너, 서비스에 대한 로그 확인

1-1 컨테이너에 대한 로그 확인

 

컨테이너 로그 가져오기

- docker container logs [OPTIONS] [컨테이너]

[OPTIONS]

--details : 로그에 추가 세부 정보 표시

--follow, -f : 로그 출력을 따르십시오

--since : 특정 시간 이후에 대한 로그를 확인

--tail : 로그 끝에서 표시 할 줄 수 => 기본 값은 all 입니다.

--timestamps, -t : 타임 스탬프 확인

--until : 특정시간 이전에 대한 로그 확인

 

--details

=> 컨테이너 생성 후 작업한 내역들을 확인 할 수 있습니다.

root@localhost:~# docker container logs --details 91jos

 

root@3716d5ffee84:/# apt-get update

Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]

Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]

.

.

root@3716d5ffee84:/# vi /etc/apache2/apache2.conf

root@3716d5ffee84:/# /etc/init.d/apache2 restart

* Restarting Apache httpd web server apache2 [ OK ]

 

--since

=> 설정한 시간 이후에 대한 로그 확인

root@localhost:~# docker container logs --since 2018-07-05 91jos

 

root@3716d5ffee84:/#

root@3716d5ffee84:/#

root@3716d5ffee84:/#

root@3716d5ffee84:/#

root@3716d5ffee84:/# apt-get update

Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]

Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]

 

--tail

=> 마지막 확인 할 줄 수 선택

root@localhost:~# docker container logs --tail 10 91jos => 마지막 10줄 확인

[ OK ]

root@3716d5ffee84:/#

root@3716d5ffee84:/#

root@3716d5ffee84:/# netstat -nltp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 33/apache2

root@3716d5ffee84:/# exit

exit

 

--timestamp

=> 출력되는 로그에 시간 확인

root@localhost:~# docker container logs --timestamps 91jos

 

2018-07-24T01:19:57.331933932Z root@3716d5ffee84:/#

2018-07-24T01:19:57.459854229Z root@3716d5ffee84:/#

2018-07-24T01:19:59.685324884Z root@3716d5ffee84:/# netstat -nltp

2018-07-24T01:19:59.692058005Z Active Internet connections (only servers)

2018-07-24T01:19:59.693098157Z Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

2018-07-24T01:20:04.912561626Z root@3716d5ffee84:/# /etc/init.d/apache2 start

2018-07-24T01:20:06.212939263Z * Starting Apache httpd web server apache2

 

--until

=> since 와 반대되는 옵션 입니다.

root@localhost:~# docker container logs --until 2018-07-25 91jos

 

root@3716d5ffee84:/etc/apache2/mods-available# /etc/init.d/apache2 restart

* Restarting Apache httpd web server apache2 [ OK ]

root@3716d5ffee84:/#

root@3716d5ffee84:/#

root@3716d5ffee84:/#

root@3716d5ffee84:/# netstat -nltp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

root@3716d5ffee84:/# /etc/init.d/apache2 start

* Starting Apache httpd web server apache2

 

1-2 서비스에 대한 로그 확인

=> 서비스에 대한 로그를 확인하려면 docker version 명령어로 API version을 확인하여야 합니다.

Client, Server API version1.29이상 이여야 합니다.

root@localhost:~# docker version

 

Client:

Version: 18.06.0-ce

API version: 1.38

Go version: go1.10.3

Git commit: 0ffa825

Built: Wed Jul 18 19:11:02 2018

OS/Arch: linux/amd64

Experimental: false

 

Server:

Engine:

Version: 18.06.0-ce

API version: 1.38 (minimum version 1.12)

Go version: go1.10.3

Git commit: 0ffa825

Built: Wed Jul 18 19:09:05 2018

OS/Arch: linux/amd64

Experimental: false

 

> docker 서비스 로그 확인

- docker service logs [OPTIONS] SERVICE|TASK

--datails : 로그에 추가 세부 정보 표시 (API 1.30 이상이여야 합니다)

--follow, -f : 로그 출력을 따르십시오

--no-resolve : 로그 출력시 ID에 이름을 매핑하지 않는다.

--no-task-ids : 작업 ID를 출력하지 않는다.

--no-trunc : 로그 출력을 자르지 않는다.

--raw : 로그를 깔끔하게 정리하지 않는다.

--since : 특정시간 이후에 대한 로그 출력

--tail : 로그 끝에 표시할 줄 수 (기본값은 all)

--timestamps, -t : 타임스탬프 표시