dockerfileÎļþÔõôÔËÐÐ
dockerfile ÎļþÊǹ¹½¨ docker ¾µÏñµÄÎı¾Îļþ£¬°üÀ¨Ö¸µ¼ docker ¹¹½¨¾µÏñµÄÖ¸Áî¡£ÒªÔËÐÐ dockerfile Îļþ£¬Çëƾ֤ÒÔÏ°취²Ù×÷£º½¨Éè dockerfile Îļþ£¬°üÀ¨¹¹½¨¾µÏñËùÐèµÄÖ¸Áî¡£ÔÚ°üÀ¨ dockerfile ÎļþµÄĿ¼Öй¹½¨¾µÏñ¡£Ê¹Óù¹½¨µÄ¾µÏñÔËÐÐÈÝÆ÷¡£½øÈëÕýÔÚÔËÐеÄÈÝÆ÷Ö´ÐÐÏÂÁî¡£×èÖ¹²¢É¾³ýÈÝÆ÷¡£
Dockerfile ÎļþµÄÔËÐÐ
Dockerfile ÎļþÊÇÒ»¸öÓÃÓÚ¹¹½¨ Docker ¾µÏñµÄÎı¾Îļþ¡£Ëü°üÀ¨Ò»×éÖ¸Áָµ¼ Docker Öð²ã¹¹½¨¾µÏñ¡£ÒªÔËÐÐ Dockerfile Îļþ£¬ÇëʹÓÃÒÔÏ°취£º
1. ½¨Éè Dockerfile Îļþ
½¨Éè°üÀ¨ÒÔÏÂÄÚÈݵÄÐÂÎı¾Îļþ£¬²¢½«ÆäÃüÃûΪ “Dockerfile”£º
FROM nginx COPY index.html /usr/share/nginx/html
µÇ¼ºó¸´ÖÆ
2. ¹¹½¨¾µÏñ
ÔÚ°üÀ¨ Dockerfile ÎļþµÄĿ¼ÖУ¬ÔËÐÐÒÔÏÂÏÂÁ
docker build -t my-nginx-image .
µÇ¼ºó¸´ÖÆ
3. ÔËÐÐÈÝÆ÷
¹¹½¨¾µÏñºó£¬Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÔËÐÐÈÝÆ÷£º
docker run -it --rm --name my-nginx-container my-nginx-image
µÇ¼ºó¸´ÖÆ
Õ⽫½¨ÉèÒ»¸öÃûΪ “my-nginx-container” µÄÐÂÈÝÆ÷²¢ÔËÐÐËü¡£Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÉó²éÕýÔÚÔËÐеÄÈÝÆ÷£º
docker ps
µÇ¼ºó¸´ÖÆ
4. »á¼ûÈÝÆ÷
ÈÝÆ÷ÔËÐк󣬿ÉÒÔʹÓÃÒÔÏÂÏÂÁî½øÈëÈÝÆ÷£º
docker exec -it my-nginx-container bash
µÇ¼ºó¸´ÖÆ
Õ⽫·¿ªÒ»¸ö½»»¥Ê½ Shell£¬Äú¿ÉÒÔÔÚÆäÖÐÖ´ÐÐÏÂÁî¡£ÒªÍ˳ö Shell£¬Çë¼üÈë “exit”¡£
5. ×èÖ¹ÈÝÆ÷
Òª×èÖ¹ÈÝÆ÷£¬ÇëʹÓÃÒÔÏÂÏÂÁ
docker stop my-nginx-container
µÇ¼ºó¸´ÖÆ
ÈÝÆ÷×èÖ¹ºó£¬Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîɾ³ýËü£º
docker rm my-nginx-container
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇdockerfileÎļþÔõôÔËÐеÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡