လန်ဒိုမိတ်ဆက်

Lando: Exploring the Simplicity of Lando as a Docker Alternative

Myo Win Thein
3 min readMar 30, 2022

Intro

Lando က တကယ်တော့ Docker လည်းသုံးချင်တယ်၊ ဒါပေမယ့် Dockerfile တွေရေးရမှာလည်းပျင်းတယ်ဆိုတဲ့ developer တွေကို target ထားတဲ့ tool တစ်ခုပါ။ သူ့ဆီမှာ popular framework & CMS ပေါင်းစုံအတွက် ကြိုရေးပြီးသား docker-compose.yml တွေရှိတယ်။ ကိုယ့် app က ဘာနဲ့ရေးထားလဲ configure လုပ်လိုက်ရင် မိနစ်ပိုင်းနဲ့ project တစ်ခုလုံး container ပေါ်ရောက်ပြီးသားပဲ။

Installation

Docker နဲ့ Docker-Compose တော့ ကြိုသွင်းထားဖို့လိုတယ်။ တစ်ခုရှိတာက Linux အတွက်ဆို docker.io လို repository က သွင်းတာမျိုးဆို ပြဿနာတက်တယ်။ Official docker page က instruction အတိုင်းသွင်းမှ ရတယ်။ Lando installation က ဒီမှာ ကြည့်လို့ရတယ်။

အားလုံးပြီးရင် project root အောက်မှာ landofile တစ်ခု create လုပ်ရုံပဲ။

lando init

Configuration

အဓိကအားဖြင့် name, recipe, config, services & tooling ဆိုတဲ့ essential top level config ၅ခုရှိတယ်။

1. Name

docker-compose.yml ရဲ့ container_name နဲ့တူတူပဲ။ Lando နဲ့ compose file တွေဆောက်တဲ့အခါ အဲဒိ value လေး pass ပေးလိုက်တာပဲ။ မထည့်လည်းရတယ်၊ ဘာမှမဖြစ်။

name: my-backend-project

2. Recipe

ဒီနေရာက Lando တစ်ခုလုံးရဲ့ အသက်ပဲ။ Supported frameworks & CMS တွေ ဒီမှာ ကြည့်ပြီး ကိုယ်သုံးချင်တာလေး နာမည်ရေးလိုက်ရုံပဲ။ အဓိကတော့ Lando run တဲ့အခါ သက်ဆိုင်ရာ docker-compose.yml တွေကို execute လုပ်ပေးသွားတာပဲ။ ကိုယ့်ဘာသာ custom compose file ရေးပြီး ချိတ်သုံးလည်းရတယ်။

recipe: laravel

3. Config

Recipe တစ်ခုချင်းဆီမှာ config လေးတွေကိုယ်စီရှိတယ်။ ဥပမာ Laravel ဆို php & composer version ပြောင်းတာ၊ web & cache server ရွေးတာ၊ webroot ပြောင်းတာ စသည် supported ပေးသလောက် စိတ်ကြိုက်ချိန်လို့ရတယ်။

config:
php: '8.0'
composer_version: 2-latest
via: nginx:1.18
webroot: public
database: postgres:14
cache: redis:6

အဲဒိက tools တွေဆိုရင် docker hub ကနေ သွားဆွဲတာ။ webroot လို property တွေဆို docker-compose.yml ရဲ့ volumes ထဲကို သွားထည့်လိုက်တာပဲ။ ဆိုလိုတာက manual ဘာတစ်ခုမှ လုပ်စရာမလိုပဲ Lando ကနေ အကုန် automated လုပ်ပေးသွားတာ။ Docker လည်း အခြေခံလောက် နားလည်ရင်ရပြီ။

4. Services

Recipe တစ်ခုမှာ သူနဲ့ချိတ်ထားတဲ့ tool ပေါင်းစုံရှိတယ်။ Services က အဲဒိတစ်ခုချင်းစီကို detail configure လုပ်ရင်သုံးတာ။ တကယ်တော့ စောနက config ဆိုတာက services ထဲက အသုံးများတဲ့ဟာတွေကို parent level မှာ ပြန်စုပေးထားတာပဲ။

Nginx ဆိုရင် custom conf တွေ import လုပ်လို့ရတယ်၊ port တွေပြောင်းလို့ရမယ်။ ဘယ်လောက်ထိလဲဆို default docker-compose.yml ထဲက settings တွေကို ဒီမှာရေးပြီး override လုပ်လို့ရတယ်။ ဒီနေရာကတော့ .lando.yml file မှာ အရှုပ်ဆုံးအပိုင်းပဲ။ ပြီးတော့ Docker ကျွမ်းလေ ကလိလို့ကောင်းလေပဲ။

services:
appserver:
type: php
run:
- nohup php artisan queue:work > /dev/null 2>&1 &
database:
type: postgres
portforward: 32848
node:
type: node:16
overrides:
ports:
- 3002:3002

5. Tooling

ဒီဟာက docker-exec -it [container] [cmd]ကို wrap လုပ်ထားတဲ့ကောင်ပါ။ တစ်ခုခုဆို စာအရှည်ကြီး ရိုက်စရာမလိုတော့ဘူးပေါ့။ Recipeတိုင်းမှာ default ပါတဲ့ cmd တွေရှိတယ်၊ Laravel ကို နမူနာကြည့်ရအောင်။

lando artisan [method]
lando composer [method]
lando db-export [file]
lando db-import [file]
lando laravel [method]

Customized cmd တွေလည်းရေးလို့ရသေးတယ်။ ခုနေ နည်းနည်းရှုပ်သလိုရှိပေမယ့် Lando docs ဖတ်လိုက်ရင် အသေးစိတ်သဘောပေါက်သွားလိမ့်မယ်။

tooling:
phpunit:
service: appserver
description: "Run PHP Unit tests: lando phpunit"
cmd: /app/vendor/bin/phpunit

lando phpunit [method]

Using Command Lines

.lando.yml တစ်ခု စိတ်ကြိုက်ဆောက်ပြီးရင်တော့ default cli တွေသုံးပြီး execute လုပ်ရုံပဲ။ တကယ်တော့ lando cli အများစုကလည်း docker cli တွေကို wrap လုပ်ထားတဲ့ကောင်တွေပါပဲ။ ဒါတွေကတော့ အသုံးအများဆုံး cmd တွေပါ။

lando start        Build & run a container
lando rebuild Reload existing container with new configuration
lando destroy Remove a container
lando logs -t -f Check container logs
lando info Check container information

Conclusion

Lando ဆိုတာ တကယ်တော့ Docker ရဲ့ abstract layer တစ်ခုပါပဲ။ စောက်ပျင်းကြီးတဲ့ developer တွေအတွက် docker container တစ်ခုကို မိနစ်ပိုင်းနဲ့ အစအဆုံး ဆောက်လို့ရအောင် လုပ်ပေးထားတာ။

တစ်ခုသတိထားရမှာက Lando ကို production server မှာ သုံးလို့ရပေမယ့် localhost မှာပဲ internal team သီးသန့်သုံးဖို့ပါ။ Docs ဖတ်တဲ့အခါ အဲဒိကိစ္စကို နေရာပေါင်းစုံမှာ ထပ်ကာထပ်ကာ သတိပေးထားတာကို တွေ့ပါလိမ့်မယ်။

They are begging not to use Lando in production again & again

--

--

Myo Win Thein

A developer sharing experiences with the world, one byte at a time.