ÔõÑùÔÚLinuxЧÀÍÆ÷ÉϽ¨Éè¸ßЧµÄDocker¾µÏñ¿ÍÕ»£¿
ÔõÑùÔÚlinuxЧÀÍÆ÷ÉϽ¨Éè¸ßЧµÄdocker¾µÏñ¿ÍÕ»£¿
Ëæ×ÅÈÝÆ÷»¯ÊÖÒÕµÄÉú³¤ºÍÆÕ¼°£¬DockerÒѳÉΪ×îÊ¢ÐеÄÈÝÆ÷»¯½â¾ö¼Æ»®Ö®Ò»¡£ÔÚʹÓÃDocker¹¹½¨ºÍÖÎÀí´ó¹æÄ£µÄÓ¦ÓóÌÐòʱ£¬¸ßЧµÄDocker¾µÏñ¿ÍÕ»ÊǺÜÊÇÖ÷ÒªµÄ¡£Ëü²»µ«¿ÉÒÔ¼ÓËÙ°²ÅźÍÀ©Õ¹Àú³Ì£¬»¹¿ÉÒÔÌá¸ß¿ª·¢ÕßµÄÊÂÇéЧÂÊ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÔÚLinuxЧÀÍÆ÷ÉϽ¨Éè¸ßЧµÄDocker¾µÏñ¿ÍÕ»£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£
×°ÖÃDockerºÍDocker Registry
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚLinuxЧÀÍÆ÷ÉÏ×°ÖÃDockerºÍDocker Registry¡£Docker¿ÉÒÔͨ¹ý¹Ù·½µÄ×°Öþ籾¾ÙÐÐ×°Öã¬ÏêϸÀú³ÌÇë²Î¿¼DockerµÄ¹Ù·½Îĵµ¡£×°ÖÃÍêDockerºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî×°ÖÃDocker Registry£º
$ docker run -d -p 5000:5000 --restart=always --name registry registry:2
µÇ¼ºó¸´ÖÆ
´ËÏÂÁÔÚЧÀÍÆ÷ÉÏÆô¶¯Ò»¸öDocker RegistryÈÝÆ÷£¬²¢½«ÈÝÆ÷ÖеÄ5000¶Ë¿ÚÓ³É䵽ЧÀÍÆ÷µÄ5000¶Ë¿Ú¡£
ÉèÖÃDocker Registry
×°ÖÃÍêDocker Registryºó£¬ÎÒÃÇÐèÒª¾ÙÐÐһЩÉèÖòŻªÊ¹Æä¸ü¸ßЧ¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒªÐÞ¸ÄDockerµÄÉèÖÃÎļþ£¬ÒÔ±ãÔÊÐí²»Çå¾²µÄ¾µÏñ´«Êä¡£±à¼/etc/docker/daemon.jsonÎļþ£¬Ìí¼ÓÒÔÏÂÄÚÈÝ£º
{ "insecure-registries" : ["your-registry-url:5000"] }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬your-registry-urlÊÇÄãµÄ¾µÏñ¿ÍÕ»µÄURL£¨ÀýÈ磺my-registry.com£©¡£
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÖØмÓÔØDockerµÄÉèÖÃÎļþ£¬ÒÔʹ¸ü¸ÄÉúЧ£º
$ systemctl daemon-reload $ systemctl restart docker
µÇ¼ºó¸´ÖÆ
½¨ÉèºÍÉÏ´«¾µÏñ
ÏÖÔÚ£¬ÎÒÃÇ¿ÉÒÔ½¨ÉèDocker¾µÏñ²¢ÉÏ´«µ½×ðÁú¿Ê±¾µÏñ¿ÍÕ»ÖÐÁË¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒª¹¹½¨Ò»¸öDocker¾µÏñ¡£ÒÔÏÂÊÇÒ»¸öʾÀýµÄDockerfileÎļþ£º
FROM ubuntu:latest RUN apt-get update && apt-get install -y python3 COPY app.py /app.py CMD ["python3", "/app.py"]
µÇ¼ºó¸´ÖÆ
ÔÚͳһĿ¼Ï½¨ÉèÒ»¸öÃûΪapp.pyµÄÎļþ£¬²¢Ìí¼ÓһЩ´úÂë¡£Ö®ºó£¬Ê¹ÓÃÒÔÏÂÏÂÁî¹¹½¨¾µÏñ£º
$ docker build -t your-registry-url:5000/my-image:1.0 .
µÇ¼ºó¸´ÖÆ
½«your-registry-urlÌ滻ΪÄãµÄ¾µÏñ¿ÍÕ»µÄURL¡£
¹¹½¨Íê³Éºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ¾µÏñÉÏ´«µ½¾µÏñ¿ÍÕ»ÖУº
$ docker push your-registry-url:5000/my-image:1.0
µÇ¼ºó¸´ÖÆ
Õ⽫»á½«¹¹½¨ºÃµÄ¾µÏñÍÆË͵½×ðÁú¿Ê±¾µÏñ¿ÍÕ»ÖС£
´Ó¾µÏñ¿ÍÕ»ÖÐÀÈ¡¾µÏñ
µ±ÎÒÃÇÐèÒªÔÚÆäËûЧÀÍÆ÷ÉÏ°²ÅÅ×ðÁú¿Ê±Ó¦ÓÃʱ£¬¿ÉÒÔ´Ó¾µÏñ¿ÍÕ»ÖÐÀÈ¡ËùÐèµÄ¾µÏñ¡£ÒÔÏÂÊÇÀÈ¡¾µÏñµÄÏÂÁ
$ docker pull your-registry-url:5000/my-image:1.0
µÇ¼ºó¸´ÖÆ
Õ⽫»á´Ó¾µÏñ¿ÍÕ»ÖÐÀÈ¡¶ÔÓ¦°æ±¾µÄ¾µÏñ¡£
ʹÓÃ˽ÓоµÏñ¿ÍÕ»
ΪÁ˱£»¤×ðÁú¿Ê±Ó¦ÓúÍÊý¾ÝÇå¾²£¬ÎÒÃÇ¿ÉÒÔʹÓûá¼û¿ØÖÆÀ´ÏÞÖƶÔ×ðÁú¿Ê±Ë½ÓоµÏñ¿ÍÕ»µÄ»á¼û¡£ÒÔÏÂÊÇÒ»ÖÖʹÓûù×Ô¼º·ÝÑéÖ¤£¨Basic Authentication£©·½·¨À´¿ØÖÆ»á¼ûµÄʾÀý£º
Ê×ÏÈ£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÃÜÂëÎļþ£¬ÓÃÓÚ´æ´¢Óû§ÃûºÍÃÜÂ롣ʹÓÃÒÔÏÂÏÂÁÉèÃÜÂëÎļþ£º
$ docker run --rm --entrypoint htpasswd registry:2 -Bbn your-username your-password > auth/htpasswd
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬your-usernameºÍyour-passwordÊÇÄãËù½ç˵µÄÓû§ÃûºÍÃÜÂë¡£
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÐÞ¸ÄDocker RegistryµÄÆô¶¯ÏÂÁָ¶¨Ê¹Óûá¼û¿ØÖÆÉèÖá£Ê¹ÓÃÒÔÏÂÏÂÁîÆô¶¯Docker RegistryÈÝÆ÷£º
$ docker run -d -p 5000:5000 --restart=always --name registry -v /path/to/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" registry:2
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬½«/path/to/authÌ滻ΪÄãËù´æ´¢ÃÜÂëÎļþµÄ·¾¶¡£
ÏÖÔÚ£¬ÄãµÄ˽ÓоµÏñ¿ÍÕ»ÒѾÉèÖÃÁË»ù×Ô¼º·ÝÑéÖ¤£¬Ö»ÓоÓÉÊÚȨµÄÓû§²Å»ª¹»»á¼û¡£
×ܽá
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËÔõÑùÔÚLinuxЧÀÍÆ÷ÉϽ¨Éè¸ßЧµÄDocker¾µÏñ¿ÍÕ»¡£ÎÒÃÇÊ×ÏÈ×°Öò¢ÉèÖÃÁËDockerºÍDocker Registry£¬È»ºóͨ¹ý¹¹½¨ºÍÉÏ´«¾µÏñµÄʾÀýÑÝʾÁËÔõÑùʹÓþµÏñ¿ÍÕ»¡£×îºó£¬ÎÒÃÇÏÈÈÝÁËÔõÑùʹÓûù×Ô¼º·ÝÑéÖ¤À´±£»¤¾µÏñ¿ÍÕ»µÄÇå¾²¡£
ͨ¹ý½¨Éè¸ßЧµÄDocker¾µÏñ¿ÍÕ»£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÖÎÀíºÍ°²ÅÅ´ó¹æÄ£µÄÓ¦ÓóÌÐò£¬Ìá¸ß¿ª·¢ºÍÔËάЧÂÊ¡£Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú£¬²¢Äܹ»ÔÚÏÖʵӦÓÃÖÐÊ©Õ¹×÷Óá£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxЧÀÍÆ÷ÉϽ¨Éè¸ßЧµÄDocker¾µÏñ¿ÍÕ»£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡