ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×ÊÔ´ÖÎÀíºÍÓÅ»¯
ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×ÊÔ´ÖÎÀíºÍÓÅ»¯£¬ÐèÒªÏêϸ´úÂëʾÀý
СÐò£º
Ëæ×ÅÔÆÅÌËãºÍÈÝÆ÷ÊÖÒյĿìËÙÉú³¤£¬Docker×÷ΪÏÖÔÚ×îÊܽӴýµÄÈÝÆ÷ÒýÇæÖ®Ò»£¬±»ÆÕ±éÓ¦ÓÃÓÚÈí¼þ¿ª·¢¡¢²âÊԺͰ²Åŵȳ¡¾°¡£È»¶ø£¬¹ØÓÚDockerÈÝÆ÷µÄ×ÊÔ´ÖÎÀíºÍÓÅ»¯£¬²»µ«ÄÜÌá¸ßÐÔÄÜ£¬»¹ÄܽÚÔ¼×ÊÔ´ÏûºÄºÍ±¾Ç®¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×ÊÔ´ÖÎÀíºÍÓÅ»¯£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
Ò»¡¢ÈÝÆ÷×ÊÔ´ÖÎÀí
CPU×ÊÔ´ÖÎÀí
£¨1£©ÏÞÖÆÈÝÆ÷µÄCPUʹÓÃÂÊ
ʹÓÃDockerÏÂÁîdocker runµÄ–cpus²ÎÊý£¬¿ÉÒÔÏÞÖÆÈÝÆ÷µÄCPUʹÓÃÂÊ¡£ÀýÈ磬ÏÞÖÆÈÝÆ÷Ö»ÄÜʹÓÃÒ»¸öCPUµÄ50%£º
docker run --cpus=0.5 [Image]
µÇ¼ºó¸´ÖÆ
£¨2£©ÉèÖÃCPUÓÅÏȼ¶
ʹÓÃDockerÏÂÁîdocker runµÄ–cpu-shares²ÎÊý£¬¿ÉÒÔÉèÖÃÈÝÆ÷µÄCPUÓÅÏȼ¶¡£Ä¬ÈÏÇéÐÎÏ£¬ËùÓÐÈÝÆ÷µÄCPUȨÖØֵΪ1024£¬¿ÉÒÔƾ֤ÐèÇóµ÷½â¡£ÀýÈ磬Ìá¸ßÈÝÆ÷µÄCPUÓÅÏȼ¶£º
docker run --cpu-shares=2048 [Image]
µÇ¼ºó¸´ÖÆ
ÄÚ´æ×ÊÔ´ÖÎÀí
£¨1£©ÏÞÖÆÈÝÆ÷µÄÄÚ´æʹÓÃ
ʹÓÃDockerÏÂÁîdocker runµÄ–memory²ÎÊý£¬¿ÉÒÔÏÞÖÆÈÝÆ÷µÄÄÚ´æʹÓÃÁ¿¡£ÀýÈ磬ÏÞÖÆÈÝÆ÷×î´óʹÓÃ100MBµÄÄڴ棺
docker run --memory=100m [Image]
µÇ¼ºó¸´ÖÆ
£¨2£©ÉèÖÃÄÚ´æ½»Á÷¿Õ¼ä
ʹÓÃDockerÏÂÁîdocker runµÄ–memory-swap²ÎÊýºÍ–memory²ÎÊýÅäºÏʹÓ㬿ÉÒÔÉèÖÃÈÝÆ÷µÄÄÚ´æ½»Á÷¿Õ¼ä¡£ÄÚ´æ½»Á÷¿Õ¼äµÄ¾ÞϸӦƾ֤ÏÖʵÐèÇó¾ÙÐе÷½â£º
docker run --memory=100m --memory-swap=200m [Image]
µÇ¼ºó¸´ÖÆ
ÍøÂç×ÊÔ´ÖÎÀí
£¨1£©ÉèÖÃÈÝÆ÷µÄÍøÂç´ø¿í
ʹÓÃDockerÏÂÁîdocker runµÄ-p²ÎÊý£¬¿ÉÒÔÉèÖÃÈÝÆ÷µÄÍøÂç´øÍÑÆÚÖÆ¡£ÀýÈ磬ÏÞÖÆÈÝÆ÷µÄ´ø¿íΪ100Mbit/s£º
docker run -p 8080:80 --network=traefiknet --network-alias=myweb -d [Image] tc qdisc add dev eth0 root tbf rate 100mbit burst 10k latency 70ms
µÇ¼ºó¸´ÖÆ
£¨2£©ÉèÖÃÈÝÆ÷µÄÍøÂçÓÅÏȼ¶
ʹÓÃDockerÏÂÁîdocker runµÄ–network-priority²ÎÊý£¬¿ÉÒÔÉèÖÃÈÝÆ÷µÄÍøÂçÓÅÏȼ¶¡£ÀýÈ磬Ìá¸ßÈÝÆ÷µÄÍøÂçÓÅÏȼ¶£º
docker run --network-priority high [Image]
µÇ¼ºó¸´ÖÆ
¶þ¡¢ÈÝÆ÷×ÊÔ´ÓÅ»¯
¶àÈÝÆ÷°²ÅÅ
½«¶à¸öÏà¹ØµÄÈÝÆ÷°²ÅÅÔÚͳһ¸öÖ÷»úÉÏ£¬¿ÉÒÔ¹²ÏíÓ²¼þ×ÊÔ´£¬Ìá¸ß×ÊԴʹÓÃÂʺÍÐÔÄÜ¡£ÀýÈ磬½«WebЧÀÍÆ÷ºÍÊý¾Ý¿âÈÝÆ÷°²ÅÅÔÚͳһÖ÷»úÉÏ£¬¿ÉÒÔ×èÖ¹ÍøÂçÑӳٺʹ«Ê俪Ïú¡£
ʹÓÃÇáÁ¿¼¶µÄ»ù´¡¾µÏñ
Ñ¡ÔñʹÓÃÇáÁ¿¼¶µÄ»ù´¡¾µÏñ£¬¿ÉÒÔ¼õСÈÝÆ÷µÄÌå»ýºÍÄÚ´æÕ¼Óã¬Ìá¸ßÈÝÆ÷µÄÆô¶¯ËÙÂʺÍÔËÐÐЧÂÊ¡£ÀýÈ磬ʹÓÃAlpine Linux×÷Ϊ»ù´¡¾µÏñ£º
FROM alpine:latest
µÇ¼ºó¸´ÖÆ
×èÖ¹²»ÐëÒªµÄÈÝÆ÷²Ù×÷
Ö»¹Ü×èÖ¹ÔÚÈÝÆ÷ÔËÐÐʱ¾ÙÐв»ÐëÒªµÄ²Ù×÷£¬ÀýÈ粻ҪƵÈÔµØÖØÆôÈÝÆ÷»òÖ´ÐÐÎÞЧµÄÏÂÁ×èÖ¹×ÊÔ´µÄÆÌÕźÍÐÔÄܵÄϽµ¡£
°´ÆÚÕûÀíÎÞÓõÄÈÝÆ÷ºÍ¾µÏñ
°´ÆÚÕûÀíÎÞÓõÄÈÝÆ÷ºÍ¾µÏñ£¬¿ÉÒÔÊÍ·Å´ÅÅÌ¿Õ¼äºÍÄÚ´æÕ¼Ó㬲¢×èÖ¹×ÊÔ´µÄÆÌÕÅ¡£¿ÉÒÔʹÓÃDockerÏÂÁîdocker rmºÍdocker rmiÀ´É¾³ýÎÞÓõÄÈÝÆ÷ºÍ¾µÏñ¡£
½áÂÛ£º
ͨ¹ýºÏÀíµÄ×ÊÔ´ÖÎÀíºÍÓÅ»¯£¬¿ÉÒÔÌá¸ßÈÝÆ÷µÄÐÔÄÜ¡¢½ÚÔ¼×ÊÔ´ÏûºÄºÍ±¾Ç®¡£±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×ÊÔ´ÖÎÀíºÍÓÅ»¯£¬²¢ÌṩÁËÏêϸµÄ´úÂëʾÀý¡£Ï£ÍûÄܶԶÁÕßÔÚÏÖʵʹÓÃÖÐÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×ÊÔ´ÖÎÀíºÍÓÅ»¯µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡