Thuta Learning
ရှာဖွေရန်
IntermediateDevOps & Toolsintermediate

Port Mapping

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Port Mapping ဆိုတာ container ထဲက service port ကို host machine ပေါ်က port တစ်ခုနဲ့ချိတ်ပေးတာပါ။ Container ထဲမှာ web server က port 80 နဲ့ run နေပေမယ့် host browser ကနေဝင်ဖို့ host port တစ်ခုကို publish လုပ်ရပါတယ်။

dockerfile
# Syntax
# docker run -p HOST_PORT:CONTAINER_PORT image_name

# Example: open Nginx through localhost:8080
docker run --name nginx-port-demo -d -p 8080:80 nginx

8080:80 မှာ ဘယ်ဘက်က 8080 သည် သင့် computer ပေါ်က port ဖြစ်ပြီး ညာဘက်က 80 သည် container ထဲက Nginx port ဖြစ်ပါတယ်။

You should see
http://localhost:8080 တွင် Nginx page ပေါ်လာပါမယ်။

Info

Host port တစ်ခုကို container တစ်ခုထက်ပိုပြီး တစ်ချိန်တည်းအသုံးမပြုနိုင်ပါ။ Port already allocated error ပေါ်ရင် port ပြောင်းပါ သို့မဟုတ် container ဟောင်းကို stop လုပ်ပါ။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • -p 80:8080 လို host/container port အစီအစဉ်ကိုပြောင်းရေးမိရင် app မပေါ်နိုင်ပါ။ Syntax က host:container ဆိုတာမှတ်ထားပါ။
Port Mapping | Thuta Learning