관리 메뉴

Sysops Notepad

[Docker] Docker namespaces,cgroups 정리 본문

업무/etc

[Docker] Docker namespaces,cgroups 정리

sysops 2019. 7. 24. 10:43

namespace : VM에서는 각 게스트 머신별로 독립적인 공간을 제공하고 서로가 충돌하지 않도록 하는 기능

1. mnt (파일시스템 마운트): 호스트 파일시스템에 구애받지 않고 독립적으로 파일시스템을 마운트하거나 언마운트 가능
2. pid (프로세스): 독립적인 프로세스 공간을 할당
3. net (네트워크): namespace간에 network 충돌 방지 (중복 포트 바인딩 등)
4. ipc (SystemV IPC): 프로세스간의 독립적인 통신통로 할당
5. uts (hostname): 독립적인 hostname 할당
6. user (UID): 독립적인 사용자 할당

# unshare --fork --pid --mount-proc bash  // PID namespace 생성, nsenter로 접근 가능 (docker exec와 비슷)

nsenter 사용방법
# docker inspect -f '{{.State.Pid}}' {container_id or name}
# nsenter -t PID -n netstat 

cgroups (Control Groups) : 
자원(resources)에 대한 제어를 가능

1. 메모리
2. CPU
3. I/O
4. 네트워크
5. /dev

 

Test
# cgcreate -a testuser -g memory:testgroup  // cgroup 생성
# ls -alh /sys/fs/cgroup/memory/testgroup  // 확인
# echo 2000000 > /sys/fs/cgroup/memory/testgroup/memory.kmem.limit_in_bytes // 최대 메모리 사용량 2MB로 제한

# cgexec -g memory:testgroup bash ; top
top: error while loading shared libraries: libgpg-error.so.0: failed to map segment from shared object // 메모리 제한 확인


출처 및 참고:
https://tech.ssut.me/what-even-is-a-container/
https://aidanbae.github.io/code/docker/docker-netstat/

Comments