Sadarwa a cikin Docker: Haɗawa da Sarrafa hanyoyin sadarwa a ciki Docker

Sadarwar sadarwa wani muhimmin al'amari ne na Docker wanda ke ba da damar container  sadarwa tare da juna da kuma hanyar sadarwar waje. Anan akwai cikakken jagora kan yadda ake haɗawa da sarrafa cibiyoyin sadarwa a cikin Docker:

Default Bridge Network

Docker yana ba da tsohuwar hanyar sadarwa da ake kira bridge don container. Lokacin ƙirƙirar container ba tare da ƙayyade hanyar sadarwa ba, yana haɗa kai tsaye zuwa tsohuwar bridge hanyar sadarwa.

Container s a kan bridge hanyar sadarwa guda ɗaya suna iya sadarwa tare da juna ta amfani da adiresoshin IP na ciki. Docker yana ba da ƙudurin DNS don ba da damar container sadarwa ta sunayen yanki.

Container Hadawa

Ta amfani da --link zaɓin, zaku iya haɗa juna container da juna, ba da damar sadarwa a tsakanin su ta hanyar amfani da container suna ko mahalli masu alaƙa.

Misali, lokacin gudanar da container hoto mai suna webapp, zaku iya haɗa shi zuwa MySQL container mai suna mysql tare da umarni mai zuwa: docker run --name webapp --link mysql:mysql webapp-image

Hanyoyin Sadarwar Sadarwa

Kuna iya ƙirƙirar cibiyoyin sadarwa na al'ada a ciki Docker don ba da damar container s a cikin hanyar sadarwa ɗaya don sadarwa.

Yi amfani da docker network create umarnin don ƙirƙirar hanyar sadarwa ta al'ada. Misali, don ƙirƙirar cibiyar sadarwa mai suna my-network, zaku iya amfani da umarnin: docker network create my-network

Haɗa Container zuwa Hanyoyin Sadarwar Sadarwa

Lokacin ƙirƙirar container, yi amfani da --network zaɓi don haɗawa container zuwa cibiyar sadarwa ta al'ada.

Misali, don haɗa a container zuwa cibiyar sadarwar "my-network", zaku iya amfani da umarnin: docker run --network my-network my-image

Haɗa Container zuwa Cibiyar Sadarwar Mai watsa shiri

Yi amfani da --publish ko --publish-all zaɓuɓɓuka don haɗa container tashoshin jiragen ruwa zuwa tashar jiragen ruwa akan na'ura mai ɗaukar nauyi ko zuwa tashar jiragen ruwa bazuwar kan mai watsa shiri.

Misali, don haɗa tashar jiragen ruwa 80 na a container zuwa tashar jiragen ruwa 8080 akan mai watsa shiri, zaku iya amfani da umarnin: docker run -p 8080:80 my-image

 

Ta amfani da fasalulluka na hanyar sadarwa a cikin Docker, zaku iya sarrafa haɗin kai da sadarwa tsakanin container  da cibiyoyin sadarwa a cikin mahallin ku Docker. Wannan yana ba da yanayi mai sassauƙa da ma'auni don aikace-aikacenku, yana ba da damar components yin container  hulɗa tare da juna da kuma hanyar sadarwar waje ba tare da matsala ba.