dockerÔËÐÐÈÝÆ÷ÔõôÓÃ
ÒªÔËÐÐ docker ÈÝÆ÷£¬ÐèÒÀ´ÎÖ´ÐУºÀÈ¡¾µÏñ (docker pull )½¨ÉèÈÝÆ÷ (docker run -it –rm –name )½»»¥²Ù×÷ÈÝÆ÷ (docker exec -it /bin/bash)¶Ë¿ÚÓ³Éä (docker run -it –rm –name my-nginx -p 8080:80 nginx)ÉèÖÃÇéÐαäÁ¿ (docker run -it –rm –name
ÔõÑùÔËÐÐ Docker ÈÝÆ÷
ÔËÐÐ Docker ÈÝÆ÷Éæ¼°ÒÔÏ°취£º
1. ÀÈ¡¾µÏñ
Ê×ÏÈ£¬ÐèÒªÀÈ¡ËùÐè¾µÏñ¡£¾µÏñÊÇ°üÀ¨Ó¦ÓóÌÐò¡¢¿âºÍÒÀÀµÏîµÄ¿ÉÖ´ÐÐÎļþ¡£Ê¹ÓÃÒÔÏÂÏÂÁîÀÈ¡¾µÏñ£º
docker pull
µÇ¼ºó¸´ÖÆ
ÀýÈ磬ҪÀÈ¡ Nginx ¾µÏñ£º
docker pull nginx
µÇ¼ºó¸´ÖÆ
2. ½¨ÉèÈÝÆ÷
ÀÈ¡¾µÏñºó£¬¿ÉÒÔʹÓà docker run ÏÂÁÉèÈÝÆ÷¡£¸ÃÏÂÁîÔÊÐíÖ¸¶¨ÈÝÆ÷µÄÔËÐÐÉèÖã¬ÀýÈç¶Ë¿ÚÓ³ÉäºÍÇéÐαäÁ¿¡£ÒÔÏÂÊÇÒ»¸ö»ù±¾Ê¾Àý£º
docker run -it --rm --name
µÇ¼ºó¸´ÖÆ
ÀýÈ磬Ҫ½¨ÉèÒ»¸öÃûΪ “my-nginx” µÄÈÝÆ÷£º
docker run -it --rm --name my-nginx nginx
µÇ¼ºó¸´ÖÆ
3. ½»»¥²Ù×÷
ÈÝÆ÷½¨Éèºó£¬¿ÉÒÔʹÓý»»¥Ê½Ä£Ê½½øÈëÈÝÆ÷¡£ÕâÔÊÐíÔÚÈÝÆ÷ÄÚÖ´ÐÐÏÂÁîºÍÉó²éÊä³ö¡£ÒÔÏÂÊǽøÈëÈÝÆ÷µÄÏÂÁ
docker exec -it /bin/bash
µÇ¼ºó¸´ÖÆ
4. ¶Ë¿ÚÓ³Éä
ÈôÊÇÈÝÆ÷ÐèҪ̻¶¶Ë¿ÚÒÔÓëÍⲿÌìÏÂͨѶ£¬ÔòÐèÒª¾ÙÐж˿ÚÓ³Éä¡£Õâ¿ÉÒÔʹÓà -p ±ê¼ÇÍê³É£¬¸Ã±ê¼ÇÖ¸¶¨Ö÷»ú¶Ë¿ÚºÍÈÝÆ÷¶Ë¿Ú¡£ÒÔÏÂʾÀý½«ÈÝÆ÷ÖÐµÄ 80 ¶Ë¿ÚÓ³Éäµ½Ö÷»úÉ쵀 8080 ¶Ë¿Ú£º
docker run -it --rm --name my-nginx -p 8080:80 nginx
µÇ¼ºó¸´ÖÆ
5. ÇéÐαäÁ¿
¿ÉÒÔÔÚ½¨ÉèÈÝÆ÷ʱÉèÖÃÇéÐαäÁ¿£¬ÒÔ±ãÈÝÆ÷ÄÚµÄÓ¦ÓóÌÐò¿ÉÒÔ»á¼ûËüÃÇ¡£Ê¹Óà -e ±ê¼ÇÖ¸¶¨ÇéÐαäÁ¿£¬ÈçÏÂËùʾ£º
docker run -it --rm --name my-nginx -e MY_ENV_VAR=value nginx
µÇ¼ºó¸´ÖÆ
6. ×èÖ¹ºÍɾ³ýÈÝÆ÷
µ±ÈÝÆ÷²»ÔÙÐèҪʱ£¬¿ÉÒÔʹÓà docker stop ÏÂÁî×èÖ¹Ëü£¬È»ºóʹÓà docker rm ÏÂÁîɾ³ýËü¡£ÒÔÏÂʾÀýÏÔʾÔõÑù×èÖ¹ºÍɾ³ý “my-nginx” ÈÝÆ÷£º
docker stop my-nginx docker rm my-nginx
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇdockerÔËÐÐÈÝÆ÷ÔõôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡