ÎÊÌâµ¼¶Á£º
1.Docker ClientÈçºÎÓëDocker Daemon½»»¥£¿
2.Docker ServerµÄ¹¦ÄÜÊÇ£¿
3.ʲôÊÇDocker Container£¿
1 ±³¾°1.1 Docker¼ò½éDockerÊÇDocker¹«Ë¾¿ªÔ´µÄÒ»¸ö»ùÓÚÇáÁ¿¼¶ÐéÄ⻯¼¼ÊõµÄÈÝÆ÷ÒýÇæÏîÄ¿,Õû¸öÏîÄ¿»ùÓÚGoÓïÑÔ¿ª·¢£¬²¢×ñ´ÓApache 2.0ÐÒ顣Ŀǰ£¬Docker¿ÉÒÔÔÚÈÝÆ÷ÄÚ²¿¿ìËÙ×Ô¶¯»¯²¿ÊðÓ¦Ó㬲¢¿ÉÒÔͨ¹ýÄÚºËÐéÄ⻯¼¼Êõ£¨namespaces¼°cgroupsµÈ£©À´ÌṩÈÝÆ÷µÄ×ÊÔ´¸ôÀëÓ밲ȫ±£Õϵȡ£ÓÉÓÚDockerͨ¹ý²Ù×÷ϵͳ²ãµÄÐéÄ⻯ʵÏÖ¸ôÀ룬ËùÒÔDockerÈÝÆ÷ÔÚÔËÐÐʱ£¬²»ÐèÒªÀàËÆÐéÄâ»ú£¨VM£©¶îÍâµÄ²Ù×÷ϵͳ¿ªÏú£¬Ìá¸ß×ÊÔ´ÀûÓÃÂÊ£¬²¢ÇÒÌáÉýÖîÈçIOµÈ·½ÃæµÄÐÔÄÜ¡£
´ÓÄ¿Ç°µÄÐÎÊÆÀ´¿´£¬DockerµÄÇ°¾°Ò»Æ¬´óºÃ¡£±¾ÏµÁÐÎÄÕ´ÓÔ´ÂëµÄ½Ç¶È³ö·¢£¬Ïêϸ½éÉÜDockerµÄ¼Ü¹¹¡¢DockerµÄÔËÐÐÒÔ¼°DockerµÄ׿ԽÌØÐÔ¡£±¾ÎÄÊÇDockerÔ´Âë·ÖÎöϵÁеĵÚһƪ---¡ª¡ªDocker¼Ü¹¹Æª¡£
1.2 Docker°æ±¾ÐÅÏ¢±¾ÎĹØÓÚDocker¼Ü¹¹µÄ·ÖÎö¶¼ÊÇ»ùÓÚDockerµÄÔ´ÂëÓëDockerÏàÓ¦°æ±¾µÄÔËÐнá¹û£¬ÆäÖÐDockerΪ×îеÄ1.2°æ±¾¡£
2 Docker¼Ü¹¹·ÖÎöÄÚÈÝ°²Åű¾ÎĵÄÄ¿µÄÊÇ£ºÔÚÀí½âDockerÔ´´úÂëµÄ»ù´¡ÉÏ£¬·ÖÎöDocker¼Ü¹¹¡£·ÖÎö¹ý³ÌÖÐÖ÷Òª°´ÕÕÒÔÏÂÈý¸ö²½Öè½øÐУº
- DockerµÄ×ܼܹ¹Í¼Õ¹Ê¾
- Docker¼Ü¹¹Í¼ÄÚ²¿¸÷Ä£¿é¹¦ÄÜÓëʵÏÖ·ÖÎö
- ÒÔDockerÃüÁîµÄÖ´ÐÐΪÀý£¬½øÐÐDockerÔËÐÐÁ÷³Ì²ûÊö
3 Docker×ܼܹ¹Í¼Ñ§Ï°DockerµÄÔ´Âë²¢²»ÊÇÒ»¸ö¿ÝÔïµÄ¹ý³Ì£¬·´¶ø¿ÉÒÔ´ÓÖÐÀí½âDocker¼Ü¹¹µÄÉè¼ÆÔÀí¡£Docker¶ÔʹÓÃÕßÀ´½²ÊÇÒ»¸öC/SģʽµÄ¼Ü¹¹£¬¶øDockerµÄºó¶ËÊÇÒ»¸ö·Ç³£ËÉñîºÏµÄ¼Ü¹¹£¬Ä£¿é¸÷˾ÆäÖ°£¬²¢Óлú×éºÏ£¬Ö§³ÅDockerµÄÔËÐС£ ÔÚ´Ë£¬Ïȸ½ÉÏDocker×ܼܹ¹£¬Èçͼ3.1¡£
ͼ3.1 Docker×ܼܹ¹Í¼
Èçͼ3.1£¬²»ÄÑ¿´³ö£¬Óû§ÊÇʹÓÃDocker ClientÓëDocker Daemon½¨Á¢Í¨ÐÅ£¬²¢·¢ËÍÇëÇó¸øºóÕß¡£
¶øDocker Daemon×÷ΪDocker¼Ü¹¹ÖеÄÖ÷Ì岿·Ö£¬Ê×ÏÈÌṩServerµÄ¹¦ÄÜʹÆä¿ÉÒÔ½ÓÊÜDocker ClientµÄÇëÇ󣻶øºóEngineÖ´ÐÐDockerÄÚ²¿µÄһϵÁй¤×÷£¬Ã¿Ò»Ï×÷¶¼ÊÇÒÔÒ»¸öJobµÄÐÎʽµÄ´æÔÚ¡£
JobµÄÔËÐйý³ÌÖУ¬µ±ÐèÒªÈÝÆ÷¾µÏñʱ£¬Ôò´ÓDocker RegistryÖÐÏÂÔؾµÏñ£¬²¢Í¨¹ý¾µÏñ¹ÜÀíÇý¶¯graphdriver½«ÏÂÔؾµÏñÒÔGraphµÄÐÎʽ´æ´¢£»µ±ÐèҪΪDocker´´½¨ÍøÂç»·¾³Ê±£¬Í¨¹ýÍøÂç¹ÜÀíÇý¶¯networkdriver´´½¨²¢ÅäÖÃDockerÈÝÆ÷ÍøÂç»·¾³£»µ±ÐèÒªÏÞÖÆDockerÈÝÆ÷ÔËÐÐ×ÊÔ´»òÖ´ÐÐÓû§Ö¸ÁîµÈ²Ù×÷ʱ£¬Ôòͨ¹ýexecdriverÀ´Íê³É¡£
¶ølibcontainerÊÇÒ»Ïî¶ÀÁ¢µÄÈÝÆ÷¹ÜÀí°ü£¬networkdriverÒÔ¼°execdriver¶¼ÊÇͨ¹ýlibcontainerÀ´ÊµÏÖ¾ßÌå¶ÔÈÝÆ÷½øÐеIJÙ×÷¡£
µ±Ö´ÐÐÍêÔËÐÐÈÝÆ÷µÄÃüÁîºó£¬Ò»¸öʵ¼ÊµÄDockerÈÝÆ÷¾Í´¦ÓÚÔËÐÐ״̬£¬¸ÃÈÝÆ÷ÓµÓжÀÁ¢µÄÎļþϵͳ£¬¶ÀÁ¢²¢ÇÒ°²È«µÄÔËÐл·¾³µÈ¡£
4 Docker¼Ü¹¹ÄÚ¸÷Ä£¿éµÄ¹¦ÄÜÓëʵÏÖ·ÖÎö½ÓÏÂÀ´£¬ÎÒÃǽ«´ÓDocker×ܼܹ¹Í¼ÈëÊÖ£¬³éÀë³ö¼Ü¹¹ÄÚ¸÷¸öÄ£¿é£¬²¢¶Ô¸÷¸öÄ£¿é½øÐиüΪϸ»¯µÄ¼Ü¹¹·ÖÎöÓ빦ÄܲûÊö¡£Ö÷ÒªµÄÄ£¿éÓУºDocker Client¡¢Docker Daemon¡¢Docker Registry¡¢Graph¡¢Driver¡¢libcontainerÒÔ¼°Docker container¡£
4.1 Docker ClientDocker ClientÊÇDocker¼Ü¹¹ÖÐÓû§ÓÃÀ´ºÍDocker Daemon½¨Á¢Í¨ÐŵĿͻ§¶Ë¡£Óû§Ê¹ÓõĿÉÖ´ÐÐÎļþΪdocker£¬Í¨¹ýdockerÃüÁîÐй¤¾ß¿ÉÒÔ·¢ÆðÖÚ¶à¹ÜÀícontainerµÄÇëÇó¡£
Docker Client¿ÉÒÔͨ¹ýÒÔÏÂÈýÖÖ·½Ê½ºÍDocker Daemon½¨Á¢Í¨ÐÅ£ºtcp://host:port£¬unix://path_to_socketºÍfd://socketfd¡£ÎªÁ˼òµ¥Æð¼û£¬±¾ÎÄÒ»ÂÉʹÓõÚÒ»ÖÖ·½Ê½×÷Ϊ½²ÊöÁ½ÕßͨÐŵÄÔÐÍ¡£Óë´Ëͬʱ£¬ÓëDocker Daemon½¨Á¢Á¬½Ó²¢´«ÊäÇëÇóµÄʱºò£¬Docker Client¿ÉÒÔͨ¹ýÉèÖÃÃüÁîÐÐflag²ÎÊýµÄÐÎʽÉèÖð²È«´«Êä²ãÐÒé(TLS)µÄÓйزÎÊý£¬±£Ö¤´«ÊäµÄ°²È«ÐÔ¡£
Docker Client·¢ËÍÈÝÆ÷¹ÜÀíÇëÇóºó£¬ÓÉDocker Daemon½ÓÊܲ¢´¦ÀíÇëÇ󣬵±Docker Client½ÓÊÕµ½·µ»ØµÄÇëÇóÏàÓ¦²¢¼òµ¥´¦Àíºó£¬Docker ClientÒ»´ÎÍêÕûµÄÉúÃüÖÜÆھͽáÊøÁË¡£µ±ÐèÒª¼ÌÐø·¢ËÍÈÝÆ÷¹ÜÀíÇëÇóʱ£¬Óû§±ØÐëÔÙ´Îͨ¹ýdocker¿ÉÖ´ÐÐÎļþ´´½¨Docker Client¡£
4.2 Docker DaemonDocker DaemonÊÇDocker¼Ü¹¹ÖÐÒ»¸ö³£×¤ÔÚºǫ́µÄϵͳ½ø³Ì£¬¹¦ÄÜÊÇ£º½ÓÊܲ¢´¦ÀíDocker Client·¢Ë͵ÄÇëÇ󡣸ÃÊØ»¤½ø³ÌÔÚºǫ́Æô¶¯ÁËÒ»¸öServer£¬Server¸ºÔð½ÓÊÜDocker Client·¢Ë͵ÄÇëÇó£»½ÓÊÜÇëÇóºó£¬Serverͨ¹ý·ÓÉÓë·Ö·¢µ÷¶È£¬ÕÒµ½ÏàÓ¦µÄHandlerÀ´Ö´ÐÐÇëÇó¡£
Docker DaemonÆô¶¯ËùʹÓõĿÉÖ´ÐÐÎļþҲΪdocker£¬ÓëDocker ClientÆô¶¯ËùʹÓõĿÉÖ´ÐÐÎļþdockerÏàͬ¡£ÔÚdockerÃüÁîÖ´ÐÐʱ£¬Í¨¹ý´«ÈëµÄ²ÎÊýÀ´ÅбðDocker DaemonÓëDocker Client¡£
Docker DaemonµÄ¼Ü¹¹£¬´óÖ¿ÉÒÔ·ÖΪÒÔÏÂÈý²¿·Ö£ºDocker Server¡¢EngineºÍJob¡£Daemon¼Ü¹¹Èçͼ4.1¡£
ͼ4.1 Docker Daemon¼Ü¹¹Ê¾Òâͼ
4.2.1 Docker ServerDocker ServerÔÚDocker¼Ü¹¹ÖÐÊÇרÃÅ·þÎñÓÚDocker ClientµÄserver¡£¸ÃserverµÄ¹¦ÄÜÊÇ£º½ÓÊܲ¢µ÷¶È·Ö·¢Docker Client·¢Ë͵ÄÇëÇó¡£Docker ServerµÄ¼Ü¹¹Èçͼ4.2¡£ ͼ4.2 Docker Server¼Ü¹¹Ê¾Òâͼ
ÔÚDockerµÄÆô¶¯¹ý³ÌÖУ¬Í¨¹ý°ügorilla/mux£¬´´½¨ÁËÒ»¸ömux.Router£¬ÌṩÇëÇóµÄ·Óɹ¦ÄÜ¡£ÔÚGolangÖУ¬gorilla/muxÊÇÒ»¸öÇ¿´óµÄURL·ÓÉÆ÷ÒÔ¼°µ÷¶È·Ö·¢Æ÷¡£¸Ãmux.RouterÖÐÌí¼ÓÁËÖÚ¶àµÄ·ÓÉÏÿһ¸ö·ÓÉÏîÓÉHTTPÇëÇó·½·¨£¨PUT¡¢POST¡¢GET»òDELETE£©¡¢URL¡¢HandlerÈý²¿·Ö×é³É¡£
ÈôDocker Clientͨ¹ýHTTPµÄÐÎʽ·ÃÎÊDocker Daemon£¬´´½¨Íêmux.RouterÖ®ºó£¬Docker½«ServerµÄ¼àÌýµØÖ·ÒÔ¼°mux.Router×÷Ϊ²ÎÊý£¬´´½¨Ò»¸öhttpSrv=http.Server{}£¬×îÖÕÖ´ÐÐhttpSrv.Serve()ΪÇëÇó·þÎñ¡£
ÔÚServerµÄ·þÎñ¹ý³ÌÖУ¬ServerÔÚlistenerÉϽÓÊÜDocker ClientµÄ·ÃÎÊÇëÇ󣬲¢´´½¨Ò»¸öȫеÄgoroutineÀ´·þÎñ¸ÃÇëÇó¡£ÔÚgoroutineÖУ¬Ê×ÏȶÁÈ¡ÇëÇóÄÚÈÝ£¬È»ºó×ö½âÎö¹¤×÷£¬½Ó×ÅÕÒµ½ÏàÓ¦µÄ·ÓÉÏËæºóµ÷ÓÃÏàÓ¦µÄHandlerÀ´´¦Àí¸ÃÇëÇó£¬×îºóHandler´¦ÀíÍêÇëÇóÖ®ºó»Ø¸´¸ÃÇëÇó¡£
ÐèҪעÒâµÄÊÇ£ºDocker ServerµÄÔËÐÐÔÚDockerµÄÆô¶¯¹ý³ÌÖУ¬ÊÇ¿¿Ò»¸öÃûΪ"serveapi"µÄjobµÄÔËÐÐÀ´Íê³ÉµÄ¡£ÔÔòÉÏ£¬Docker ServerµÄÔËÐÐÊÇÖÚ¶àjobÖеÄÒ»¸ö£¬µ«ÊÇΪÁËÇ¿µ÷Docker ServerµÄÖØÒªÐÔÒÔ¼°ÎªºóÐøjob·þÎñµÄÖØÒªÌØÐÔ£¬½«¸Ã"serveapi"µÄjobµ¥¶À³éÀë³öÀ´·ÖÎö£¬Àí½âΪDocker Server¡£
4.2.2 EngineEngineÊÇDocker¼Ü¹¹ÖеÄÔËÐÐÒýÇ棬ͬʱҲDockerÔËÐеĺËÐÄÄ£¿é¡£Ëü°çÑÝDocker container´æ´¢²Ö¿âµÄ½ÇÉ«£¬²¢ÇÒͨ¹ýÖ´ÐÐjobµÄ·½Ê½À´²Ù×ݹÜÀíÕâЩÈÝÆ÷¡£
ÔÚEngineÊý¾Ý½á¹¹µÄÉè¼ÆÓëʵÏÖ¹ý³ÌÖУ¬ÓÐÒ»¸öhandler¶ÔÏ󡣸Ãhandler¶ÔÏó´æ´¢µÄ¶¼ÊǹØÓÚÖÚ¶àÌض¨jobµÄhandler´¦Àí·ÃÎÊ¡£¾ÙÀý˵Ã÷£¬EngineµÄhandler¶ÔÏóÖÐÓÐÒ»ÏîΪ£º{"create": daemon.ContainerCreate,}£¬Ôò˵Ã÷µ±ÃûΪ"create"µÄjobÔÚÔËÐÐʱ£¬Ö´ÐеÄÊÇdaemon.ContainerCreateµÄhandler¡£
4.2.3 JobÒ»¸öJob¿ÉÒÔÈÏΪÊÇDocker¼Ü¹¹ÖÐEngineÄÚ²¿×î»ù±¾µÄ¹¤×÷Ö´Ðе¥Ôª¡£Docker¿ÉÒÔ×öµÄÿһÏ×÷£¬¶¼¿ÉÒÔ³éÏóΪһ¸öjob¡£ÀýÈ磺ÔÚÈÝÆ÷ÄÚ²¿ÔËÐÐÒ»¸ö½ø³Ì£¬ÕâÊÇÒ»¸öjob£»´´½¨Ò»¸öеÄÈÝÆ÷£¬ÕâÊÇÒ»¸öjob£¬´ÓInternetÉÏÏÂÔØÒ»¸öÎĵµ£¬ÕâÊÇÒ»¸öjob£»°üÀ¨Ö®Ç°ÔÚDocker Server²¿·Ö˵¹ýµÄ£¬´´½¨Server·þÎñÓÚHTTPµÄAPI£¬ÕâÒ²ÊÇÒ»¸öjob£¬µÈµÈ¡£
JobµÄÉè¼ÆÕߣ¬°ÑJobÉè¼ÆµÃÓëUnix½ø³ÌÏà·Â¡£±ÈÈç˵£ºJobÓÐÒ»¸öÃû³Æ£¬ÓвÎÊý£¬Óл·¾³±äÁ¿£¬Óбê×¼µÄÊäÈëÊä³ö£¬ÓдíÎó´¦Àí£¬Óзµ»Ø״̬µÈ¡£
4.3 Docker RegistryDocker RegistryÊÇÒ»¸ö´æ´¢ÈÝÆ÷¾µÏñµÄ²Ö¿â¡£¶øÈÝÆ÷¾µÏñÊÇÔÚÈÝÆ÷±»´´½¨Ê±£¬±»¼ÓÔØÓÃÀ´³õʼ»¯ÈÝÆ÷µÄÎļþ¼Ü¹¹ÓëĿ¼¡£
ÔÚDockerµÄÔËÐйý³ÌÖУ¬Docker Daemon»áÓëDocker RegistryͨÐÅ£¬²¢ÊµÏÖËÑË÷¾µÏñ¡¢ÏÂÔؾµÏñ¡¢ÉÏ´«¾µÏñÈý¸ö¹¦ÄÜ£¬ÕâÈý¸ö¹¦ÄܶÔÓ¦µÄjobÃû³Æ·Ö±ðΪ"search"£¬"pull" Óë "push"¡£
ÆäÖУ¬ÔÚDocker¼Ü¹¹ÖУ¬Docker¿ÉÒÔʹÓù«ÓеÄDocker Registry£¬¼´´ó¼ÒÊìÖªµÄ Docker Hub£¬Èç´ËÒ»À´£¬Docker»ñÈ¡ÈÝÆ÷¾µÏñÎļþʱ£¬±ØÐëͨ¹ý»¥ÁªÍø·ÃÎÊDocker Hub£»Í¬Ê±DockerÒ²ÔÊÐíÓû§¹¹½¨±¾µØ˽ÓеÄDocker Registry£¬ÕâÑù¿ÉÒÔ±£Ö¤ÈÝÆ÷¾µÏñµÄ»ñÈ¡ÔÚÄÚÍøÍê³É¡£
4.4 GraphGraphÔÚDocker¼Ü¹¹ÖаçÑÝÒÑÏÂÔØÈÝÆ÷¾µÏñµÄ±£¹ÜÕߣ¬ÒÔ¼°ÒÑÏÂÔØÈÝÆ÷¾µÏñÖ®¼ä¹ØϵµÄ¼Ç¼Õß¡£Ò»·½Ã棬Graph´æ´¢×ű¾µØ¾ßÓа汾ÐÅÏ¢µÄÎļþϵͳ¾µÏñ£¬ÁíÒ»·½ÃæҲͨ¹ýGraphDB¼Ç¼×ÅËùÓÐÎļþϵͳ¾µÏñ±Ë´ËÖ®¼äµÄ¹Øϵ¡£GraphµÄ¼Ü¹¹Èçͼ4.3¡£ ͼ4.3 Graph¼Ü¹¹Ê¾Òâͼ
ÆäÖУ¬GraphDBÊÇÒ»¸ö¹¹½¨ÔÚSQLiteÖ®ÉϵÄСÐÍͼÊý¾Ý¿â£¬ÊµÏÖÁ˽ڵãµÄÃüÃûÒÔ¼°½ÚµãÖ®¼ä¹ØÁª¹ØϵµÄ¼Ç¼¡£Ëü½ö½öʵÏÖÁË´ó¶àÊýͼÊý¾Ý¿âËùÓµÓеÄÒ»¸öСµÄ×Ó¼¯£¬µ«ÊÇÌṩÁ˼òµ¥µÄ½Ó¿Ú±íʾ½ÚµãÖ®¼äµÄ¹Øϵ¡£
ͬʱÔÚGraphµÄ±¾µØĿ¼ÖУ¬¹ØÓÚÿһ¸öµÄÈÝÆ÷¾µÏñ£¬¾ßÌå´æ´¢µÄÐÅÏ¢ÓУº¸ÃÈÝÆ÷¾µÏñµÄÔªÊý¾Ý£¬ÈÝÆ÷¾µÏñµÄ´óСÐÅÏ¢£¬ÒÔ¼°¸ÃÈÝÆ÷¾µÏñËù´ú±íµÄ¾ßÌårootfs¡£
4.5 DriverDriverÊÇDocker¼Ü¹¹ÖеÄÇý¶¯Ä£¿é¡£Í¨¹ýDriverÇý¶¯£¬Docker¿ÉÒÔʵÏÖ¶ÔDockerÈÝÆ÷Ö´Ðл·¾³µÄ¶¨ÖÆ¡£ÓÉÓÚDockerÔËÐеÄÉúÃüÖÜÆÚÖУ¬²¢·ÇÓû§ËùÓеIJÙ×÷¶¼ÊÇÕë¶ÔDockerÈÝÆ÷µÄ¹ÜÀí£¬ÁíÍ⻹ÓйØÓÚDockerÔËÐÐÐÅÏ¢µÄ»ñÈ¡£¬GraphµÄ´æ´¢Óë¼Ç¼µÈ¡£Òò´Ë£¬ÎªÁ˽«DockerÈÝÆ÷µÄ¹ÜÀí´ÓDocker DaemonÄÚ²¿ÒµÎñÂß¼ÖÐÇø·Ö¿ªÀ´£¬Éè¼ÆÁËDriver²ãÇý¶¯À´½Ó¹ÜËùÓÐÕⲿ·ÖÇëÇó¡£
ÔÚDocker DriverµÄʵÏÖÖУ¬¿ÉÒÔ·ÖΪÒÔÏÂÈýÀàÇý¶¯£ºgraphdriver¡¢networkdriverºÍexecdriver¡£
graphdriverÖ÷ÒªÓÃÓÚÍê³ÉÈÝÆ÷¾µÏñµÄ¹ÜÀí£¬°üÀ¨´æ´¢Óë»ñÈ¡¡£¼´µ±Óû§ÐèÒªÏÂÔØÖ¸¶¨µÄÈÝÆ÷¾µÏñʱ£¬graphdriver½«ÈÝÆ÷¾µÏñ´æ´¢ÔÚ±¾µØµÄÖ¸¶¨Ä¿Â¼£»Í¬Ê±µ±Óû§ÐèҪʹÓÃÖ¸¶¨µÄÈÝÆ÷¾µÏñÀ´´´½¨ÈÝÆ÷µÄrootfsʱ£¬graphdriver´Ó±¾µØ¾µÏñ´æ´¢Ä¿Â¼ÖлñÈ¡Ö¸¶¨µÄÈÝÆ÷¾µÏñ¡£
ÔÚgraphdriverµÄ³õʼ»¯¹ý³Ì֮ǰ£¬ÓÐ4ÖÖÎļþϵͳ»òÀàÎļþϵͳÔÚÆäÄÚ²¿×¢²á£¬ËüÃÇ·Ö±ðÊÇaufs¡¢btrfs¡¢vfsºÍdevmapper¡£¶øDockerÔÚ³õʼ»¯Ö®Ê±£¬Í¨¹ý»ñȡϵͳ»·¾³±äÁ¿¡±DOCKER_DRIVER¡±À´ÌáÈ¡ËùʹÓÃdriverµÄÖ¸¶¨ÀàÐÍ¡£¶øÖ®ºóËùÓеÄgraph²Ù×÷£¬¶¼Ê¹ÓøÃdriverÀ´Ö´ÐС£
graphdriverµÄ¼Ü¹¹Èçͼ4.4£º ͼ4.4 graphdriver¼Ü¹¹Ê¾Òâͼ
networkdriverµÄÓÃ;ÊÇÍê³ÉDockerÈÝÆ÷ÍøÂç»·¾³µÄÅäÖã¬ÆäÖаüÀ¨DockerÆô¶¯Ê±ÎªDocker»·¾³´´½¨ÍøÇÅ£»DockerÈÝÆ÷´´½¨Ê±ÎªÆä´´½¨×¨ÊôÐéÄâÍø¿¨É豸£»ÒÔ¼°ÎªDockerÈÝÆ÷·ÖÅäIP¡¢¶Ë¿Ú²¢ÓëËÞÖ÷»ú×ö¶Ë¿ÚÓ³É䣬ÉèÖÃÈÝÆ÷·À»ðǽ²ßÂԵȡ£networkdriverµÄ¼Ü¹¹Èçͼ4.5£º ͼ4. 5 networkdriver¼Ü¹¹Ê¾Òâͼ
execdriver×÷ΪDockerÈÝÆ÷µÄÖ´ÐÐÇý¶¯£¬¸ºÔð´´½¨ÈÝÆ÷ÔËÐÐÃüÃû¿Õ¼ä£¬¸ºÔðÈÝÆ÷×ÊԴʹÓõÄͳ¼ÆÓëÏÞÖÆ£¬¸ºÔðÈÝÆ÷ÄÚ²¿½ø³ÌµÄÕæÕýÔËÐеȡ£ÔÚexecdriverµÄʵÏÖ¹ý³ÌÖУ¬ÔÏÈ¿ÉÒÔʹÓÃLXCÇý¶¯µ÷ÓÃLXCµÄ½Ó¿Ú£¬À´²Ù×ÝÈÝÆ÷µÄÅäÖÃÒÔ¼°ÉúÃüÖÜÆÚ£¬¶øÏÖÔÚexecdriverĬÈÏʹÓÃnativeÇý¶¯£¬²»ÒÀÀµÓÚLXC¡£¾ßÌåÌåÏÖÔÚDaemonÆô¶¯¹ý³ÌÖмÓÔصÄExecDriverflag²ÎÊý£¬¸Ã²ÎÊýÔÚÅäÖÃÎļþÒѾ±»ÉèΪ"native"¡£Õâ¿ÉÒÔÈÏΪÊÇDockerÔÚ1.2°æ±¾ÉÏÒ»¸öºÜ´óµÄ¸Ä±ä£¬»òÕß˵DockerʵÏÖ¿çƽ̨µÄÒ»¸öÏÈÕס£execdriver¼Ü¹¹Èçͼ4.6£º ͼ4.6 execdriver¼Ü¹¹Ê¾Òâͼ
4.6 libcontainerlibcontainerÊÇDocker¼Ü¹¹ÖÐÒ»¸öʹÓÃGoÓïÑÔÉè¼ÆʵÏֵĿ⣬Éè¼Æ³õÖÔÊÇÏ£Íû¸Ã¿â¿ÉÒÔ²»ÒÀ¿¿ÈκÎÒÀÀµ£¬Ö±½Ó·ÃÎÊÄÚºËÖÐÓëÈÝÆ÷Ïà¹ØµÄAPI¡£
ÕýÊÇÓÉÓÚlibcontainerµÄ´æÔÚ£¬Docker¿ÉÒÔÖ±½Óµ÷ÓÃlibcontainer£¬¶ø×îÖÕ²Ù×ÝÈÝÆ÷µÄnamespace¡¢cgroups¡¢apparmor¡¢ÍøÂçÉ豸ÒÔ¼°·À»ðǽ¹æÔòµÈ¡£ÕâһϵÁвÙ×÷µÄÍê³É¶¼²»ÐèÒªÒÀÀµLXC»òÕßÆäËû°ü¡£libcontainer¼Ü¹¹Èçͼ4.7£º ͼ4.7 libcontainerʾÒâͼ
ÁíÍ⣬libcontainerÌṩÁËÒ»ÕûÌ×±ê×¼µÄ½Ó¿ÚÀ´Âú×ãÉϲã¶ÔÈÝÆ÷¹ÜÀíµÄÐèÇó¡£»òÕß˵£¬libcontainerÆÁ±ÎÁËDockerÉϲã¶ÔÈÝÆ÷µÄÖ±½Ó¹ÜÀí¡£ÓÖÓÉÓÚlibcontainerʹÓÃGoÕâÖÖ¿çƽ̨µÄÓïÑÔ¿ª·¢ÊµÏÖ£¬ÇÒ±¾ÉíÓÖ¿ÉÒÔ±»Éϲã¶àÖÖ²»Í¬µÄ±à³ÌÓïÑÔ·ÃÎÊ£¬Òò´ËºÜÄÑ˵£¬Î´À´µÄDocker¾ÍÒ»¶¨»á½ô½ôµØºÍLinuxÀ¦°óÔÚÒ»Æ𡣶øÓÚ´Ëͬʱ£¬MicrosoftÔÚÆäÖøÃûÔƼÆËãƽ̨AzureÖУ¬Ò²Ìí¼ÓÁ˶ÔDockerµÄÖ§³Ö£¬¿É¼ûDockerµÄ¿ª·Å³Ì¶ÈÓëÒµ½çµÄ»ðÈȶȡ£
Ôݲ»Ì¸Docker£¬ÓÉÓÚlibcontainerµÄ¹¦ÄÜÒÔ¼°Æä±¾ÉíÓëϵͳµÄËÉñîºÏÌØÐÔ£¬ºÜÓпÉÄÜ»áÔÚÆäËûÒÔÈÝÆ÷ΪÔÐ͵Äƽ̨³öÏÖ£¬Í¬Ê±Ò²ºÜÓпÉÄÜ´ßÉú³öÔƼÆËãÁìÓòȫеÄÏîÄ¿¡£
4.7 Docker containerDocker container£¨DockerÈÝÆ÷£©ÊÇDocker¼Ü¹¹ÖзþÎñ½»¸¶µÄ×îÖÕÌåÏÖÐÎʽ¡£
Docker°´ÕÕÓû§µÄÐèÇóÓëÖ¸Á¶©ÖÆÏàÓ¦µÄDockerÈÝÆ÷£º - Óû§Í¨¹ýÖ¸¶¨ÈÝÆ÷¾µÏñ£¬Ê¹µÃDockerÈÝÆ÷¿ÉÒÔ×Ô¶¨ÒårootfsµÈÎļþϵͳ£»
- Óû§Í¨¹ýÖ¸¶¨¼ÆËã×ÊÔ´µÄÅä¶î£¬Ê¹µÃDockerÈÝÆ÷ʹÓÃÖ¸¶¨µÄ¼ÆËã×ÊÔ´£»
- Óû§Í¨¹ýÅäÖÃÍøÂç¼°Æ䰲ȫ²ßÂÔ£¬Ê¹µÃDockerÈÝÆ÷ÓµÓжÀÁ¢ÇÒ°²È«µÄÍøÂç»·¾³£»
- Óû§Í¨¹ýÖ¸¶¨ÔËÐеÄÃüÁʹµÃDockerÈÝÆ÷Ö´ÐÐÖ¸¶¨µÄ¹¤×÷¡£
DockerÈÝÆ÷ʾÒâͼÈçͼ4.8£º ͼ4.8 DockerÈÝÆ÷ʾÒâͼ
5 DockerÔËÐа¸Àý·ÖÎöÉÏÒ»Õ½Ú×ÅÖØÓÚDocker¼Ü¹¹Öи÷¸ö²¿·ÖµÄ½éÉÜ¡£±¾ÕµÄÄÚÈÝ£¬½«ÒÔ´®ÁªDocker¸÷Ä£¿éÀ´¼òÒª·ÖÎö£¬·ÖÎöÔÐÍΪDockerÖеÄdocker pullÓëdocker runÁ½¸öÃüÁî¡£
5.1 docker pulldocker pullÃüÁîµÄ×÷ÓÃΪ£º´ÓDocker RegistryÖÐÏÂÔØÖ¸¶¨µÄÈÝÆ÷¾µÏñ£¬²¢´æ´¢ÔÚ±¾µØµÄGraphÖУ¬ÒÔ±¸ºóÐø´´½¨DockerÈÝÆ÷ʱµÄʹÓá£docker pullÃüÁîÖ´ÐÐÁ÷³ÌÈçͼ5.1¡£ ͼ5.1 docker pullÃüÁîÖ´ÐÐÁ÷³ÌʾÒâͼ
Èçͼ£¬Í¼Öбê¼ÇµÄºìÉ«¼ýÍ·±íʾdocker pullÃüÁîÔÚ·¢Æðºó£¬DockerËù×öµÄһϵÁÐÔËÐС£ÒÔÏÂÖðÒ»·ÖÎöÕâЩ²½Öè¡£
(1) Docker Client½ÓÊÜdocker pullÃüÁ½âÎöÍêÇëÇóÒÔ¼°ÊÕ¼¯ÍêÇëÇó²ÎÊýÖ®ºó£¬·¢ËÍÒ»¸öHTTPÇëÇó¸øDocker Server£¬HTTPÇëÇó·½·¨ÎªPOST£¬ÇëÇóURLΪ"/images/create? "+"xxx"£»
(2) Docker Server½ÓÊÜÒÔÉÏHTTPÇëÇ󣬲¢½»¸ømux.Router£¬mux.Routerͨ¹ýURLÒÔ¼°ÇëÇó·½·¨À´È·¶¨Ö´ÐиÃÇëÇóµÄ¾ßÌåhandler£»
(3) mux.Router½«ÇëÇó·ÓÉ·Ö·¢ÖÁÏàÓ¦µÄhandler£¬¾ßÌåΪPostImagesCreate£»
(4) ÔÚPostImageCreateÕâ¸öhandlerÖ®ÖУ¬Ò»¸öÃûΪ"pull"µÄjob±»´´½¨£¬²¢¿ªÊ¼Ö´ÐУ»
(5) ÃûΪ"pull"µÄjobÔÚÖ´Ðйý³ÌÖУ¬Ö´ÐÐpullRepository²Ù×÷£¬¼´´ÓDocker RegistryÖÐÏÂÔØÏàÓ¦µÄÒ»¸ö»òÕ߶à¸öimage£»
(6) ÃûΪ"pull"µÄjob½«ÏÂÔصÄimage½»¸øgraphdriver£»
(7) graphdriver¸ºÔð½«image½øÐд洢£¬Ò»·½´´½¨graph¶ÔÏó£¬ÁíÒ»·½ÃæÔÚGraphDBÖмǼimageÖ®¼äµÄ¹Øϵ¡£
5.2 docker rundocker runÃüÁîµÄ×÷ÓÃÊÇÔÚÒ»¸öȫеÄDockerÈÝÆ÷ÄÚ²¿ÔËÐÐÒ»ÌõÖ¸Áî¡£DockerÔÚÖ´ÐÐÕâÌõÃüÁîµÄʱºò£¬Ëù×ö¹¤×÷¿ÉÒÔ·ÖΪÁ½²¿·Ö£ºµÚÒ»£¬´´½¨DockerÈÝÆ÷ËùÐèµÄrootfs£»µÚ¶þ£¬´´½¨ÈÝÆ÷µÄÍøÂçµÈÔËÐл·¾³£¬²¢ÕæÕýÔËÐÐÓû§Ö¸Áî¡£Òò´Ë£¬ÔÚÕû¸öÖ´ÐÐÁ÷³ÌÖУ¬Docker Client¸øDocker Server·¢ËÍÁËÁ½´ÎHTTPÇëÇ󣬵ڶþ´ÎÇëÇóµÄ·¢ÆðÈ¡¾öÓÚµÚÒ»´ÎÇëÇóµÄ·µ»Ø״̬¡£Docker runÃüÁîÖ´ÐÐÁ÷³ÌÈçͼ5.2¡£ ͼ5.2 docker runÃüÁîÖ´ÐÐÁ÷³ÌʾÒâͼ
Èçͼ£¬Í¼Öбê¼ÇµÄºìÉ«¼ýÍ·±íʾdocker runÃüÁîÔÚ·¢Æðºó£¬DockerËù×öµÄһϵÁÐÔËÐС£ÒÔÏÂÖðÒ»·ÖÎöÕâЩ²½Öè¡£
(1) Docker Client½ÓÊÜdocker runÃüÁ½âÎöÍêÇëÇóÒÔ¼°ÊÕ¼¯ÍêÇëÇó²ÎÊýÖ®ºó£¬·¢ËÍÒ»¸öHTTPÇëÇó¸øDocker Server£¬HTTPÇëÇó·½·¨ÎªPOST£¬ÇëÇóURLΪ"/containers/create? "+"xxx"£»
(2) Docker Server½ÓÊÜÒÔÉÏHTTPÇëÇ󣬲¢½»¸ømux.Router£¬mux.Routerͨ¹ýURLÒÔ¼°ÇëÇó·½·¨À´È·¶¨Ö´ÐиÃÇëÇóµÄ¾ßÌåhandler£»
(3) mux.Router½«ÇëÇó·ÓÉ·Ö·¢ÖÁÏàÓ¦µÄhandler£¬¾ßÌåΪPostContainersCreate£»
(4) ÔÚPostImageCreateÕâ¸öhandlerÖ®ÖУ¬Ò»¸öÃûΪ"create"µÄjob±»´´½¨£¬²¢¿ªÊ¼ÈøÃjobÔËÐУ»
(5) ÃûΪ"create"µÄjobÔÚÔËÐйý³ÌÖУ¬Ö´ÐÐContainer.Create²Ù×÷£¬¸Ã²Ù×÷ÐèÒª»ñÈ¡ÈÝÆ÷¾µÏñÀ´ÎªDockerÈÝÆ÷´´½¨rootfs£¬¼´µ÷ÓÃgraphdriver£»
(6) graphdriver´ÓGraphÖлñÈ¡´´½¨DockerÈÝÆ÷rootfsËùÐèÒªµÄËùÓеľµÏñ£»
(7) graphdriver½«rootfsËùÓоµÏñ£¬¼ÓÔØ°²×°ÖÁDockerÈÝÆ÷Ö¸¶¨µÄÎļþĿ¼Ï£»
(8) ÈôÒÔÉϲÙ×÷È«²¿Õý³£Ö´ÐУ¬Ã»Óзµ»Ø´íÎó»òÒì³££¬ÔòDocker ClientÊÕµ½Docker Server·µ»Ø״̬֮ºó£¬·¢ÆðµÚ¶þ´ÎHTTPÇëÇó¡£ÇëÇó·½·¨Îª"POST"£¬ÇëÇóURLΪ"/containers/"+container_ID+"/start"£»
(9) Docker Server½ÓÊÜÒÔÉÏHTTPÇëÇ󣬲¢½»¸ømux.Router£¬mux.Routerͨ¹ýURLÒÔ¼°ÇëÇó·½·¨À´È·¶¨Ö´ÐиÃÇëÇóµÄ¾ßÌåhandler£»
(10)mux.Router½«ÇëÇó·ÓÉ·Ö·¢ÖÁÏàÓ¦µÄhandler£¬¾ßÌåΪPostContainersStart£»
(11)ÔÚPostContainersStartÕâ¸öhandlerÖ®ÖУ¬ÃûΪ"start"µÄjob±»´´½¨£¬²¢¿ªÊ¼Ö´ÐУ»
(12)ÃûΪ"start"µÄjobÖ´ÐÐÍê³õ²½µÄÅäÖù¤×÷ºó£¬¿ªÊ¼ÅäÖÃÓë´´½¨ÍøÂç»·¾³£¬µ÷ÓÃnetworkdriver£»
(13)networkdriverÐèҪΪָ¶¨µÄDockerÈÝÆ÷´´½¨ÍøÂç½Ó¿ÚÉ豸£¬²¢ÎªÆä·ÖÅäIP£¬port£¬ÒÔ¼°ÉèÖ÷À»ðǽ¹æÔò£¬ÏàÓ¦µÄ²Ù×÷ת½»ÖÁlibcontainerÖеÄnetlink°üÀ´Íê³É£»
(14)netlinkÍê³ÉDockerÈÝÆ÷µÄÍøÂç»·¾³ÅäÖÃÓë´´½¨£»
(15)·µ»ØÖÁÃûΪ"start"µÄjob£¬Ö´ÐÐÍêһЩ¸¨ÖúÐÔ²Ù×÷ºó£¬job¿ªÊ¼Ö´ÐÐÓû§Ö¸Áµ÷ÓÃexecdriver£»
(16)execdriver±»µ÷Ó㬳õʼ»¯DockerÈÝÆ÷ÄÚ²¿µÄÔËÐл·¾³£¬ÈçÃüÃû¿Õ¼ä£¬×ÊÔ´¿ØÖÆÓë¸ôÀ룬ÒÔ¼°Óû§ÃüÁîµÄÖ´ÐУ¬ÏàÓ¦µÄ²Ù×÷ת½»ÖÁlibcontainerÀ´Íê³É£»
(17)libcontainer±»µ÷Óã¬Íê³ÉDockerÈÝÆ÷ÄÚ²¿µÄÔËÐл·¾³³õʼ»¯£¬²¢×îÖÕÖ´ÐÐÓû§ÒªÇóÆô¶¯µÄÃüÁî¡£
6 ×ܽ᱾ÎÄ´ÓDocker 1.2µÄÔ´ÂëÈëÊÖ£¬·ÖÎö³éÏó³öDockerµÄ¼Ü¹¹Í¼£¬²¢¶Ô¸Ã¼Ü¹¹Í¼Öеĸ÷¸öÄ£¿é½øÐй¦ÄÜÓëʵÏֵķÖÎö£¬×îºóͨ¹ýÁ½¸ödockerÃüÁîչʾÁËDockerÄÚ²¿µÄÔËÐС£ ͨ¹ý¶ÔDocker¼Ü¹¹µÄѧϰ£¬¿ÉÒÔÈ«ÃæÉ¶ÔDockerÉè¼Æ¡¢¹¦ÄÜÓë¼ÛÖµµÄÀí½â¡£Í¬Ê±ÔÚ½èÖúDockerʵÏÖÓû§¶¨ÖƵķֲ¼Ê½ÏµÍ³Ê±£¬Ò²ÄܸüºÃµØÕÒµ½ÒÑÓÐƽ̨ÓëDocker½ÏΪÀíÏëµÄÆõºÏµã¡£ÁíÍ⣬ÊìϤDockerÏÖÓмܹ¹ÒÔ¼°Éè¼Æ˼Ï룬ҲÄܶÔÔƼÆËãPaaSÁìÓò´øÀ´¸ü¶àµÄÆô·¢£¬´ßÉú³ö¸ü¶àʵ¼ùÓ봴С£
7 ×÷Õß¼ò½éËïºêÁÁ£¬Õã½´óѧVLISʵÑéÊÒ˶ʿÑо¿Éú¡£Á½ÄêÀ´ÔÚÔƼÆËã·½ÃæÖ÷ÒªÑо¿PaaSÁìÓòµÄÏà¹Ø֪ʶÓë¼¼Êõ¡£¼áÐÅÇáÁ¿¼¶ÐéÄ⻯ÈÝÆ÷µÄ¼¼Êõ£¬»á¸øPaaSÁìÓò´øÀ´Éî¶ÈÓ°Ï죬ÉõÖÁ¾ö¶¨Î´À´PaaS¼¼ÊõµÄ×ßÏò¡£ÓÊÏ䣺 shlallen@zju.edu.cn
#########################################################
|