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

ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂç

ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂç

СÐò£º

Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄÉú³¤£¬Ô½À´Ô½¶àµÄÆóÒµ×îÏȽ«Ó¦ÓóÌÐòÔËÐÐÔÚÈÝÆ÷ÖУ¬ÊµÏÖÁËÓ¦ÓóÌÐòµÄÇáÓ¯¡¢¿ìËÙ°²ÅÅ¡£¶øÈÝÆ÷ÍøÂç×÷ΪÈÝÆ÷¼¯ÈºµÄÖ÷Òª×é³É²¿·Ö£¬¹ØÓÚÈÝÆ÷¼¯ÈºµÄ¸ß¿ÉÓÃÐÔºÍÐÔÄÜÓÐ×ÅÖÁ¹ØÖ÷ÒªµÄ×÷Óᣱ¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂ磬²¢Ìṩ´úÂëʾÀý¹©¶ÁÕ߲ο¼¡£

°ì·¨Ò»£º´î½¨ÈÝÆ÷ÍøÂç

×°ÖÃDocker»òKubernetesµÈÈÝÆ÷ÖÎÀí¹¤¾ß

¹ØÓÚÈÝÆ÷ÍøÂçµÄÉèÖã¬ÎÒÃÇ¿ÉÒÔÑ¡ÔñʹÓÃDocker»òKubernetesµÈÈÝÆ÷ÖÎÀí¹¤¾ß¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÒÔDockerΪÀý¾ÙÐÐ˵Ã÷¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚLinuxÉÏ×°ÖÃDocker£¬¿Éƾ֤¹Ù·½Îĵµ¾ÙÐвÙ×÷¡£

½¨ÉèÈÝÆ÷ÍøÂç

ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁ½¨ÉèÒ»¸ö×Ô½ç˵µÄÈÝÆ÷ÍøÂ磺

$ docker network create --driver bridge my-network

µÇ¼ºó¸´ÖÆ

Õ⽫½¨ÉèÒ»¸öÃûΪmy-networkµÄÈÝÆ÷ÍøÂ磬ÓÃÓÚÅþÁ¬ÈÝÆ÷Ⱥ¼¯Öеĸ÷¸öÈÝÆ÷¡£

°ì·¨¶þ£ºÉèÖÃÈÝÆ÷ÍøÂçµÄ¸ß¿ÉÓÃÐÔ

ÈÝÆ÷ÍøÂ縴ÖÆ

ÔÚÈÝÆ÷ÍøÂçÖУ¬Í¨³£»áÓжà¸öÈÝÆ÷¾ÙÐÐЧÀÍ°²ÅÅ¡£ÎªÁËʵÏÖÈÝÆ÷ÍøÂçµÄ¸ß¿ÉÓÃÐÔ£¬ÎÒÃÇ¿ÉÒÔ½«ÈÝÆ÷ÍøÂç¾ÙÐи´ÖÆ£¬ÒÔÌá¸ßЧÀ͵Ŀɿ¿ÐÔºÍÐÔÄÜ¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄPython´úÂëʾÀý£¬ÓÃÓÚÔÚ½¨ÉèÈÝÆ÷ʱ¾ÙÐÐÈÝÆ÷ÍøÂçµÄ¸´ÖÆ£º

import docker

# ½¨Éèdocker¿Í»§¶Ë
client = docker.from_env()

# ÈÝÆ÷ÍøÂçµÄÃû³Æ
network_name = "my-network"

# ½¨ÉèÈÝÆ÷ʱÉèÖÃÈÝÆ÷ÍøÂ縴ÖÆ
container = client.containers.run(
    image="webapp",
    name="webapp1",
    detach=True,
    network=network_name,
    labels={
        "com.docker.network.bridge.enable_icc": "true",
        "com.docker.network.bridge.name": network_name,
        "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
        "com.docker.network.bridge.enable_ip_masquerade": "true"
    }
)

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃÇͨ¹ýʹÓÃDockerµÄPython SDK½¨ÉèÁËÒ»¸öÃûΪwebapp1µÄÈÝÆ÷£¬²¢½«ÆäÅþÁ¬µ½ÃûΪmy-networkµÄÈÝÆ÷ÍøÂçÉÏ¡£Í¨¹ýÉèÖÃlabels£¬ÎÒÃÇʵÏÖÁËÈÝÆ÷ÍøÂçµÄ¸´ÖÆ£¬ÒÔÌṩ¸ß¿ÉÓõÄЧÀÍ¡£

ÈÝÆ÷ÍøÂçµÄ¸ºÔØƽºâ

³ýÁËÈÝÆ÷ÍøÂçµÄ¸´ÖÆÍ⣬ÎÒÃÇ»¹¿ÉÒÔͨ¹ý¸ºÔØƽºâ»úÖÆʵÏָ߿ÉÓõÄÈÝÆ÷ÍøÂç¡£ÔÚDockerÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃDocker SwarmµÈ¹¤¾ßÀ´ÊµÏÖÈÝÆ÷ÍøÂçµÄ¸ºÔØƽºâ¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄDocker SwarmЧÀͱàÅÅÎļþʾÀý£º

version: '3'

services:
  web:
    image: my-webapp
    deploy:
      replicas: 3
      labels:
        - "com.docker.lb.hosts=webapp.mydomain.com"
        - "com.docker.lb.port=80"
    networks:
      - my-network

networks:
  my-network:
    external:
      name: my-network

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪwebµÄЧÀÍ£¬Í¨¹ýÉèÖÃreplicas²ÎÊý£¬ÎÒÃÇ¿ÉÒÔ½«webЧÀ͸´ÖƳɶà¸öʵÀý¡£Í¨¹ýÉèÖÃlabels£¬ÎÒÃǽ«webЧÀÍÓëÓòÃûwebapp.mydomain.comºÍ¶Ë¿Ú80¹ØÁªÆðÀ´£¬ÊµÏÖ¸ºÔØƽºâ¡£

½áÂÛ£º

ͨ¹ýÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂ磬ÎÒÃÇ¿ÉÒÔÌá¸ßÈÝÆ÷¼¯ÈºµÄ¿É¿¿ÐÔºÍÐÔÄÜ¡£±¾ÎÄÏÈÈÝÁ˴ÈÝÆ÷ÍøÂçµÄ°ì·¨£¬²¢ÌṩÁË´úÂëʾÀý¹©¶ÁÕ߲ο¼¡£ÔÚÏÖʵӦÓÃÖУ¬¶ÁÕß»¹¿ÉÒÔƾ֤ÐèÒª¾ÙÐнøÒ»²½µÄÉèÖúÍÓÅ»¯£¬ÒÔÖª×ã×Ô¼ºµÄÓªÒµÐèÇó¡£Ï£Íû±¾ÎĶԶÁÕßÓÐËù×ÊÖú£¡

ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷ÍøÂçµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ