×ðÁú¿­Ê±¹ÙÍøµÇ¼

LinuxºÍDocker£ºÔõÑùʵÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½£¿

linuxºÍdocker£ºÔõÑùʵÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½£¿

ÕªÒª£ºDockerÊÇÒ»ÖÖÊ¢ÐеÄÈÝÆ÷»¯ÊÖÒÕ £¬ËüÌṩÁËÒ»ÖÖÇáÁ¿¼¶µÄÐéÄ⻯½â¾ö¼Æ»®¡£ÔÚ¶àÖ÷»úÇéÐÎÖÐ £¬ÊµÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½ÊǷǾ­³£¼ûµÄÐèÇó¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃLinuxºÍDockerÀ´ÊµÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½ £¬²¢ÌṩһЩʾÀý´úÂ빩²Î¿¼¡£

СÐò

ÈÝÆ÷»¯ÊÖÒÕµÄÐËÆðʹµÃÓ¦Óð²ÅźÍǨáã±äµÃÔ½·¢ÎÞаºÍ¸ßЧ¡£ÔÚ¶àÖ÷»úÇéÐÎÖÐ £¬ÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½ÊDZز»¿ÉÉٵĹ¦Ð§ £¬¿ÉÒÔ×ÊÖúÎÒÃÇʵÏÖ¸ºÔØƽºâ¡¢¸ß¿ÉÓÃÐÔÒÔ¼°×ÊÔ´µÄ×îÓÅʹÓá£LinuxÌṩÁËһЩ¹¤¾ßºÍ¹¦Ð§À´Ö§³ÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½ £¬¶øDockerÔò»ùÓÚLinuxÌṩÁËÔ½·¢±ã½ÝµÄ·½·¨À´ÖÎÀíºÍ²Ù×÷ÈÝÆ÷¡£

LinuxµÄÈÝÆ÷ǨáãºÍͬ²½

ÔÚLinuxÖÐ £¬ÈÝÆ÷µÄǨáãºÍͬ²½Ö÷ÒªÒÀÀµÓÚÁ½ÏîÊÖÒÕ£ºÇ¨áã´æ´¢ºÍÍøÂ硣Ǩáã´æ´¢ÊÇÖ¸½«ÈÝÆ÷µÄÊý¾ÝºÍÎļþϵͳ´ÓÔ´Ö÷»úǨá㵽ĿµÄÖ÷»úµÄÀú³Ì £¬¶øÍøÂçÔòÊÇÔÚÈÝÆ÷ǨáãÀú³ÌÖмá³ÖÍøÂçÅþÁ¬µÄÒªº¦¡£

2.1 Ǩáã´æ´¢

¹ØÓÚÈÝÆ÷µÄǨáã´æ´¢ £¬Óм¸ÖÖ³£ÓõÄÊÖÒտɹ©Ñ¡Ôñ £¬Èç¹Å°åµÄ¸´ÖƺÍͬ²½Îļþϵͳ¡¢ÂþÑÜʽÎļþϵͳÒÔ¼°ÂþÑÜʽ¿é´æ´¢¡£¸´ÖƺÍͬ²½ÎļþϵͳÊÇ×î³£¼ûµÄ·½·¨ £¬ËüÃÇÊÊÓÃÓÚС¹æÄ£ÇéÐÎ £¬µ«ÔÚ´ó¹æÄ£ÇéÐÎÖпÉÄ᷺ܻÆðÐÔÄÜÆ¿¾±¡£ÂþÑÜʽÎļþϵͳºÍÂþÑÜʽ¿é´æ´¢Ôò¿ÉÒÔÌṩ¸ü¸ßµÄÐÔÄܺͿÉÀ©Õ¹ÐÔ £¬µ«ÉèÖúÍÖÎÀíÏà¶ÔÖØ´ó¡£ÔÚÕâÀï £¬ÎÒÃǽ«ÒÔ¸´ÖƺÍͬ²½ÎļþϵͳΪÀý¾ÙÐÐ˵Ã÷¡£

¼ÙÉèÎÒÃÇÓÐÁ½Ì¨Ö÷»ú £¬Ô´Ö÷»úºÍÄ¿µÄÖ÷»ú £¬Òª½«ÈÝÆ÷´ÓÔ´Ö÷»úǨá㵽ĿµÄÖ÷»ú £¬ÎÒÃÇ¿ÉÒÔÖ´ÐÐÒÔÏ°취£º

°ì·¨1£º×èÖ¹ÈÝÆ÷ÔÚÔ´Ö÷»úÉϵÄÔËÐС£

$ docker stop container_id

µÇ¼ºó¸´ÖÆ

°ì·¨2£ºµ¼³öÈÝÆ÷µÄÎļþϵͳ¡£

$ docker export container_id > container.tar

µÇ¼ºó¸´ÖÆ

°ì·¨3£º½«ÈÝÆ÷µÄÎļþϵͳ´«Ê䵽ĿµÄÖ÷»ú¡£

$ scp container.tar user@target_host:/path/

µÇ¼ºó¸´ÖÆ

°ì·¨4£ºÔÚÄ¿µÄÖ÷»úÉϵ¼ÈëÈÝÆ÷µÄÎļþϵͳ¡£

$ docker import /path/container.tar

µÇ¼ºó¸´ÖÆ

°ì·¨5£ºÆô¶¯ÈÝÆ÷ÔÚÄ¿µÄÖ÷»úÉÏÔËÐС£

$ docker run -d --name container_name image_name

µÇ¼ºó¸´ÖÆ

2.2 ÍøÂçͬ²½

ÔÚÈÝÆ÷ǨáãÀú³ÌÖÐ £¬¼á³ÖÍøÂçÅþÁ¬µÄÎȹÌÐÔÊǺÜÊÇÖ÷ÒªµÄ¡£LinuxÌṩÁËһЩ¹¤¾ßºÍÊÖÒÕÀ´ÊµÏÖÍøÂçµÄͬ²½ £¬Èçiptables¹æÔò¡¢ÍøÂçÃüÃû¿Õ¼äºÍmacvlan¡£ÏêϸµÄʵÏÖ·½·¨È¡¾öÓÚÍøÂç¼Ü¹¹ºÍÐèÇó¡£

¼ÙÉèÎÒÃÇÓÐÁ½Ì¨Ö÷»ú £¬Ô´Ö÷»úºÍÄ¿µÄÖ÷»ú £¬Òª¼á³ÖÈÝÆ÷ÔÚǨáãÀú³ÌÖеÄÍøÂçÅþÁ¬ £¬ÎÒÃÇ¿ÉÒÔÖ´ÐÐÒÔÏ°취£º

°ì·¨1£ºÔÚÔ´Ö÷»úÉϽ¨ÉèÍøÂçÃüÃû¿Õ¼ä £¬²¢½«ÈÝÆ÷µÄÍøÂç½Ó¿ÚÒƶ¯µ½¸ÃÃüÃû¿Õ¼ä¡£

$ ip link set dev eth0 netns container_ns

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

°ì·¨2£ºÔÚÄ¿µÄÖ÷»úÉϽ¨ÉèÍøÂçÃüÃû¿Õ¼ä £¬²¢½«ÈÝÆ÷µÄÍøÂç½Ó¿ÚÒƶ¯µ½¸ÃÃüÃû¿Õ¼ä¡£

$ ip link set dev eth0 netns container_ns

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

°ì·¨3£ºÔÚÔ´Ö÷»úÉÏÉèÖÃiptables¹æÔò £¬½«ÈÝÆ÷µÄÍøÂçÁ÷Á¿Öض¨Ïòµ½Ä¿µÄÖ÷»ú¡£

$ iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-destination target_ip

µÇ¼ºó¸´ÖÆ

°ì·¨4£ºÔÚÄ¿µÄÖ÷»úÉÏÆô¶¯ÈÝÆ÷µÄÍøÂç½Ó¿Ú¡£

$ ip link set dev eth0 up

µÇ¼ºó¸´ÖÆ

°ì·¨5£ºÔÚÄ¿µÄÖ÷»úÉÏÉèÖÃiptables¹æÔò £¬½«ÈÝÆ÷µÄÍøÂçÁ÷Á¿×ª·¢µ½ÈÝÆ÷µÄÍøÂçÃüÃû¿Õ¼ä¡£

$ iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-destination container_ip

µÇ¼ºó¸´ÖÆ

DockerµÄÈÝÆ÷ǨáãºÍͬ²½

ÔÚDockerÖÐ £¬ÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½Ö÷ÒªÒÀÀµÓÚDocker Swarm¡£Docker SwarmÊÇÒ»¸öÔ­ÉúµÄDocker¼¯ÈººÍ±àÅŹ¤¾ß £¬Ëü¿ÉÒÔÖÎÀíºÍµ÷Àí¿ç¶à¸öÖ÷»úµÄÈÝÆ÷¡£

¼ÙÉèÎÒÃÇÒѾ­ÉèÖúÃÁËDocker Swarm £¬ÔÚ¶àÖ÷»úÇéÐÎÖÐʵÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½¿ÉÒÔÖ´ÐÐÒÔÏ°취£º

°ì·¨1£º½«ÈÝÆ÷¼ÓÈëµ½Docker Swarm¼¯Èº¡£

$ docker swarm join --token SWMTKN-abcdefg1234567890 manager_ip:2377

µÇ¼ºó¸´ÖÆ

°ì·¨2£ºÔÚÔ´Ö÷»úÉϱê¼ÇÈÝÆ÷ £¬ÒÔָʾËüÐèÒª¿çÖ÷»úǨáã¡£

$ docker service update --label-add com.docker.ucp.mesh.http.ports=80 container_name

µÇ¼ºó¸´ÖÆ

°ì·¨3£ºÔÚÄ¿µÄÖ÷»úÉÏÆô¶¯Í¬ÃûµÄЧÀÍ¡£

$ docker service create --name container_name image_name

µÇ¼ºó¸´ÖÆ

°ì·¨4£ºDocker Swarm»á×Ô¶¯½«Ô´Ö÷»úÉϵÄÈÝÆ÷Ǩá㵽ĿµÄÖ÷»úÉÏ¡£

½áÂÛ

ͨ¹ýLinuxºÍDocker £¬ÎÒÃÇ¿ÉÒÔºÜÊÇÀû±ãµØʵÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½¡£ÎÞÂÛÊÇÔÚLinuxÇéÐÎÏÂÖ±½ÓʹÓø´ÖƺÍͬ²½Îļþϵͳ £¬ÕÕ¾ÉʹÓÃDocker SwarmÀ´ÖÎÀíºÍµ÷Àí¿çÖ÷»úµÄÈÝÆ÷ £¬¶¼¿ÉÒÔÖª×ãÎÒÃÇÔÚ¶àÖ÷»úÇéÐÎÖеÄÐèÇó¡£Ï£Íû±¾ÎĶԶÁÕßÔÚʵÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½·½ÃæÌṩÁËһЩ×ÊÖú¡£

²Î¿¼ÎÄÏ×£º

Docker documentation: https://docs.docker.com/

Linux documentation: https://www.kernel.org/doc/html/latest/

¸½Â¼£º´úÂëʾÀý

# ʾÀý´úÂë1£º¸´ÖƺÍͬ²½Îļþϵͳ
# °ì·¨1£º×èÖ¹ÈÝÆ÷ÔÚÔ´Ö÷»úÉϵÄÔËÐС£
$ docker stop container_id

# °ì·¨2£ºµ¼³öÈÝÆ÷µÄÎļþϵͳ¡£
$ docker export container_id > container.tar

# °ì·¨3£º½«ÈÝÆ÷µÄÎļþϵͳ´«Ê䵽ĿµÄÖ÷»ú¡£
$ scp container.tar user@target_host:/path/

# °ì·¨4£ºÔÚÄ¿µÄÖ÷»úÉϵ¼ÈëÈÝÆ÷µÄÎļþϵͳ¡£
$ docker import /path/container.tar

# °ì·¨5£ºÆô¶¯ÈÝÆ÷ÔÚÄ¿µÄÖ÷»úÉÏÔËÐС£
$ docker run -d --name container_name image_name

# ʾÀý´úÂë2£ºÍøÂçͬ²½
# °ì·¨1£ºÔÚÔ´Ö÷»úÉϽ¨ÉèÍøÂçÃüÃû¿Õ¼ä£¬²¢½«ÈÝÆ÷µÄÍøÂç½Ó¿ÚÒƶ¯µ½¸ÃÃüÃû¿Õ¼ä¡£
$ ip link set dev eth0 netns container_ns

# °ì·¨2£ºÔÚÄ¿µÄÖ÷»úÉϽ¨ÉèÍøÂçÃüÃû¿Õ¼ä£¬²¢½«ÈÝÆ÷µÄÍøÂç½Ó¿ÚÒƶ¯µ½¸ÃÃüÃû¿Õ¼ä¡£
$ ip link set dev eth0 netns container_ns

# °ì·¨3£ºÔÚÔ´Ö÷»úÉÏÉèÖÃiptables¹æÔò£¬½«ÈÝÆ÷µÄÍøÂçÁ÷Á¿Öض¨Ïòµ½Ä¿µÄÖ÷»ú¡£
$ iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-destination target_ip

# °ì·¨4£ºÔÚÄ¿µÄÖ÷»úÉÏÆô¶¯ÈÝÆ÷µÄÍøÂç½Ó¿Ú¡£
$ ip link set dev eth0 up

# °ì·¨5£ºÔÚÄ¿µÄÖ÷»úÉÏÉèÖÃiptables¹æÔò£¬½«ÈÝÆ÷µÄÍøÂçÁ÷Á¿×ª·¢µ½ÈÝÆ÷µÄÍøÂçÃüÃû¿Õ¼ä¡£
$ iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-destination container_ip

# ʾÀý´úÂë3£ºDocker SwarmµÄÈÝÆ÷ǨáãºÍͬ²½
# °ì·¨1£º½«ÈÝÆ÷¼ÓÈëµ½Docker Swarm¼¯Èº¡£
$ docker swarm join --token SWMTKN-abcdefg1234567890 manager_ip:2377

# °ì·¨2£ºÔÚÔ´Ö÷»úÉϱê¼ÇÈÝÆ÷£¬ÒÔָʾËüÐèÒª¿çÖ÷»úǨáã¡£
$ docker service update --label-add com.docker.ucp.mesh.http.ports=80 container_name

# °ì·¨3£ºÔÚÄ¿µÄÖ÷»úÉÏÆô¶¯Í¬ÃûµÄЧÀÍ¡£
$ docker service create --name container_name image_name

# °ì·¨4£ºDocker Swarm»á×Ô¶¯½«Ô´Ö÷»úÉϵÄÈÝÆ÷Ǩá㵽ĿµÄÖ÷»úÉÏ¡£

µÇ¼ºó¸´ÖÆ

£¨×Ü×ÖÊý£ºÔ­ÎÄÔ¼1306×Ö £¬Ê¾Àý´úÂë607×Ö£©

ÒÔÉϾÍÊÇLinuxºÍDocker£ºÔõÑùʵÏÖÈÝÆ÷µÄ¿çÖ÷»úǨáãºÍͬ²½£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ