๐ŸŒฑ Infra/Container_Docker

[Docker-Basic (4)] Container Quota ์‚ฌ์šฉํ•˜๊ธฐ

mini_world 2020. 9. 28. 14:40
๋ชฉ์ฐจ ์ ‘๊ธฐ

 


 

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ์ปจํ…Œ์ด๋„ˆ์— CPU, Memory๋ฅผ ํ• ๋‹นํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

 

1. ์ปจํ…Œ์ด๋„ˆ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น

   1-1 ) ์ปจํ…Œ์ด๋„ˆ์— ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹นํ•˜๊ธฐ

์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹œ์ž‘ํ• ๋•Œ ์ปจํ…Œ์ด๋„ˆ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฆฌ์†Œ์Šค ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :)
๋จผ์ € ๋ฉ”๋ชจ๋ฆฌ๋ฅผ 100m ์ง€์ •ํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•ด๋ด…์‹œ๋‹ค.

[root@docker /]# docker run --name nginx -d -p 8080:80 --memory="100m" nginx
9fc9ccbf2a551a2bd4911d096a545b105c63762f9affb900390431a3df0402a0

docker inspect ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ปจํ…Œ์ด๋„ˆ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ปจํ…Œ์ด๋„ˆ์— ์ •๋ง ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น๋Ÿ‰์ด ์„ค์ • ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.

[root@docker /]# docker container inspect nginx | grep Memory
            "Memory": 104857600,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 209715200,
            "MemorySwappiness": null,

 

  1-2) ๋ฉ”๋ชจ๋ฆฌ ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ

๋ฉ”๋ชจ๋ฆฌ๋ฅผ 100m์—์„œ 200m๋กœ ์—…๋ฐ์ดํŠธ ํ•ฉ๋‹ˆ๋‹ค.

[root@docker /]# docker container update --memory='200m' nginx
nginx

๋ฉ”๋ชจ๋ฆฌ ์Šค์™‘ ํฌ๊ธฐ๋„ 500m๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

[root@docker /]# docker container update --memory-swap='500m' nginx
nginx

๋ณ€๊ฒฝ ๋‚ด์šฉ์ด ์ž˜ ๋ฐ˜์˜ ๋˜์—ˆ๋Š”์ง€ inspect ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.

[root@docker /]# docker container inspect nginx | grep Memory
            "Memory": 209715200,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 524288000,
            "MemorySwappiness": null,

 

* ๋ฉ”๋ชจ๋ฆฌ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์˜ต์…˜์„ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
docs.docker.com/engine/reference/commandline/container_update/

 

 

2. ์ปจํ…Œ์ด๋„ˆ CPU ํ• ๋‹น

  2-1) CPU ๊ณ ์ • ํ• ๋‹น ํ•˜๊ธฐ

ํŠน์ • ์ปจํ…Œ์ด๋„ˆ์— ๊ณ ์ •๋œ CPU์ž์›์„ ํ• ๋‹นํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ปจํ…Œ์ด๋„ˆ์— ๋ฌผ๋ฆฌ CPU๋ฅผ ๊ณ ์ •ํ•ด์„œ ํ• ๋‹นํ•ด์ฃผ๋Š” ๋ช…๋ น์–ด ์ž…๋‹ˆ๋‹ค. --cpuset-cpus=1 ๋œป์€ 2๋ฒˆ CPU๋งŒ ์จ๋ผ(๊ณ ์ •ํ• ๋‹น) ๋ผ๋Š” ์˜๋ฏธ ์ž…๋‹ˆ๋‹ค.

[root@docker /]# docker container run --name nginx -d -p 8080:80 --cpuset-cpus=1 nginx
37f6b2d8ff927c8357f3bc54aa2cea612b3baed5ca8c6bd493a77f6c20bfa48c

ํ• ๋‹น์ด ์ž˜ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด๋ณผ๊นŒ์š”? 
1๋ฒˆ CPU๊ฐ€ ํ• ๋‹น ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

[root@docker /]# docker container inspect nginx | grep Cpuset
            "CpusetCpus": "1",
            "CpusetMems": "",

 

 2-2) CPU ๊ฐœ์ˆ˜ ์„ ํƒ

ํŠน์ • CPU๋ฅผ ๊ณ ์ •ํ•ด์„œ ์‚ฌ์šฉํ•˜๋„๋ก ํ• ๋‹นํ•˜๋Š”๊ฒƒ ์™ธ  CPU๋ฅผ ์ตœ๋Œ€ ๋ช‡๊ฐœ๊นŒ์ง€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ• ์ง€๋„ ์„ค์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
ํ• ๋‹นํ•ด๋ด…์‹œ๋‹ค.

[root@docker /]# docker run --name nginx -d -p 8080:80 --cpus=2 nginx
6b8152cdb30970d639d6ce81aaec6f6d6a16a6159f3e68c4e28578215ca29a9e

์ปจํ…Œ์ด๋„ˆ์— ํ• ๋‹น๋œ CPU๋ฅผ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.

[root@docker /]# docker container inspect nginx | grep NanoCpu
            "NanoCpus": 2000000000,
728x90