尊龙凯时人生就是搏

Docker ÈëÃÅ×îÖÕÖ¸ÄÏ£¬Ïêϸ°æ£¡±ðÔÙ˵²»»áÓà Docker ÁË£¡

Web ʱ´ú£¬Ó¦ÓñäµÃÔ½À´Ô½Ç¿Ê¢£¬Óë´ËͬʱҲԽÀ´Ô½ÖØ´ó¡£¼¯Èº°²ÅÅ¡¢¸ôÀëÇéÐΡ¢»Ò¶ÈÐû²¼ÒÔ¼°¶¯Ì¬À©ÈÝȱһ²»¿É£¬¶øÈÝÆ÷»¯Ôò³ÉΪÖÐÐĵÄÐëÒªÇÅÁº¡£±¾½ÚÎÒÃǾÍÀ´Ì½Ë÷һϠDocker µÄÉñÃØÌìÏ£¬´ÓÁãµ½Ò»ÕÆÎÕ Docker µÄ»ùÀ´Ô´ÀíÓëʵ¼ù²Ù×÷¡£±ðÔÙÊØ×ÅÇ°¶ËÄÇһĶÈý·ÖµØ£¬ÊÇʱ¼ä¸Ã¿ª½®À©ÍÁÁË¡£ÎÒÃǽ«»áΧÈÆÏÂÃ漸µãÕö¿ª£º½²¸ö¹ÊÊÂÐéÄâ»úÓëÈÝÆ÷ÊìϤ Docker

µÇ¼ºó¸´ÖÆ

Docker

µÇ¼ºó¸´ÖÆ

Docker ÊÇʲô£¬ÎÒÃÇÏÈÀ´½²¸ö¹ÊÊ£ºÎÒÐèÒª¸ÇÒ»¸öÎÝ×Ó£¬ÓÚÊÇÎÒ°áʯͷ¡¢¿³Ä¾Í·¡¢»æͼֽ¡¢¸ÇÎÝ×Ó¡£Ò»¶Ù²Ù×÷£¬ÖÕÓÚ°ÑÕâ¸öÎÝ×ӸǺÃÁË¡£Ð§¹û£¬×¡ÁËÒ»¶Îʱ¼ä£¬ÐÄѪÀ´³±Ïë°áµ½º£±ßÈ¥¡£Õâʱ¼ä°´ÒÔÍùµÄ²½·¥£¬ÎÒÖ»ÄÜÈ¥º£±ß£¬Ôٴΰáʯͷ¡¢¿³Ä¾Í·¡¢»æͼֽ¡¢¸ÇÎÝ×Ó¡£°ÃÄÕÖ®¼Ê£¬ÅÜÀ´Ò»¸öаÊõʦ½Ì»áÎÒÒ»ÖÖаÊõ¡£ÕâÖÖаÊõ¿ÉÒÔ°ÑÎҸǺõÄÎÝ×Ó¸´ÖÆÒ»·Ý£¬×ö³É¡¸¾µÏñ¡¹£¬·ÅÔÚÎҵı³°üÀï¡£ºÚаÊõµÈÎÒµ½Á˺£±ß£¬¾ÍÓÃÕâ¸ö¡¸¾µÏñ¡¹£¬¸´ÖÆÒ»Ì×ÎÝ×Ó£¬Áà°üÈëס¡£ÊDz»ÊǺÜÉñÆ棿¶ÔÓ¦µ½ÎÒÃǵÄÏîÄ¿ÖÐÀ´£¬ÎÝ×Ó¾ÍÊÇÏîÄ¿×Ô¼º£¬¾µÏñ¾ÍÊÇÏîÄ¿µÄ¸´ÖÆ£¬±³°ü¾ÍÊǾµÏñ¿ÍÕ»¡£ÈôÊÇÒª¶¯Ì¬À©ÈÝ£¬´Ó¿ÍÕ»ÖÐÈ¡³öÏîÄ¿¾µÏñ£¬Ëæ±ã¸´ÖƾͿÉÒÔÁË¡£Build?once£¬Run?anywhere!²»±ØÔÙ¹Ø×¢°æ±¾¡¢¼æÈÝ¡¢°²ÅŵÈÎÊÌ⣬³¹µ×½â¾öÁË¡¸ÉÏÏß¼´±À£¬ÎÞÐÝÖ¹¹¹½¨¡¹µÄÞÏÞÎ¡£¶þ¡¢ÐéÄâ»úÓëÈÝÆ÷×îÏÈ֮ǰ£¬ÎÒÃÇÀ´×öһЩ»ù´¡ÖªÊ¶µÄ´¢±¸£º1.ÐéÄâ»ú£ºÐéÄ⻯Ӳ¼þÐéÄâ»ú Virtual Machine ָͨ¹ýÈí¼þÄ£ÄâµÄ¾ßÓÐÍêÕûÓ²¼þϵͳ¹¦Ð§µÄ¡¢ÔËÐÐÔÚÒ»¸öÍêÈ«¸ôÀëÇéÐÎÖеÄÍêÕûÅÌËã»úϵͳ¡£ÔÚʵÌåÅÌËã»úÖÐÄܹ»Íê³ÉµÄÊÂÇéÔÚÐéÄâ»úÖж¼Äܹ»ÊµÏÖ¡£ÔÚÅÌËã»úÖн¨ÉèÐéÄâ»úʱ£¬ÐèÒª½«ÊµÌå»úµÄ²¿·ÖÓ²Å̺ÍÄÚ´æÈÝÁ¿×÷ΪÐéÄâ»úµÄÓ²Å̺ÍÄÚ´æÈÝÁ¿¡£Ã¿¸öÐéÄâ»ú¶¼ÓÐ×ÔÁ¦µÄ CMOS¡¢Ó²Å̺ͲÙ×÷ϵͳ£¬¿ÉÒÔÏñʹÓÃʵÌå»úÒ»Ñù¶ÔÐéÄâ»ú¾ÙÐвÙ×÷¡£ÔÚÈÝÆ÷ÊÖÒÕ֮ǰ£¬Òµ½çµÄÍøºìÊÇÐéÄâ»ú¡£ÐéÄâ»úÊÖÒյĴú±í£¬ÊÇ VMWare ºÍ OpenStack¡£¸ü¶àÇë²Î¿´£ºhttps://baike.m.zuhaoqu.com/item/%E8%99%9A%E6%8B%9F%E6%9C%BA/104440?fr=aladdin2.ÈÝÆ÷£º½«²Ù×÷ϵͳ²ãÐéÄ⻯£¬ÊÇÒ»¸ö±ê×¼µÄÈí¼þµ¥Î»Ëæ´¦ÔËÐУºÈÝÆ÷¿ÉÒÔ½«´úÂëÓëÉèÖÃÎļþºÍÏà¹ØÒÀÀµ¿â¾ÙÐдò°ü£¬´Ó¶øÈ·±£ÔÚÈκÎÇéÐÎϵÄÔËÐж¼ÊÇÒ»ÖµÄ¡£¸ß×ÊԴʹÓÃÂÊ£ºÈÝÆ÷ÌṩÀú³Ì¼¶µÄ¸ôÀ룬Òò´Ë¿ÉÒÔÔ½·¢Ï¸ÄåµØÉèÖà CPU ºÍÄÚ´æµÄʹÓÃÂÊ£¬½ø¶ø¸üºÃµØʹÓÃЧÀÍÆ÷µÄÅÌËã×ÊÔ´¡£¿ìËÙÀ©Õ¹£ºÃ¿¸öÈÝÆ÷¶¼¿É×÷Ϊµ¥¶ÀµÄÀú³ÌÓèÒÔÔËÐУ¬²¢ÇÒ¿ÉÒÔ¹²Ïíµ×²ã²Ù×÷ϵͳµÄϵͳ×ÊÔ´£¬ÕâÑùÒ»À´¿ÉÒÔ¼ÓËÙÈÝÆ÷µÄÆô¶¯ºÍ×èֹЧÂÊ¡£3.Çø±ðÓëÁªÏµÐéÄâ»úËäÈ»¿ÉÒÔ¸ôÀë³öÐí¶à¡¸×ÓµçÄÔ¡¹£¬µ«Õ¼Óÿռä¸ü´ó£¬Æô¶¯¸üÂý¡£ÐéÄâ»úÈí¼þ¿ÉÄÜ»¹Òª»¨Ç®£¬ÀýÈçVMWare£»ÈÝÆ÷ÊÖÒÕ²»ÐèÒªÐéÄâ³öÕû¸ö²Ù×÷ϵͳ£¬Ö»ÐèÒªÐéÄâÒ»¸öС¹æÄ£µÄÇéÐΣ¬ÀàËÆ¡¸É³Ï䡹£»ÔËÐпռ䣬ÐéÄâ»úÒ»Ñùƽ³£Òª¼¸ GB µ½ ¼¸Ê® GB µÄ¿Õ¼ä£¬¶øÈÝÆ÷Ö»ÐèÒª MB ¼¶ÉõÖÁ KB ¼¶£»ÎÒÃÇÀ´¿´Ò»Ï±ÈÕÕÊý¾Ý£ºÓëÐéÄâ»úÏà±È£¬ÈÝÆ÷¸üÇáÁ¿ÇÒËÙÂʸü¿ì£¬ÓÉÓÚËüʹÓÃÁË Linux µ×²ã²Ù×÷ϵͳÔÚ¸ôÀëµÄÇéÐÎÖÐÔËÐÐ¡£ÐéÄâ»úµÄ Hypervisor ½¨ÉèÁËÒ»¸öºÜÊÇÀο¿µÄ½çÏߣ¬ÒÔ±ÜÃâÓ¦ÓóÌÐòÍ»ÆÆËü£¬¶øÈÝÆ÷µÄ½çÏß²»ÄÇôǿʢ¡£ÎïÀí»ú°²ÅŲ»¿É³ä·ÖʹÓÃ×ÊÔ´£¬Ôì³É×ÊÔ´ÆÌÕÅ¡£ÐéÄâ»ú·½·¨°²ÅÅ£¬ÐéÄâ»ú×Ô¼º»áÕ¼Óôó×Ú×ÊÔ´£¬µ¼ÖÂ×ÊÔ´ÆÌÕÅ£¬ÁíÍâÐéÄâ»úÐÔÄÜÒ²ºÜ²î¡£¶øÈÝÆ÷»¯°²ÅŽÏÁ¿ÎÞа£¬ÇÒÇáÁ¿¼¶£¬ÐÔÄܽϺÃ¡£ÐéÄâ»úÊôÓÚÐéÄ⻯ÊÖÒÕ£¬¶ø Docker ÕâÑùµÄÈÝÆ÷ÊÖÒÕ£¬ÊôÓÚÇáÁ¿¼¶µÄÐéÄ⻯¡£Èý¡¢ÊìϤ DockerDocker1.¿´·¨Docker ÊÇÒ»¸ö¿ªÔ´µÄÓ¦ÓÃÈÝÆ÷ÒýÇ棬ÉÁ¿ª·¢Õß¿ÉÒÔ´ò°üËûÃǵÄÓ¦ÓÃÒÔ¼°ÒÀÀµ°üµ½Ò»¸ö¿ÉÒÆÖ²µÄÈÝÆ÷ÖУ¬È»ºóÐû²¼µ½ÈκÎÊ¢ÐÐµÄ Linux »úеÉÏ£¬Ò²¿ÉÒÔʵÏÖÐéÄ⻯¡£ÈÝÆ÷ÊÇÍêȫʹÓÃɳÏä»úÖÆ£¬Ï໥֮¼ä²»»áÓÐÈκνӿÚ¡£Docker ÊÖÒÕµÄÈý´ó½¹µã¿´·¨£¬»®·ÖÊÇ£º¾µÏñ Image¡¢ÈÝÆ÷ Container¡¢¿ÍÕ» Repository¡£2.Docker ÇáÁ¿¼¶µÄÔµ¹ÊÔ­ÓÉ£¿ÐÅÍÐÄãÒ²»áÓÐÕâÑùµÄÒÉ»ó£ºÎªÊ²Ã´ Docker Æô¶¯¿ì£¿ÔõÑù×öµ½ºÍËÞÖ÷»ú¹²ÏíÄںˣ¿µ±ÎÒÃÇÇëÇó Docker ÔËÐÐÈÝÆ÷ʱ£¬Docker »áÔÚÅÌËã»úÉÏÉèÖÃÒ»¸ö×ÊÔ´¸ôÀëµÄÇéÐÎ¡£È»ºó½«´ò°üµÄÓ¦ÓóÌÐòºÍ¹ØÁªµÄÎļþ¸´ÖƵ½ Namespace ÄÚµÄÎļþϵͳÖУ¬´ËʱÇéÐεÄÉèÖþÍÍê³ÉÁË¡£Ö®ºó Docker »áÖ´ÐÐÎÒÃÇÔ¤ÏÈÖ¸¶¨µÄÏÂÁÔËÐÐÓ¦ÓóÌÐò¡£¾µÏñ²»°üÀ¨Èκζ¯Ì¬Êý¾Ý£¬ÆäÄÚÈÝÔÚ¹¹½¨Ö®ºóÒ²²»»á±»¸Ä±ä¡£ËÄ¡¢½¹µã¿´·¨1.Build, Ship and Run£¨´î½¨¡¢ÔËÊä¡¢ÔËÐУ©£»2.Build?once, Run?anywhere£¨Ò»´Î´î½¨£¬Ëæ´¦ÔËÐУ©£»3.Docker ×Ô¼º²¢²»ÊÇÈÝÆ÷£¬ËüÊǽ¨ÉèÈÝÆ÷µÄ¹¤¾ß£¬ÊÇÓ¦ÓÃÈÝÆ÷ÒýÇ棻4.Docker Èý´ó½¹µã¿´·¨£¬»®·ÖÊÇ£º¾µÏñ Image£¬ÈÝÆ÷ Container¡¢¿ÍÕ» Repository£»5.Docker ÊÖÒÕʹÓà Linux Äں˺ÍÄں˹¦Ð§£¨ÀýÈç Cgroups ºÍ namespaces£©À´ÍÑÀëÀú³Ì£¬ÒÔ±ã¸÷Àú³ÌÏ໥×ÔÁ¦ÔËÐÐ¡£6.ÓÉÓÚ Namespace ºÍ Cgroups ¹¦Ð§½öÔÚ Linux ÉÏ¿ÉÓã¬Òò´ËÈÝÆ÷ÎÞ·¨ÔÚÆäËû²Ù×÷ϵͳÉÏÔËÐÐ¡£ÄÇô Docker ÔõÑùÔÚ macOS »ò Windows ÉÏÔËÐУ¿ Docker ÏÖʵÉÏʹÓÃÁËÒ»¸ö¼¼ÇÉ£¬²¢ÔÚ·Ç Linux ²Ù×÷ϵͳÉÏ×°Öà Linux ÐéÄâ»ú£¬È»ºóÔÚÐéÄâ»úÄÚÔËÐÐÈÝÆ÷¡£ÁíÍ⣬ËÑË÷ÃñÖÚºÅpythonÈ˹¤ÖÇÄÜÊÖÒÕºǫ́»Ø¸´¡°ÃûÖø¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£7.¾µÏñÊÇÒ»¸ö¿ÉÖ´Ðаü£¬Æä°üÀ¨ÔËÐÐÓ¦ÓóÌÐòËùÐèµÄ´úÂë¡¢ÔËÐÐʱ¡¢¿â¡¢ÇéÐαäÁ¿ºÍÉèÖÃÎļþ£¬ÈÝÆ÷ÊǾµÏñµÄÔËÐÐʱʵÀý¡£Îå¡¢×°Öà Docker1.ÏÂÁîÐÐ×°ÖÃHomebrew µÄ Cask ÒѾ­Ö§³Ö Docker for Mac£¬Òò´Ë¿ÉÒÔºÜÀû±ãµÄʹÓà Homebrew Cask À´¾ÙÐÐ×°Öã¬Ö´ÐÐÈçÏÂÏÂÁbrew cask install docker

¸ü¶à×°Ö÷½·¨£¬ÇëÉó²é¹Ù·½Îĵµ£ºhttps://www.docker.com/get-started2.Éó²é°æ±¾docker -v  

3.ÉèÖþµÏñ¼ÓËÙÉèÖà Docker Engine дÈëÉèÖãº{
  "registry-mirrors": [
    "http://hub-mirror.c.163.com/",
    "https://registry.docker-cn.com"
  ],
  "insecure-registries":[],
  "experimental": false,
  "debug": true
}

4.×°ÖÃ×ÀÃæ¶ËDocker ×ÀÃæ¶Ë×ÀÃæ¶Ë²Ù×÷ºÜÊǼòÆÓ£¬ÏÈÈ¥¹ÙÍøÏÂÔØ¡£Í¨¹ý Docker ×ÀÃæ¶Ë£¬ÎÒÃÇ¿ÉÒÔÀû±ãµÄ²Ù×÷£ºclone£º¿Ë¡һ¸öÏîÄ¿build£º´ò°ü¾µÏñrun£ºÔËÐÐʵÀýshare£º¹²Ïí¾µÏñºÃÁË£¬×¼±¸ÊÂÇéÍ£µ±£¬ÏÂÃæ¿ÉÒÔ´óÕ¹ÉíÊÖÁË£¡Áù¡¢¿ìËÙ×îÏÈ×°ÖÃÍê Docker Ö®ºó£¬ÎÒÃÇÏÈ´ò¸öÏÖʵÏîÄ¿µÄ¾µÏñ£¬±ßѧ±ßÓÃ¡£1.Ê×ÏÈÐèÒª´óÖÂÏàʶһÏÂÎÒÃǽ«»áÓõ½µÄ 11 ¸öÏÂÁî2.н¨ÏîĿΪÁË¿ì½Ý£¬ÎÒÃÇÖ±½ÓʹÓÃVue ½ÅÊּܹ¹½¨ÏîÄ¿£ºvue create docker-demo  

ʵÑéÆô¶¯Ò»Ï£ºyarn serve  

»á¿´·¨Ö·£ºhttp://localhost:8080/¡£ÏîÄ¿Í£µ±£¬ÎÒÃǽÓ×ÅΪÏîÄ¿´ò°ü£ºyarn build  

Õâʱ¼ä£¬ÏîĿĿ¼Ï嵀 Dist ¾ÍÊÇÎÒÃÇÒª°²Åŵľ²Ì¬×ÊÔ´ÁË£¬ÎÒÃǼÌÐøÏÂÒ»²½¡£ÐèҪעÖØ£ºÇ°¶ËÏîÄ¿Ò»Ñùƽ³£·ÖÁ½À࣬һÀàÖ±½Ó Nginx ¾²Ì¬°²ÅÅ£¬Ò»ÀàÐèÒªÆô¶¯ Node ЧÀÍ¡£±¾½ÚÎÒÃÇֻ˼Á¿µÚÒ»ÖÖ¡£3.н¨ Dockerfilecd docker-demo && touch Dockerfile  

´ËʱµÄÏîĿĿ¼ÈçÏ£º.  
©À©¤©¤ Dockerfile  
©À©¤©¤ README.md  
©À©¤©¤ babel.config.js  
©À©¤©¤ dist  
©À©¤©¤ node_modules  
©À©¤©¤ package.json  
©À©¤©¤ public  
©À©¤©¤ src  
©¸©¤©¤ yarn.lock  

¿ÉÒÔ¿´µ½ÎÒÃÇÒѾ­ÔÚ docker-demo Ŀ¼ÏÂÀֳɽ¨ÉèÁË Dockerfile Îļþ¡£Å£±Æ°¡£¡½Ó˽»î±Ø±¸µÄ N ¸ö¿ªÔ´ÏîÄ¿£¡¸ÏæÕä²Ø°É
4.×¼±¸ Nginx ¾µÏñÔËÐÐÄãµÄ Docker ×ÀÃæ¶Ë£¬¾Í»áĬÈÏÆô¶¯ÊµÀý£¬ÎÒÃÇÔÚ¿ØÖÆ̨À­È¡ Nginx ¾µÏñ£ºdocker pull nginx  

¿ØÖÆ̨»á·ºÆðÈçÏÂÐÅÏ¢£ºUsing default tag: latest
latest: Pulling from library/nginx
8559a31e96f4: Pull complete
8d69e59170f7: Pull complete
3f9f1ec1d262: Pull complete
d1f5ff4f210d: Pull complete
1e22bfa8652e: Pull complete
Digest: sha256:21f32f6c08406306d822a0e6e8b7dc81f53f336570e852e25fbe1e3e3d0d0133
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

ÈôÊÇÄã·ºÆðÕâÑùµÄÒì³££¬ÇëÈ·ÈÏ Docker ʵÀýÊÇ·ñÕý³£ÔËÐÐ¡£Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?  

¾µÏñ×¼±¸ OK£¬ÎÒÃÇÔÚ¸ùĿ¼½¨Éè Nginx ÉèÖÃÎļþ£ºtouch default.conf  

дÈ룺server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    access_log  /var/log/nginx/host.access.log  main;
    error_log  /var/log/nginx/error.log  error;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

5.ÉèÖþµÏñ·­¿ª Dockerfile £¬Ð´ÈëÈçÏÂÄÚÈÝ£ºFROM nginx  
COPY dist/ /usr/share/nginx/html/  
COPY default.conf /etc/nginx/conf.d/default.conf  

ÎÒÃÇÖðÐÐÚ¹ÊÍһϴúÂ룺FROM nginx Ö¸¶¨¸Ã¾µÏñÊÇ»ùÓÚ nginx:latest ¾µÏñ¶ø¹¹½¨µÄ£»COPY dist/ /usr/share/nginx/html/ ÏÂÁîµÄÒâ˼Êǽ«ÏîÄ¿¸ùĿ¼Ï dist Îļþ¼ÐÖеÄËùÓÐÎļþ¸´ÖƵ½¾µÏñÖÐ /usr/share/nginx/html/ Ŀ¼Ï£»COPY default.conf /etc/nginx/conf.d/default.conf ½« default.conf ¸´ÖƵ½ etc/nginx/conf.d/default.conf£¬ÓÃÍâµØµÄ default.conf ÉèÖÃÀ´Ìæ»» Nginx ¾µÏñÀïµÄĬÈÏÉèÖÃ¡£6.¹¹½¨¾µÏñDocker ͨ¹ý build ÏÂÁîÀ´¹¹½¨¾µÏñ£ºdocker build -t jartto-docker-demo .  

ƾ֤ÀÏÀý£¬ÎÒÃÇÚ¹ÊÍÒ»ÏÂÉÏÊö´úÂ룺-t ²ÎÊý¸ø¾µÏñÃüÃû jartto-docker-demo. ÊÇ»ùÓÚÄ¿½ñĿ¼µÄ Dockerfile À´¹¹½¨¾µÏñÖ´ÐÐÀֳɺ󣬽«»áÊä³ö£ºSending build context to Docker daemon  115.4MB
Step 1/3 : FROM nginx
 ---> 2622e6cca7eb
Step 2/3 : COPY dist/ /usr/share/nginx/html/
 ---> Using cache
 ---> 82b31f98dce6
Step 3/3 : COPY default.conf /etc/nginx/conf.d/default.conf
 ---> 7df6efaf9592
Successfully built 7df6efaf9592
Successfully tagged jartto-docker-demo:latest

¾µÏñÖÆ×÷Àֳɣ¡ÎÒÃÇÀ´Éó²éÒ»ÏÂÈÝÆ÷£ºdocker image ls | grep jartto-docker-demo  

¿ÉÒÔ¿´µ½£¬ÎÒÃÇ´ò³öÁËÒ»¸ö 133MB µÄÏîÄ¿¾µÏñ£ºjartto-docker-demo latest 7df6efaf9592 About a minute ago 133MB  

¾µÏñÒ²ÓÐÓÅÁÓÖ®·Ö£¬ºóÐøÎÒÃǽ«ÏÈÈÝÔõÑùÓÅ»¯£¬ÕâÀï¿ÉÒÔÏÈÔÝʱºöÂÔ¡£À©Õ¹£º½Ó˽»î¶ù7.ÔËÐÐÈÝÆ÷docker run -d -p 3000:80 --name docker-vue jartto-docker-demo  

ÕâÀïÚ¹ÊÍһϲÎÊý£º-d ÉèÖÃÈÝÆ÷ÔÚºǫ́ÔËÐÐ-p ÌåÏֶ˿ÚÓ³É䣬°Ñ±¾»úµÄ 3000 ¶Ë¿ÚÓ³Éäµ½ container µÄ 80 ¶Ë¿Ú£¨ÕâÑùÍâÍø¾ÍÄÜͨ¹ý±¾»úµÄ 3000 ¶Ë¿Ú»á¼ûÁË¡£ÁíÍ⣬ËÑË÷ÃñÖںűà³ÌÊÖÒÕȦºǫ́»Ø¸´¡°ÉñÆ÷¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£--name ÉèÖÃÈÝÆ÷Ãû docker-vuejartto-docker-demo ÊÇÎÒÃÇÉÏÃæ¹¹½¨µÄ¾µÏñÃû×ÖÔö²¹Ò»µã£ºÔÚ¿ØÖÆ̨£¬ÎÒÃÇ¿ÉÒÔͨ¹ý docker ps Éó²é¸ÕÔËÐÐµÄ Container µÄ ID£ºdocker ps -a  

¿ØÖÆ̨»áÊä³ö£ºCONTAINER ID IMAGE              COMMAND                  CREATED       STATUS PORTS  NAMES
ab1375befb0b jartto-docker-demo "/docker-entrypoint.¡­"   8 minutes ago Up 7 minutes  0.0.0.0:3000->80/tcp  docker-vue

ÈôÊÇÄãʹÓÃ×ÀÃæ¶Ë£¬ÄÇô·­¿ª Docker Dashboard ¾Í¿ÉÒÔ¿´µ½ÈÝÆ÷ÁбíÁË£¬ÈçÏÂͼ£º8.»á¼ûÏîÄ¿ÓÉÓÚÎÒÃÇÓ³ÉäÁ˱¾»ú 3000 ¶Ë¿Ú£¬ÒÔÊÇÖ´ÐУºcurl -v -i localhost:3000  

»òÕß·­¿ªä¯ÀÀÆ÷£¬»á¼û£ºlocalhost:30009.Ðû²¼¾µÏñÈôÊÇÄãÏëΪÉçÇøТ˳ʵÁ¦£¬ÄÇôÐèÒª½«¾µÏñÐû²¼£¬Àû±ãÆäËû¿ª·¢ÕßʹÓÃ¡£Ðû²¼¾µÏñÐèÒªÈçÏ°취£ºÉÏ°¶ [dockerhub](https://hub.docker.com)£¬×¢²áÕ˺Å£»ÏÂÁîÐÐÖ´ÐÐ docker login£¬Ö®ºóÊäÈëÎÒÃǵÄÕ˺ÅÃÜÂ룬¾ÙÐеǼ£»ÍÆË;µÏñ֮ǰ£¬ÐèÒª´òÒ»¸ö Tag£¬Ö´ÐÐ docker tag <image> <username>/<repository>:<tag>È«Á÷³Ì¿¢Ê£¬ÒÔºóÎÒÃÇҪʹÓã¬ÔÙÒ²²»ÐèÒª¡¸°áʯͷ¡¢¿³Ä¾Í·¡¢»æͼֽ¡¢¸ÇÎÝ×Ó¡¹ÁË£¬Áà°üÈëס¡£ÕâÒ²ÊÇ docker ÆæÒì÷ÈÁ¦ËùÔÚ¡£Æß¡¢Í¨Àý²Ù×÷µ½ÕâÀ¹§Ï²ÄãÒѾ­Íê³ÉÁË Docker µÄÈëÃÅÏîÄ¿£¡ÈôÊÇ»¹Ïë¼ÌÐøÉîÈ룬ÎÞ·Á½Ó×ÅÍùÏ¿´¿´¡£1.²ÎÊýʹÓÃFROM

µÇ¼ºó¸´ÖÆ

FROM ÏÂÁî±ØÐèÊÇ Dockerfile µÄµÚÒ»¸öÏÂÁîFROM <image> [AS <name>] Ö¸¶¨´ÓÒ»¸ö¾µÏñ¹¹½¨ÆðÒ»¸öеľµÏñÃû×ÖFROM <image>[:<tag>] [AS <name>] Ö¸¶¨¾µÏñµÄ°æ±¾ Tag

µÇ¼ºó¸´ÖÆ

FROM mysql:5.0 AS database

µÇ¼ºó¸´ÖÆ

MAINTAINER

µÇ¼ºó¸´ÖÆ

MAINTAINER <name>

µÇ¼ºó¸´ÖÆ

MAINTAINER Jartto Jartto@qq.com

µÇ¼ºó¸´ÖÆ

RUN

µÇ¼ºó¸´ÖÆ

RUN <command>

µÇ¼ºó¸´ÖÆ

RUN ["executable", "param1", "param2"]

µÇ¼ºó¸´ÖÆ

ADD

µÇ¼ºó¸´ÖÆ

ADD <src> <dest>

µÇ¼ºó¸´ÖÆ

ADD *.js /app Ìí¼Ó js Îļþµ½ÈÝÆ÷ÖÐµÄ app Ŀ¼ÏÂCOPY

µÇ¼ºó¸´ÖÆ

ADD Ò»Ñù£¬Ö»ÊǸ´ÖÆ£¬²»»á½âѹ»òÕßÏÂÔØÎļþCMD

µÇ¼ºó¸´ÖÆ

RUN ·×ÆçÑù£¬RUN ÊÇÔÚ¹¹½¨¾µÏñÊÇÒªÔËÐеÄÏÂÁʹÓà docker run ÔËÐÐÈÝÆ÷µÄʱ¼ä£¬Õâ¸ö¿ÉÒÔÔÚÏÂÁîÐб»ÁýÕÖʾÀý£ºCMD ["executable", "param1", "param2"]

µÇ¼ºó¸´ÖÆ

ENTRYPOINT

µÇ¼ºó¸´ÖÆ

CMD Ò»Ñù£¬Ö»ÊÇÕâ¸öÏÂÁî²»»á±»ÏÂÁîÐÐÁýÕÖENTRYPOINT ["executable", "param1", "param2"]

µÇ¼ºó¸´ÖÆ

ENTRYPOINT ["donnet", "myapp.dll"]

µÇ¼ºó¸´ÖÆ

LABEL£ºÎª¾µÏñÌí¼ÓÔªÊý¾Ý£¬key-value ÐÎʽLABEL <key>=<value> <key>=<value> ...

µÇ¼ºó¸´ÖÆ

LABEL version="1.0" description="ÕâÊÇÒ»¸öwebÓ¦ÓÃ"

µÇ¼ºó¸´ÖÆ

ENV£ºÉèÖÃÇéÐαäÁ¿£¬ÓÐЩÈÝÆ÷ÔËÐÐʱ»áÐèҪijЩÇéÐαäÁ¿ENV <key> <value> Ò»´ÎÉèÖÃÒ»¸öÇéÐαäÁ¿ENV <key>=<value> <key>=<value> <key>=<value> ÉèÖöà¸öÇéÐαäÁ¿Ê¾Àý£ºENV JAVA_HOME /usr/java1.8/

µÇ¼ºó¸´ÖÆ

EXPOSE£ºÌ»Â¶¶ÔÍâµÄ¶Ë¿Ú£¨ÈÝÆ÷ÄÚ²¿³ÌÐòµÄ¶Ë¿Ú£¬ËäÈ»»áºÍËÞÖ÷»úµÄÒ»Ñù£¬¿ÉÊÇ×ÅʵÊÇÁ½¸ö¶Ë¿Ú£©EXPOSE <port>

µÇ¼ºó¸´ÖÆ

EXPOSE 80

µÇ¼ºó¸´ÖÆ

-p Ó³ÉäÍⲿ¶Ë̸·æÆø»á¼ûµ½ÈÝÆ÷ÄڵĶ˿ÚVOLUME£ºÖ¸¶¨Ãü¾Ý³¤ÆÚ»¯µÄĿ¼£¬¹Ù·½ÓïÑÔ½Ð×ö¹ÒÔØVOLUME /var/log Ö¸¶¨ÈÝÆ÷ÖÐÐèÒª±»¹ÒÔصÄĿ¼£¬»á°ÑÕâ¸öĿ¼ӳÉäµ½ËÞÖ÷»úµÄÒ»¸öËæ»úĿ¼ÉÏ£¬ÊµÏÖÊý¾ÝµÄ³¤ÆÚ»¯ºÍͬ²½¡£VOLUME ["/var/log","/var/test".....] Ö¸¶¨ÈÝÆ÷Öжà¸öÐèÒª±»¹ÒÔصÄĿ¼£¬»á°ÑÕâЩĿ¼ӳÉäµ½ËÞÖ÷»úµÄ¶à¸öËæ»úĿ¼ÉÏ£¬ÊµÏÖÊý¾ÝµÄ³¤ÆÚ»¯ºÍͬ²½VOLUME /var/data var/log Ö¸¶¨ÈÝÆ÷ÖÐµÄ var/log Ŀ¼¹ÒÔص½ËÞÖ÷»úÉ쵀 /var/data Ŀ¼£¬ÕâÖÖÐÎʽ¿ÉÒÔÊÖ¶¯Ö¸¶¨ËÞÖ÷»úÉϵÄĿ¼WORKDIR£ºÉèÖÃÊÂÇéĿ¼£¬ÉèÖÃÖ®ºó £¬RUN¡¢CMD¡¢COPY¡¢ADD µÄÊÂÇéĿ¼¶¼»áͬ²½±ä»»WORKDIR <path>

µÇ¼ºó¸´ÖÆ

WORKDIR /app/test

µÇ¼ºó¸´ÖÆ

USER£ºÖ¸¶¨ÔËÐÐÏÂÁîʱËùʹÓõÄÓû§£¬ÎªÁËÇå¾²ºÍȨÏÞÆð¼û£¬Æ¾Ö¤ÒªÖ´ÐеÄÏÂÁîÑ¡Ôñ²î±ðÓû§USER <user>:[<group>]

µÇ¼ºó¸´ÖÆ

USER test

µÇ¼ºó¸´ÖÆ

ARG£ºÉèÖù¹½¨¾µÏñÊÇҪת´ïµÄ²ÎÊýARG <name>[=<value>]

µÇ¼ºó¸´ÖÆ

ARG name=sss

µÇ¼ºó¸´ÖÆ

¸ü¶à²Ù×÷£¬ÇëÒƲ½¹Ù·½Ê¹ÓÃÎĵµ£º

https://docs.docker.com/

°Ë¡¢×î¼Ñʵ¼ù

ÔÚÕÆÎÕ Docker Í¨Àý²Ù×÷Ö®ºó£¬ÎÒÃǺÜÈÝÒ׾ͿÉÒÔ´ò³ö×Ô¼ºÏëÒªµÄÏîÄ¿¾µÏñ ¡£È»¶ø²î±ðµÄ²Ù×÷´ò³öµÄ¾µÏñÒ²ÊÇǧ²îÍò±ð ¡£

ÊÂʵÊÇʲôԵ¹ÊÔ­Óɵ¼Ö¾µÏñ²î±ð£¬ÎÒÃÇÎÞ·Á¼ÌÐø̽Ë÷ ¡£

ÒÔÏÂÊÇÔÚÓ¦ÓàDocker Àú³ÌÖÐÕûÀíµÄ×î¼Ñʵ¼ù£¬ÇëÖ»¹Ü×ñÕÕÈçÏÂ×¼Ôò£º

Require Ã÷È·£ºÐèҪʲô¾µÏñ

°ì·¨¾«¼ò£º×ª±ä½ÏÉٵĠStep ÓÅÏÈ

°æ±¾Ã÷È·£º¾µÏñÃüÃûÃ÷È·

˵Ã÷Îĵµ£ºÕû¸ö¾µÏñ´ò°ü°ì·¨¿ÉÒÔÖØÏÖ

¾Å¡¢×ܽá

ÈÝÆ÷»¯ÊÖÒձؽ«ÊÇÔÆʱ´ú²»¿É»òȱµÄÊÖÒÕÖ®Ò»£¬¶ø Docker Ö»ÊǾÅţһë ¡£ËæÖ®¶øÀ´µÄÉÐÓм¯ÈºÈÝÆ÷ÖÎÀí K8s¡¢Service Mesh ¡¢Istio µÈÊÖÒÕ ¡£·­¿ª Docker µÄ´óÃÅ£¬Ò»Ö±³éË¿°þ¼ë£¬Öð²ãÉîÈ룬Ä㽫¸ÐÊܵ½ÈÝÆ÷»¯µÄÎÞÏÞ÷ÈÁ¦ ¡£

ÒÔÉϾÍÊÇDocker ÈëÃÅ×îÖÕÖ¸ÄÏ£¬Ïêϸ°æ£¡±ðÔÙ˵²»»áÓà Docker ÁË£¡µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ