Docker 컨테이너에서 OOM 킬러 컨테이너 재시작 문제를 해결하는 방법은 무엇입니까?
4767
Created On 05/29/25 21:30 PM - Last Modified 07/09/25 17:28 PM
Objective
- 다음 Docker 명령의 출력을 검토하세요.
- 도커 ps
- 도커 검사
- 도커 통계
목표는 Docker 컨테이너가 다시 시작되었는지 확인하는 것입니다. 그렇다면 OOM 킬러가 컨테이너 다시 시작의 원인인지 확인합니다.
Environment
- Linux/macOS 머신
- 도커 런타임
Procedure
- 도커 PS
1. 이 명령은 사용자 환경에서 실행 중인 컨테이너를 표시합니다.
2. 컨테이너가 얼마나 오랫동안 사용되었는지 확인하려면 STATUS 열을 확인해야 합니다.
건강하게 잘 달리고 있어요.
3. 실행 시간은 컨테이너가 2시간(이 경우) 후에 다시 시작/재생성되었음을 증명합니다. - 도커 검사
1. 아래에 표시된 스니펫은 이 명령의 출력에서 잘라낸 것으로, OOM 킬러가 컨테이너가 다운되거나 종료된 원인임을 확인합니다.
컨테이너는 마지막으로 FinishedAt": "2025-05-19T13:42:31.566652718Z 에 종료되었습니다. OOM 킬러 프로세스.
2. 이 명령의 출력에는 "RestartCount": 41을 언급하는 스니펫이 하나 더 있거나 한 줄이 더 있습니다. - 도커 통계
1. 이 명령은 컨테이너에 설정된 cgroup 제한을 표시하는데, 이는 재시작을 유발하는 초과일 가능성이 높습니다.
해결:
도커 업데이트하다 명령은 특정 리소스 제한 및 구성 옵션을 수정할 수 있는 강력한 유틸리티입니다.컨테이너 실행작업을 중단하고 다시 생성할 필요 없이, 작업 부하에 따라 리소스 할당을 동적으로 조정하는 데 매우 유용합니다.
도커 업데이트 방법은 다음과 같습니다. 특히 리소스 제한과 관련된 작업:
-
메모리 제한:
--memoryor-m: Sets the maximum amount of memory the container can use (e.g.,512m,2g). If a container exceeds this limit, it may be OOMKilled (Out Of Memory Killed) by the system.--memory-swap: The total amount of memory and swap the container can use. If you set--memorybut not--memory-swap, the container can use swap space up to twice the memory limit (if host swap is enabled). To prevent a container from using any swap, set--memory-swapto the same value as--memory
- 이 사용 사례에서는 4Gi 메모리가 컨테이너에 충분하지 않아 컨테이너가 재시작되는 현상이 발생합니다. 다음 명령을 사용하여 이 설정을 변경할 수 있습니다.
docker update --memory=6g <name-of-the-container>
다음 사항을 참고하시기 바랍니다.
- Memory Swap (
--memory-swap): Allows you to update the total memory the container can use (RAM + Swap).- If
--memory-swapis set to the same value as--memory, the container cannot use swap. - If
--memory-swapis-1, the container can use unlimited swap (up to the host's available swap). - If
--memoryis set and--memory-swapis not, the container can use swap up to the same amount as the memory limit (total 2x the memory limit)
- If
Additional Information
다음 명령을 사용하여 OOM 메시지를 확인할 수 있습니다.
sudo dmesg -T | grep -i "oom-killer" or sudo journalctl -k | grep -i "oom-killer"