container에 접속하기
현재 run 된 docker container 가 아래와 같을때
~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef00e3c232c0 redis:6.2 "docker-entrypoint.s…" 12 days ago Up 3 days redis
0fcb433753db eclipse-mosquitto "/docker-entrypoint.…" 3 months ago Up 3 days mosquitto
docker exec -it <container_name> <command>
format으로 실행한다.
예: sudo docker exec -it redis /bin/bash
~$ sudo docker exec -it redis /bin/bash
/data#
/data# cd ..
/# ls -al
total 80
drwxr-xr-x 1 root root 4096 Oct 7 08:50 .
drwxr-xr-x 1 root root 4096 Oct 7 08:50 ..
-rwxr-xr-x 1 root root 0 Oct 7 08:50 .dockerenv
drwxr-xr-x 1 root root 4096 Oct 5 09:34 bin
drwxr-xr-x 2 root root 4096 Sep 3 12:10 boot
drwxrwxrwx 2 redis root 4096 Oct 7 08:52 data
drwxr-xr-x 5 root root 340 Oct 16 07:08 dev
drwxr-xr-x 1 root root 4096 Oct 7 08:50 etc
drwxr-xr-x 2 root root 4096 Sep 3 12:10 home
drwxr-xr-x 1 root root 4096 Oct 5 09:34 lib
drwxr-xr-x 2 root root 4096 Oct 4 00:00 lib64
drwxr-xr-x 2 root root 4096 Oct 4 00:00 media
drwxr-xr-x 2 root root 4096 Oct 4 00:00 mnt
drwxr-xr-x 2 root root 4096 Oct 4 00:00 opt
dr-xr-xr-x 444 root root 0 Oct 16 07:08 proc
drwx------ 1 root root 4096 Oct 5 09:32 root
drwxr-xr-x 3 root root 4096 Oct 4 00:00 run
drwxr-xr-x 2 root root 4096 Oct 4 00:00 sbin
drwxr-xr-x 2 root root 4096 Oct 4 00:00 srv
dr-xr-xr-x 13 root root 0 Oct 16 07:08 sys
drwxrwxrwt 1 root root 4096 Oct 5 09:34 tmp
drwxr-xr-x 1 root root 4096 Oct 4 00:00 usr
drwxr-xr-x 1 root root 4096 Oct 4 00:00 var
/#
docker container log 확인
docker container에서 발생하는 log를 파일로 확인하는 과정을 설명한다.
docker container가 아닌 host에 저장되는 log를 확인하는 과정임에 유의한다.
1. root 로 전환
/etc/docker$ sudo -i
~#
2. log folder로 이동
~# cd /var/lib/docker/containers
/var/lib/docker/containers#
/var/lib/docker/containers# ll
합계 16
drwx--x--- 4 root root 4096 10월 7 17:50 ./
drwx--x--- 13 root root 4096 10월 16 16:08 ../
drwx--x--- 4 root root 4096 10월 19 17:48 0fcb433753db653b44f60800a8bba94288538926ca2596ce6bb294124367fd2f/
drwx--x--- 4 root root 4096 10월 19 17:32 ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686/
/var/lib/docker/containers#
3. docker ps -a
/var/lib/docker/containers# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef00e3c232c0 redis:6.2 "docker-entrypoint.s…" 12 days ago Up 3 days redis
0fcb433753db eclipse-mosquitto "/docker-entrypoint.…" 3 months ago Up 3 days mosquitto
/var/lib/docker/containers#
redis container의 CONTAINER ID 는 ef00e3c232c0 인데 이는
/var/lib/docker/containers 하위 directory 중 “ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686"에 log가 쌓인다.
4. container log directory
/var/lib/docker/containers# cd ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686/
/var/lib/docker/containers/ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686# ll
합계 44
drwx--x--- 4 root root 4096 10월 19 20:18 ./
drwx--x--- 4 root root 4096 10월 7 17:50 ../
drwx------ 2 root root 4096 10월 7 17:50 checkpoints/
-rw------- 1 root root 3448 10월 16 16:08 config.v2.json
-rw-r----- 1 root root 4686 10월 16 16:08 ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686-json.log
-rw-r--r-- 1 root root 1630 10월 16 16:08 hostconfig.json
-rw-r--r-- 1 root root 14 10월 16 16:08 hostname
-rw-r--r-- 1 root root 228 10월 16 16:08 hosts
drwx--x--- 2 root root 4096 10월 7 17:50 mounts/
-rw-r--r-- 1 root root 717 10월 16 16:08 resolv.conf
/var/lib/docker/containers/ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686#
위 와 같이 “ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686“ 내 에는 여러 파일들이 존재하며
그 중 ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686-json.log 에 실제 log가 json format으로 저장되어 있다.
예: ef00e3c232c014a998a9b39c7c2329835b8ac1eb02c6e5ace31bafc251f02686-json.log
{"log":"1:C 07 Oct 2022 08:50:43.867 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo\n","stream":"stdout","time":"2022-10-07T08:50:43.867438086Z"}
{"log":"1:C 07 Oct 2022 08:50:43.867 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=1, just started\n","stream":"stdout","time":"2022-10-07T08:50:43.867457124Z"}
{"log":"1:C 07 Oct 2022 08:50:43.867 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf\n","stream":"stdout","time":"2022-10-07T08:50:43.867459376Z"}
{"log":"1:M 07 Oct 2022 08:50:43.867 * monotonic clock: POSIX clock_gettime\n","stream":"stdout","time":"2022-10-07T08:50:43.867817742Z"}
{"log":"1:M 07 Oct 2022 08:50:43.867 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.\n","stream":"stdout","time":"2022-10-07T08:50:43.867959983Z"}
{"log":"1:M 07 Oct 2022 08:50:43.867 * Running mode=standalone, port=6379.\n","stream":"stdout","time":"2022-10-07T08:50:43.86799153Z"}
{"log":"1:M 07 Oct 2022 08:50:43.867 # Server initialized\n","stream":"stdout","time":"2022-10-07T08:50:43.868008499Z"}
{"log":"1:M 07 Oct 2022 08:50:43.868 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.\n","stream":"stdout","time":"2022-10-07T08:50:43.868017901Z"}
{"log":"1:M 07 Oct 2022 08:50:43.868 * Ready to accept connections\n","stream":"stdout","time":"2022-10-07T08:50:43.868163249Z"}
{"log":"1:signal-handler (1665132740) Received SIGTERM scheduling shutdown...\n","stream":"stdout","time":"2022-10-07T08:52:20.524778581Z"}
{"log":"1:M 07 Oct 2022 08:52:20.577 # User requested shutdown...\n","stream":"stdout","time":"2022-10-07T08:52:20.578268329Z"}
{"log":"1:M 07 Oct 2022 08:52:20.577 * Saving the final RDB snapshot before exiting.\n","stream":"stdout","time":"2022-10-07T08:52:20.57830911Z"}
{"log":"1:M 07 Oct 2022 08:52:20.579 * DB saved on disk\n","stream":"stdout","time":"2022-10-07T08:52:20.579805999Z"}
{"log":"1:M 07 Oct 2022 08:52:20.579 # Redis is now ready to exit, bye bye...\n","stream":"stdout","time":"2022-10-07T08:52:20.57983426Z"}
{"log":"1:C 16 Oct 2022 07:08:54.620 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo\n","stream":"stdout","time":"2022-10-16T07:08:54.62025439Z"}
{"log":"1:C 16 Oct 2022 07:08:54.620 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=1, just started\n","stream":"stdout","time":"2022-10-16T07:08:54.620361064Z"}
{"log":"1:C 16 Oct 2022 07:08:54.620 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf\n","stream":"stdout","time":"2022-10-16T07:08:54.62036514Z"}
{"log":"1:M 16 Oct 2022 07:08:54.620 * monotonic clock: POSIX clock_gettime\n","stream":"stdout","time":"2022-10-16T07:08:54.620663622Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.\n","stream":"stdout","time":"2022-10-16T07:08:54.621198043Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 * Running mode=standalone, port=6379.\n","stream":"stdout","time":"2022-10-16T07:08:54.621217999Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 # Server initialized\n","stream":"stdout","time":"2022-10-16T07:08:54.621242347Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.\n","stream":"stdout","time":"2022-10-16T07:08:54.621251943Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 * Loading RDB produced by version 6.2.7\n","stream":"stdout","time":"2022-10-16T07:08:54.621492847Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 * RDB age 771394 seconds\n","stream":"stdout","time":"2022-10-16T07:08:54.621497705Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 * RDB memory usage when created 0.77 Mb\n","stream":"stdout","time":"2022-10-16T07:08:54.621507434Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 # Done loading RDB, keys loaded: 0, keys expired: 0.\n","stream":"stdout","time":"2022-10-16T07:08:54.621510042Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 * DB loaded from disk: 0.000 seconds\n","stream":"stdout","time":"2022-10-16T07:08:54.621513059Z"}
{"log":"1:M 16 Oct 2022 07:08:54.621 * Ready to accept connections\n","stream":"stdout","time":"2022-10-16T07:08:54.621515468Z"}
docker 컨테이너 log 남기기
docker 컨테이너 log 남기기 container안에서 어떤 일(에러 및 로그 정보)이 생기는지는 매우 중요합니다. 도커는 컨테이너의 표준 출력과 에러 로그를 별도의 메타데이터 파일로 저장하며 이를 확인
hoony-gunputer.tistory.com
'공부 > ServerSide' 카테고리의 다른 글
Linux NTP 설정 (0) | 2023.04.02 |
---|