ทุกคำสั่งและพารามิเตอร์ของ th container อยู่ในคู่มืออ้างอิง CLI
ติดตั้งและเข้าสู่ระบบ
# Linux, macOS
curl -fsSL https://raw.githubusercontent.com/mrzack99s/thailandhosting-cli/main/install.sh | sh
# Windows (PowerShell)
irm https://raw.githubusercontent.com/mrzack99s/thailandhosting-cli/main/install.ps1 | iex
# or with Go 1.23+
go install github.com/mrzack99s/thailandhosting-cli/cmd/th@latestth auth login จะเปิด Console ให้ตรวจว่ารหัสตรงกับใน terminal แล้วกด อนุญาต การเข้าสู่ระบบนี้ใช้ได้ 90 วัน และแสดงใน บัญชี → อุปกรณ์ที่เข้าสู่ระบบ ซึ่งออกจากระบบได้จากที่นั่น
th auth login # opens the Console to approve
th config set project my-project # optional: the CLI picks your first Project
th container deploy api --source . # build this folder and deploy it--source ทำอะไรบ้าง
- CLI แพ็กโฟลเดอร์ โดยตัดไฟล์ที่อยู่ใน
.thignore,.dockerignoreหรือ.gitignore(รวมถึง.gitและnode_modules) ขนาดไม่เกิน 100 MB - ระบบ build ให้ ถ้ามี
Dockerfileจะใช้ไฟล์นั้น ถ้าไม่มีจะเขียนให้สำหรับ Node.js (package.json), Python (requirements.txtหรือpyproject.toml) หรือ Go (go.mod) และแสดงใน log ให้คัดลอกไปปรับได้ log จะไหลมาที่ terminal ของคุณ - image ถูกเก็บใน Registry ของ Project และ deploy เป็น Revision ใหม่ ครั้งแรกจะสร้าง Container ให้ ครั้งต่อไปคงการตั้งค่าเดิมไว้ เปลี่ยนเฉพาะที่คุณระบุ
กด Ctrl+C ระหว่าง build ได้ Build ยังทำต่อที่ฝั่งเรา ดูต่อด้วย th builds log <id> --follow
Deploy จาก image ปรับการตั้งค่า และย้อน Revision
th container deploy api --image ghcr.io/acme/api:1.4 --port 3000 \
--cpu 1 --memory 512Mi --min-instances 0 --max-instances 5 \
--set-env-vars NODE_ENV=production --secret-env API_KEY=xxxxth container services list
th container services describe api
th container services logs api --lines 200
th container revisions list --service api
th container services update-traffic api --to-revision 3 # roll back
th container images list api # images and what keeps them
th container images delete api:old-tag
th builds list
th builds log <build-id> --followimage ที่ build หรือ push อยู่ที่ registry.thailandhosting.com/<project>/<name> จะ push ด้วย Docker เองก็ได้:
th auth configure-docker # docker login to our registry
docker build -t registry.thailandhosting.com/my-project/api:1.4 .
docker push registry.thailandhosting.com/my-project/api:1.4
th container deploy api --image registry.thailandhosting.com/my-project/api:1.4Registry เก็บ image ไว้ให้ 10 Revision ล่าสุดของแต่ละ Container (Revision ที่เก่ากว่านั้นย้อนกลับไม่ได้หลังผ่านไป 7 วัน) และ image ที่ติด tag ไว้ แต่ละ Project ได้ 20 GB และจะได้อีเมลเตือนเมื่อใช้ถึง 80% ดูและลบ image ได้ด้วย th container images list / th container images delete หรือการ์ด Registry ในหน้า Container
Deploy จาก GitHub Actions หรือ CI อื่น
ใน Console เปิด Integrations → API keys สร้าง Key ที่มีสิทธิ์ Containers: deploy (run:write) Key นี้ใช้ได้เฉพาะ Container, Build และ Registry ของ Project ของมัน เก็บไว้เป็น secret ชื่อ TH_API_KEY
# .github/workflows/deploy.yml
on: { push: { branches: [main] } }
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with: { go-version: '1.23' }
- run: go install github.com/mrzack99s/thailandhosting-cli/cmd/th@latest
- run: th container deploy api --source .
env:
TH_API_KEY: ${{ secrets.TH_API_KEY }} # a key with the run:write scopeBuild และ Registry คิดเงินตามการใช้งาน Wallet ของ Project ต้องมียอดเงิน เครื่อง Build สร้าง image ได้สำหรับ CPU แบบเดียว ถ้าประเภทเครื่องของ Container ใช้อีกแบบ ให้ build เองด้วย docker buildx --platform แล้ว deploy ด้วย --image
ถ้าเจอปัญหา
ขึ้นว่า “ไม่พบ Dockerfile และไม่รู้จักชนิดโปรเจกต์”
เพิ่ม Dockerfile ที่ชั้นบนสุดของโฟลเดอร์ หรือสั่ง deploy จากโฟลเดอร์ที่มี package.json, go.mod หรือ requirements.txt
Build จบด้วย exit code 137
Build ใช้หน่วยความจำเกิน ลดงานตอน build หรือ build image เองแล้ว deploy ด้วย --image
CLI ขึ้นว่า “Token ไม่ถูกต้องหรือหมดอายุ”
สั่ง th auth login ใหม่ ถ้าเป็น CI ให้ตรวจว่า API Key มีสิทธิ์ run:write และยังไม่หมดอายุ