dockerÔõôÉèÖÃhost
Ϊ docker ÈÝÆ÷ÉèÖÃÖ÷»úÐèÐÞ¸ÄËÞÖ÷»úÉ쵀 /etc/hosts Îļþ£¬°ì·¨°üÀ¨£º1. È·¶¨Ä¿µÄÈÝÆ÷ ip µØµã£»2. ±à¼ hosts Îļþ£»3. Ìí¼ÓÖ÷»ú¼Í¼¡£ÀýÈ磬½«ÈÝÆ÷ ip µØµã 172.17.0.2 ÉèÖÃΪÖ÷»úÃû my-host£¬ÔòÔÚ /etc/hosts ÎļþÖÐÌí¼Ó 172.17.0.2 my-host¡£
ÔÚ Docker ÖÐÉèÖÃÖ÷»ú
ÎÊÌ⣺ÔõÑùÔÚ Docker ÈÝÆ÷ÖÐÉèÖÃÖ÷»ú£¿
»Ø¸²£ºÎª Docker ÈÝÆ÷ÉèÖÃÖ÷»úÉæ¼°ÐÞ¸ÄËÞÖ÷»úÉ쵀 /etc/hosts Îļþ¡£
°ì·¨£º
È·¶¨Ä¿µÄÈÝÆ÷ IP µØµã£ºÔËÐÐ docker inspect my-container ÏÂÁÆäÖÐ my-container ÊÇÈÝÆ÷µÄÃû³Æ¡£ÔÚ “NetworkSettings” ²¿·ÖÏ£¬ÕÒµ½ÈÝÆ÷µÄ IPv4 µØµã¡£
±à¼ hosts Îļþ£ºÊ¹ÓÃÎı¾±à¼Æ÷£¨Èç nano »ò vi£©±à¼ËÞÖ÷»úµÄ /etc/hosts Îļþ¡£
Ìí¼ÓÖ÷»ú¼Í¼£ºÔÚÎļþÖÐÌí¼ÓÒ»ÐУ¬ÃûÌÃΪ£º
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
172.17.0.2 my-host
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÉúÑIJ¢Í˳ö hosts Îļþ¡£
ʾÀý£º
¼ÙÉèÄãÏ뽫ÈÝÆ÷ my-container µÄ IP µØµã 172.17.0.2 ÉèÖÃΪÖ÷»úÃû my-host£¬Äã¿ÉÒÔ×ñÕÕÒÔÏ°취£º
ÔËÐÐ docker inspect my-container ÏÂÁî²¢¼ÇÏ IP µØµã¡£
ʹÓà sudo nano /etc/hosts ·¿ª /etc/hosts Îļþ¡£
Ìí¼ÓÒ»ÐУº
172.17.0.2 my-host
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
°´ Ctrl + X ÉúÑIJ¢Í˳öÎļþ¡£
ÏÖÔÚ£¬ÄãµÄ Docker ÈÝÆ÷¿ÉÒÔ»á¼ûÖ÷»úÃûΪ my-host µÄÖ÷»ú¡£
ÒÔÉϾÍÊÇdockerÔõôÉèÖÃhostµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡