Thuta Learning
Docker
BasicDevOps & Toolsintermediate

docker run

docker run သည် image တစ်ခုကိုအခြေခံပြီး container အသစ်တစ်ခု create + start လုပ်ပေးတဲ့ command ဖြစ်ပါတယ်။ Docker ကိုနေ့စဉ်သုံးရင် အများဆုံးတွေ့ရမယ့် command လည်းဖြစ်ပါတယ်။

အသုံးများသော options

• -d — background မှာ run

• -p — host port နဲ့ container port ချိတ်

• --name — container ကိုနာမည်ပေး

• -e — environment variable ထည့်

• --rm — container ပြီးသွားတာနဲ့ auto remove

dockerfile
# Run Alpine Linux and print a message
# --rm removes the container after the command finishes
docker run --rm alpine echo "hello from docker"

# Run Nginx in the background with a name
docker run --name web-demo -d -p 8080:80 nginx

ပထမ command က Alpine Linux image ကိုသုံးပြီး message တစ်ကြောင်း print လုပ်ပါတယ်။ Task ပြီးတာနဲ့ --rm ကြောင့် container ကိုဖျက်သွားပါမယ်။ ဒုတိယ command က Nginx web server ကို background မှာ run လုပ်ပြီး web-demo ဆိုတဲ့ name ပေးပါတယ်။

You should see
Terminal တွင် hello from docker ပေါ်လာမည်။ Nginx command အတွက် browser မှာ localhost:8080 ဖွင့်နိုင်မည်။

Info

Container name ကိုပေးထားရင် နောက်ပိုင်း docker stop web-demo လို command တွေမှာ container ID အရှည်ကြီးမရေးရတော့ပါ။

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

  • နာမည်တူ container ရှိပြီးသားဆိုရင် name conflict error ပေါ်ပါမယ်။ အရင် container ကို docker rm လုပ်ပါ သို့မဟုတ် name အသစ်ပေးပါ။
docker run | Thuta Learning