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 nginx8080: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 လုပ်ပါ။