LinuxϵÄDocker£ºÔõÑù°ü¹ÜÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ£¿
linuxϵÄdocker£ºÔõÑù°ü¹ÜÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ£¿
Ëæ×ÅÔÆÅÌËãºÍÈÝÆ÷ÊÖÒյĿìËÙÉú³¤£¬DockerÒѾ³ÉΪÁËÒ»¸öºÜÊÇÊ¢ÐеÄÈÝÆ÷»¯Æ½Ì¨¡£Docker²»µ«ÌṩÁËÇáÁ¿¼¶¡¢¿ÉÒÆÖ²ºÍ¿ÉÀ©Õ¹µÄÈÝÆ÷ÇéÐΣ¬²¢ÇÒ»¹¾ß±¸ÓÅÒìµÄÇå¾²ÐԺ͸ôÀëÐÔ¡£±¾ÎĽ«ÏÈÈÝÔÚLinuxϵͳÏÂÔõÑù°ü¹ÜDockerÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ£¬²¢¸ø³öһЩÏà¹ØµÄ´úÂëʾÀý¡£
ʹÓÃ×îеÄDocker°æ±¾
DockerÊÇÒ»¸ö»îÔ¾µÄ¿ªÔ´ÏîÄ¿£¬Ã¿¸ö°æ±¾¶¼»áÐÞ¸´Ò»Ð©Çå¾²Îó²îºÍÎÊÌâ¡£Òò´Ë£¬ÎªÁË°ü¹ÜÈÝÆ÷µÄÇå¾²ÐÔ£¬ÎÒÃÇÓ¦¸ÃʼÖÕʹÓÃ×îеÄDocker°æ±¾¡£ÔÚUbuntuϵͳÉÏ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´×°ÖÃ×îеÄDocker°æ±¾£º
sudo apt-get update sudo apt-get install docker-ce
µÇ¼ºó¸´ÖÆ
ÉèÖÃDockerµÄÇ徲ѡÏî
DockerÌṩÁËһЩÇ徲ѡÏ¿ÉÒÔÉèÖÃÈÝÆ÷µÄ¸ôÀ뼶±ðºÍȨÏÞ¡£ÔÚDockerµÄÉèÖÃÎļþÖУ¬¿ÉÒÔÉèÖÃÒÔϵÄÑ¡Ï
# ÉèÖÃÈÝÆ÷µÄ¸ôÀ뼶±ð£¬ÍƼöʹÓÃĬÈÏÖµ --security-opt seccomp=unconfined # ½ûÓÃÈÝÆ÷µÄÍøÂ繦Ч£¬×èÖ¹ÈÝÆ÷±»ÓÃ×÷¹¥»÷ÆäËûÍøÂç×ÊÔ´ --security-opt no-new-privileges # ÏÞÖÆÈÝÆ÷µÄϵͳŲÓÃȨÏÞ£¬×èÖ¹ÈÝÆ÷ÀÄÓÃϵͳ×ÊÔ´ --security-opt apparmor=docker-default
µÇ¼ºó¸´ÖÆ
¿ÉÒÔƾ֤ÏÖʵÐèÇóÀ´ÉèÖÃÕâЩѡÏÒÔÌá¸ßÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ¡£
ʹÓý¡È«µÄ¾µÏñºÍÈÝÆ÷
DockerÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔÒ²ÓëËùʹÓõľµÏñºÍÈÝÆ÷×Ô¼ºÓйء£ÎÒÃÇÓ¦¸ÃÑ¡ÔñÀ´×Ô¿É¿¿ÈªÔ´µÄ¾µÏñ£¬²¢È·±£ËüÃÇÊǾÓÉÑéÖ¤ºÍרÃÅΪDockerÉè¼ÆµÄ¡£±ðµÄ£¬ÎÒÃÇ»¹Ó¦¸Ã°´ÆÚ¸üкÍÉý¼¶¾µÏñÖÐËùʹÓõÄÈí¼þ°üºÍÒÀÀµÏÒÔïÔÌDZÔÚµÄÇå¾²Îó²î¡£
ʹÓÃÇå¾²µÄÍøÂçÉèÖÃ
DockerÌṩÁ˶àÖÖÍøÂçÑ¡Ï¿ÉÒÔƾ֤ÏÖʵÐèÇóÀ´ÉèÖÃÈÝÆ÷µÄÍøÂ硣ΪÁË°ü¹ÜÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔϵÄÍøÂçÉèÖãº
# ʹÓÃÇŽÓÍøÂ磬ÿ¸öÈÝÆ÷¶¼ÓÐ×Ô¼ºµÄIPµØµã --network bridge # ÏÞÖÆÈÝÆ÷µÄÍøÂçÁ÷Á¿£¬Ö»ÔÊÐíÌض¨µÄ¶Ë¿ÚºÍÐÒé --publish <host-port>:<container-port>/<protocol> # ÉèÖÃÈÝÆ÷µÄÍøÂçÕ½ÂÔ£¬Ö»ÔÊÐíÓëÌض¨IPµØµã»òÍøÂç¾ÙÐÐͨѶ --network-policy <ip-address>/<subnet>
µÇ¼ºó¸´ÖÆ
¿ÉÒÔƾ֤ÏÖʵÐèÇóÀ´ÉèÖÃÕâЩÍøÂçÑ¡ÏÒÔÌá¸ßÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ¡£
ʹÓÃÈÝÆ÷µÄÏÞÖƺÍ×ÊÔ´¿ØÖÆ
LinuxϵͳÌṩÁËһЩ»úÖÆÀ´ÏÞÖƺͿØÖÆÀú³ÌµÄ×ÊԴʹÓá£ÎÒÃÇ¿ÉÒÔʹÓÃÕâЩ»úÖÆÀ´ÏÞÖƺͿØÖÆDockerÈÝÆ÷µÄ×ÊԴʹÓã¬ÒÔ°ü¹ÜÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ¡£ÒÔÏÂÊÇһЩ³£ÓõÄ×ÊÔ´¿ØÖÆÑ¡Ï
# ÏÞÖÆÈÝÆ÷µÄCPUʹÓà --cpu-shares <shares> # ÏÞÖÆÈÝÆ÷µÄÄÚ´æʹÓà --memory <memory-limit> # ÏÞÖÆÈÝÆ÷µÄ´ÅÅÌʹÓà --storage-opt size=<size-limit>
µÇ¼ºó¸´ÖÆ
¿ÉÒÔƾ֤ÏÖʵÐèÇóÀ´ÉèÖÃÕâЩ×ÊÔ´¿ØÖÆÑ¡ÏÒÔÌá¸ßÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ¡£
×ÛÉÏËùÊö£¬°ü¹ÜDockerÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔÔÚLinuxϵͳÏÂÊǺÜÊÇÖ÷ÒªµÄ¡£Í¨¹ýʹÓÃ×îеÄDocker°æ±¾¡¢ÉèÖÃÇ徲ѡÏʹÓý¡È«µÄ¾µÏñºÍÈÝÆ÷¡¢Ê¹ÓÃÇå¾²µÄÍøÂçÉèÖÃÒÔ¼°Ê¹ÓÃÈÝÆ÷µÄÏÞÖƺÍ×ÊÔ´¿ØÖÆ£¬ÎÒÃÇ¿ÉÒÔÓÐÓõØÌá¸ßÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ¡£Òò´Ë£¬ÔÚʹÓÃDockerʱ£¬ÎñÐëÒª¹Ø×¢ÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ£¬²¢Æ¾Ö¤ÏÖʵÐèÇóÀ´¾ÙÐÐÏìÓ¦µÄÉèÖú͵÷ÓÅ¡£
£¨ÎÄÕÂͼÀý/ͼƬȪԴ£ºDocker¹Ù·½ÍøÕ¾£©
´úÂëʾÀý£º
# ½¨ÉèÒ»¸öÃûΪ"mycontainer"µÄÈÝÆ÷£¬²¢ÉèÖÃÇ徲ѡÏî docker run --name mycontainer --security-opt seccomp=unconfined --security-opt no-new-privileges --security-opt apparmor=docker-default ubuntu:latest
µÇ¼ºó¸´ÖÆ
# ½«ÈÝÆ÷µÄ80¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ8080¶Ë¿Ú£¬²¢Æô¶¯ÈÝÆ÷ docker run -d -p 8080:80 nginx:latest
µÇ¼ºó¸´ÖÆ
# ÏÞÖÆÈÝÆ÷µÄCPUʹÓÃΪ50% docker run --cpu-shares 512 mycontainer
µÇ¼ºó¸´ÖÆ
# ÏÞÖÆÈÝÆ÷µÄÄÚ´æʹÓÃΪ512MB docker run --memory 512m mycontainer
µÇ¼ºó¸´ÖÆ
ÒÔÉÏÊÇһЩDockerÈÝÆ÷µÄÏà¹ØÉèÖúÍÏÂÁîʾÀý£¬¿ÉÒÔƾ֤ÏÖʵÐèÇóÀ´Ê¹Óú͵÷½â¡£
ÒÔÉϾÍÊÇLinuxϵÄDocker£ºÔõÑù°ü¹ÜÈÝÆ÷µÄÇå¾²ÐԺ͸ôÀëÐÔ£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡