LinuxϵÄDockerÈÝÆ÷ÍøÂ磺ÔõÑùÉèÖÃÈÝÆ÷¼äµÄÍøÂçÅþÁ¬ºÍͨѶ£¿
linuxϵÄdockerÈÝÆ÷ÍøÂ磺ÔõÑùÉèÖÃÈÝÆ÷¼äµÄÍøÂçÅþÁ¬ºÍͨѶ£¿
ÔÚʹÓÃDocker¾ÙÐÐÓ¦Óð²ÅÅʱ£¬ÈÝÆ÷Ö®¼äµÄÍøÂçÅþÁ¬ºÍͨѶÊÇÒ»¸öºÜÊÇÖ÷ÒªµÄÎÊÌâ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxÇéÐÎÏÂÉèÖÃÈÝÆ÷µÄÍøÂçÅþÁ¬£¬²¢ÌṩһЩ³£ÓõĴúÂëʾÀý¡£
DockerÖÐÓжàÖÖÍøÂçģʽ¿É¹©Ñ¡Ôñ£¬ÆäÖÐ×î³£ÓõÄÈýÖÖÊÇ£ºÇŽÓģʽ¡¢Ö÷»úģʽºÍOverlayÍøÂçģʽ¡£ÔÚÇŽÓģʽÏ£¬Docker½«ÎªÃ¿¸öÈÝÆ÷½¨ÉèÒ»¸öÐéÄâÍøÂç½Ó¿Ú£¬²¢Í¨¹ýÒ»¸ö¹²ÏíµÄÍøÂçÇŽÓÆ÷ÅþÁ¬ÕâЩÈÝÆ÷¡£ÔÚÖ÷»úģʽÏ£¬ÈÝÆ÷½«Ö±½ÓʹÓÃËÞÖ÷»úµÄÍøÂç½Ó¿Ú¡£OverlayÍøÂçģʽÔòÊÇΪ¿çÖ÷»úµÄÈÝÆ÷ͨѶÌṩÁËÒ»ÖÖ½â¾ö¼Æ»®¡£
Ê×ÏÈ£¬ÎÒÃÇÀ´ÏÈÈÝÔõÑùʹÓÃÇŽÓģʽÉèÖÃÈÝÆ÷µÄÍøÂçÅþÁ¬¡£ÎÒÃÇ¿ÉÒÔʹÓÃDockerµÄÏÂÁîÐй¤¾ß»òDocker ComposeÀ´ÊµÏÖ¡£
ʹÓÃÏÂÁîÐй¤¾ß£º
docker run -d --name container1 --network bridge image1 docker run -d --name container2 --network bridge image2
µÇ¼ºó¸´ÖÆ
ʹÓÃDocker Compose£º
version: '3' services: container1: image: image1 networks: - bridge container2: image: image2 networks: - bridge networks: bridge: driver: bridge
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǽ¨ÉèÁËÁ½¸öÈÝÆ÷container1ºÍcontainer2£¬²¢½«ËüÃÇÅþÁ¬µ½Ò»¸öÃûΪbridgeµÄÍøÂçÖС£Í¨¹ýÕâÑùµÄÉèÖã¬ÈÝÆ÷Ö®¼ä¿ÉÒÔʹÓÃÈÝÆ÷Ãû³Æ¾ÙÐÐÏ໥ͨѶ¡£
ÏÂÃæÊÇʹÓÃÖ÷»úģʽÉèÖÃÈÝÆ÷µÄÍøÂçÅþÁ¬µÄʾÀý£º
ʹÓÃÏÂÁîÐй¤¾ß£º
docker run -d --name container1 --network host image1 docker run -d --name container2 --network host image2
µÇ¼ºó¸´ÖÆ
ʹÓÃDocker Compose£º
version: '3' services: container1: image: image1 networks: - host container2: image: image2 networks: - host networks: host: driver: host
µÇ¼ºó¸´ÖÆ
ÔÚÕâÖÖÉèÖÃÏ£¬ÈÝÆ÷½«Ö±½ÓʹÓÃËÞÖ÷»úµÄÍøÂç½Ó¿Ú£¬Òò´ËËüÃÇ¿ÉÒÔͨ¹ýËÞÖ÷»úµÄIPµØµã¾ÙÐÐͨѶ¡£
×îºó£¬ÎÒÃÇÏÈÈÝÒ»ÏÂʹÓÃOverlayÍøÂçģʽ¾ÙÐÐÈÝÆ÷¼äͨѶµÄÉèÖá£ÕâÖÖģʽÐèҪʹÓÃDocker Swarm¾ÙÐа²ÅÅ¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒª³õʼ»¯Ò»¸öSwarm£º
docker swarm init
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÎÒÃǽ¨ÉèÒ»¸öOverlayÍøÂ磺
docker network create -d overlay my-network
µÇ¼ºó¸´ÖÆ
½ÓÏÂÀ´£¬ÎÒÃǽ¨ÉèЧÀͲ¢½«ÆäÅþÁ¬µ½¸ÃÍøÂ磺
docker service create --name service1 --network my-network image1 docker service create --name service2 --network my-network image2
µÇ¼ºó¸´ÖÆ
ʹÓÃOverlayÍøÂçģʽ¿ÉÒÔʵÏÖ¿çÖ÷»úµÄÈÝÆ÷ͨѶ£¬²¢°ü¹ÜͨѶµÄÇå¾²ÐԺͿɿ¿ÐÔ¡£
×ÛÉÏËùÊö£¬±¾ÎÄÏÈÈÝÁËÔÚLinuxÇéÐÎÏÂÉèÖÃDockerÈÝÆ÷µÄÍøÂçÅþÁ¬ºÍͨѶµÄÒªÁ죬°üÀ¨ÇŽÓģʽ¡¢Ö÷»úģʽºÍOverlayÍøÂçģʽ¡£ÕâЩҪÁì¿ÉÒÔƾ֤ÏêϸµÄÐèÇóÑ¡ÔñʹÓã¬×ÊÖúÎÒÃÇÔÚʹÓÃDockerʱ¸üºÃµØÖÎÀíÈÝÆ÷µÄÍøÂç¡£
´úÂëʾÀý½ö¹©²Î¿¼£¬ÏÖʵʹÓÃʱÇëƾ֤ÏêϸÇéÐξÙÐÐÏìÓ¦µÄµ÷½âºÍÉèÖá£Í¨¹ýÎÞаµÄÍøÂçÉèÖã¬ÎÒÃÇ¿ÉÒÔÇáËɹ¹½¨³ö¸ßЧ¿É¿¿µÄÈÝÆ÷»¯Ó¦ÓÃϵͳ¡£
ÒÔÉϾÍÊÇLinuxϵÄDockerÈÝÆ÷ÍøÂ磺ÔõÑùÉèÖÃÈÝÆ÷¼äµÄÍøÂçÅþÁ¬ºÍͨѶ£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡