Dockerfile
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
Dockerfile ဆိုတာ နာမည်အတိုင်းပဲ file တစ်ခုပါပဲ။ သူ့ဆီမှာ တိကျတဲ့ instructions တွေပါမယ် အဲ့ instructions တွေနဲ့ ကိုယ်လိုချင်တဲ့ customized images တွေကို build လုပ်ပါတယ် Default အနေနဲ့တော့ နာမည်ကို Dockerfile လို့ တဝေမသိမ်းပေးရပါမယ်။
$ docker build -t image_name .
ဒါကတော့ ရေးပြီးသား dockerfile နဲ့ image build လုပ်တဲ့ command ပါ။ -t
ဆိုတာ tag name ကိုကိုယ်စားပြုပါတယ် သူ့အနောက်မှာ image name လိုက်ပါတယ် သေချာကြည့်ပါ command အဆုံးမှာ ( . )
ပါပါတယ် သူက current working directory မှာ ရှိတဲ့ Dockerfile ကိုယူပြီးသုံးမယ်လို့ ဆိုလိုတာပါ အကယ်၍ ခင်ဗျားမှာသာ Dockerfile တစ်ခုမက ရှိနေရင် သို့မဟုတ် Dockerfile မှာ နာမည်အစ D ကသာ small letter (d) ဖြစ်နေခဲ့မယ်ဆိုရင် error တက်နိုင်ပါတယ်။
$ docker build -t image_name -f /path/to/Dockerfile
ဒီ command ကလဲ image build တဲ့ command ပါပဲ။ ထူးခြားတာကတော့ -f
flag ကိုသုံးထားတာပါ။ Current working directory ထဲကမဟုတ်ပဲ ခင်ဗျားရဲ့ file system ထဲက တစ်နေရာရာမှာ ရှိတဲ့ Dockerfile ကို ခေါ်သုံးချင်ရင် ဒီလို သုံးရပါမယ်။
ဒီနေရာမှာ အစမ်းအနေနဲ့ Github ပေါ်က sample project ကိုယူသုံးပါ့မယ်။
$ git clone https://github.com/tecrahul/dockerfile
$ cd dockerfile
$ docker build -t apacheimage .
အပေါ်က command သုံးကြောင်းပြီးရင် image တစ်ခုဆောက်ပြီးပါပြီ ဆောက်ပြီးသား images တွေကို docker images ဆိုတဲ့ command နဲ့ခေါ်ကြည့်နိုင်ပါတယ်။
$ docker run -it -p 8080:80 apacheimage
ဒီcommand နဲ့ ဆောက်ပြီးသား image ကိုသုံးပြီး container တစ်ခုတည်ဆောက်ပါတယ်။ i
က interactive နဲ့ t
က tty ကို ကိုယ်စားပြုပါတယ်။ -p
ဆိုတာကတော့ port သတ်မှတ်ပေးတာပါ။ ဒီ ဥပမာမှာဆို ကိုယ့် host system ရဲ့ port 8080 နဲ့ container ရဲ့ port 80ကို ချိတ်ပေးဖို့ သုံးထားတာကို တွေ့ရမှာပါ။ အရှေ့က ကိုယ့် host systemရဲ့ port နဲ့ အနောက်က container ရဲ့ portကြားမှာ colon ( : )
ကိုရေးရမှာပါ။