dockerÔõô½¨Éè¾µÏñ
ÔõÑù¹¹½¨ docker ¾µÏñ£¿½¨Éè°üÀ¨¹¹½¨Ö¸ÁîµÄ dockerfile¡£Í¨¹ý docker build ÏÂÁî´Ó dockerfile ¹¹½¨¾µÏñ¡£Ê¹ÓÿÉÑ¡µÄ docker push ÏÂÁîÍÆË;µÏñµ½×¢²á±í¡£Ê¹Óà docker run ÏÂÁîÔËÐдӾµÏñ½¨ÉèµÄÈÝÆ÷¡£
ÔõÑùʹÓà Docker ¹¹½¨¾µÏñ
½¨Éè Docker ¾µÏñÊǽ«Ó¦ÓóÌÐò¼°ÆäËùÓÐÒÀÀµÏî´ò°ü³Éµ¥¸ö¿ÉÒÆÖ²µ¥Î»µÄÀú³Ì£¬´Ó¶øʵÏÖ¿çÇéÐεÄÒ»Ö°²ÅÅ¡£ÒÔÏÂÊÇÔõÑùʹÓà Docker ¹¹½¨¾µÏñµÄ°ì·¨£º
1. ½¨Éè Dockerfile
Dockerfile ÊÇÒ»¸öÎı¾Îļþ£¬ÆäÖаüÀ¨Ò»ÏµÁÐÖ¸ÁÏêϸ˵Ã÷ÔõÑù¹¹½¨¾µÏñ¡£Ëü±ØÐè°üÀ¨ÒÔÏÂÖ¸Á
FROM£ºÖ¸¶¨»ù´¡¾µÏñ
RUN£ºÔËÐÐÏÂÁîÒÔ×°ÖÃÒÀÀµÏî»òÖ´ÐÐÆäËû²Ù×÷
COPY£º½«Îļþ»òĿ¼´ÓÖ÷»ú¸´ÖƵ½¾µÏñ
CMD£ºÖ¸¶¨¾µÏñÆô¶¯Ê±ÒªÔËÐеÄÏÂÁî
2. ¹¹½¨¾µÏñ
ʹÓÃÒÔÏÂÏÂÁî´Ó Dockerfile ¹¹½¨¾µÏñ£º
docker build -t [¾µÏñÃû³Æ] [Dockerfile ·¾¶]
µÇ¼ºó¸´ÖÆ
ÆäÖУº
-t£ºÖ¸¶¨¾µÏñÃû³Æ
[¾µÏñÃû³Æ]£ºÒª½¨ÉèµÄ¾µÏñµÄÃû³Æ
[Dockerfile ·¾¶]£ºDockerfile µÄ·¾¶
3. ÍÆË;µÏñ£¨¿ÉÑ¡£©
ÈôÊÇÄúÏ£ÍûÔÚÆäËû»úеÉÏʹÓøþµÏñ£¬Äú¿ÉÒÔ½«ÆäÍÆË͵½ Docker ×¢²á±íÖУº
docker push [¾µÏñÃû³Æ]
µÇ¼ºó¸´ÖÆ
4. ʹÓþµÏñ
Äú¿ÉÒÔʹÓà docker run ÏÂÁîÔËÐдӾµÏñ½¨ÉèµÄÈÝÆ÷£º
docker run [¾µÏñÃû³Æ] [ÏÂÁî]
µÇ¼ºó¸´ÖÆ
ÆäÖУº
[¾µÏñÃû³Æ]£ºÒªÔËÐеľµÏñµÄÃû³Æ
[ÏÂÁî]£ºÔÚÈÝÆ÷Æô¶¯Ê±ÒªÔËÐеÄÏÂÁ¿ÉÑ¡£©
ʾÀý Dockerfile
ÒÔÏÂÊÇÒ»¸öÓÃÓÚ¹¹½¨ Node.js Ó¦ÓóÌÐò¾µÏñµÄʾÀý Dockerfile£º
FROM node:16 WORKDIR /usr/src/app COPY package.json yarn.lock ./ RUN yarn install COPY . ./ CMD ["node", "index.js"]
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇdockerÔõô½¨Éè¾µÏñµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡