Thuta Learning
Docker
IntermediateDevOps & Toolsအလယ်အလတ်

Port Mapping

Dockerသင်ခန်းစာ 12

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 ဆိုတာမှတ်ထားပါ။

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Port Mapping | Thuta Learning