จัดการ Docker ด้วย Portainer Web UI บน VPS

จัดการ Docker ด้วย Portainer Web UI บน VPS

มิถุนายน 2026 · อ่าน 6 นาที

Portainer CE คือ Web UI สำหรับจัดการ Docker ที่ทำให้เห็น containers, images, volumes และ networks ทั้งหมดในหน้าเดียว ไม่ต้องพิมพ์คำสั่ง Docker ยาวๆ ทุกครั้ง สามารถ start/stop/restart container, ดู logs, เข้า shell และ deploy stack ผ่าน browser ได้เลย

ติดตั้ง Portainer ด้วย Docker

# สร้าง volume สำหรับเก็บ Portainer data
docker volume create portainer_data

# ติดตั้ง Portainer CE
docker run -d \
  --name portainer \
  --restart unless-stopped \
  -p 8000:8000 \
  -p 9443:9443 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer-ce:latest

# ตรวจว่า run แล้ว
docker ps | grep portainer

ตั้ง Nginx Reverse Proxy ให้ Portainer

sudo nano /etc/nginx/sites-available/portainer

server {
    listen 443 ssl;
    server_name portainer.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/portainer.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/portainer.yourdomain.com/privkey.pem;

    location / {
        proxy_pass https://localhost:9443;
        proxy_ssl_verify off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
}

Login ครั้งแรกและตั้ง Admin

# เปิด https://portainer.yourdomain.com
# หรือ https://YOUR_VPS_IP:9443

# ครั้งแรกต้องตั้ง admin password ภายใน 5 นาที
# ถ้าหมดเวลา reset ด้วย:
docker exec -it portainer /bin/sh
reset-password

Deploy Stack ผ่าน Portainer

# ไปที่ Stacks > Add Stack
# ใส่ชื่อ stack และ docker-compose.yml content
# กด Deploy the stack

# ตัวอย่าง compose ที่ใส่ใน Portainer:
version: "3.8"
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/share/nginx/html
Tip: ใช้ Portainer Templates (App Templates) สำหรับ deploy apps ยอดนิยมอย่าง WordPress, Grafana, Nextcloud ได้ด้วยคลิกเดียว ไม่ต้องเขียน compose เอง

จัดการ Multiple Servers

# ติดตั้ง Portainer Agent บน server ที่ต้องการ manage
docker run -d \
  --name portainer_agent \
  --restart always \
  -p 9001:9001 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /var/lib/docker/volumes:/var/lib/docker/volumes \
  portainer/agent:latest

# เพิ่ม server ใน Portainer:
# Settings > Environments > Add environment > Agent
# ใส่ IP:9001 ของ agent server

ความปลอดภัย: จำกัดสิทธิ์และ HTTPS

Portainer คุม Docker ทั้งเครื่อง = เทียบเท่า root ถ้าหลุดคือจบ ต้องล็อกให้แน่น:

# จำกัด UI ให้เฉพาะ IP office ด้วย UFW
sudo ufw allow from 203.0.113.0/24 to any port 9443 proto tcp
sudo ufw deny 9443
Tip: ถ้าใช้ Portainer แค่ดู/จัดการเป็นครั้งคราว ปิด container ทิ้งไว้แล้วค่อย docker start portainer ตอนต้องใช้ ลด attack surface ได้มาก

ตรวจสอบว่า Portainer ทำงานถูกต้อง

# ตรวจ container
docker ps | grep portainer

# ตรวจ port
ss -tlnp | grep 9443

# ดู logs
docker logs portainer -f

# ทดสอบ API
curl -k https://localhost:9443/api/status
Tip: เปิดใช้ Portainer Edge Agent เพื่อ manage server ที่อยู่หลัง firewall โดยไม่ต้องเปิด inbound port ใดๆ เหมาะสำหรับ server ใน private network

แก้ปัญหาที่พบบ่อย

Portainer admin password reset ไม่ได้ (container ลบแล้วสร้างใหม่)

Volume portainer_data ยังเก็บ data เดิม ต้องลบ volume ด้วย:

docker stop portainer && docker rm portainer
docker volume rm portainer_data
docker volume create portainer_data
# แล้วติดตั้งใหม่

Container ใน Portainer หายไปหลัง VPS restart

Container ที่สร้างผ่าน Portainer ไม่มี restart policy ต้องตั้ง restart=unless-stopped เสมอ:

# แก้ใน Portainer: Container > Restart policies > Unless Stopped
# หรือผ่าน command:
docker update --restart unless-stopped container_name

Portainer แสดง "cannot connect to Docker daemon"

Docker socket path ไม่ถูกหรือ permission ผิด:

ls -la /var/run/docker.sock
# ถ้าไม่มี socket ตรวจ Docker service
sudo systemctl status docker
sudo systemctl start docker

คำถามที่พบบ่อย

Portainer CE ฟรีหรือไม่?

Portainer CE (Community Edition) ฟรีสมบูรณ์ รองรับ Docker standalone และ Docker Swarm Portainer Business (มีค่าใช้จ่าย) เพิ่ม LDAP, RBAC และ audit log สำหรับองค์กรใหญ่

Portainer รองรับ Kubernetes ไหม?

Portainer Business รองรับ Kubernetes แบบ full support Portainer CE รองรับ Kubernetes แบบ basic จัดการ namespaces, deployments และ services ได้ผ่าน Web UI แต่ features น้อยกว่า

Portainer ปลอดภัยไหม? ควรเปิด port สาธารณะไหม?

ควร protect ด้วย Nginx + SSL และไม่เปิด port 9443 โดยตรง ถ้าใช้คนเดียวแนะนำให้เข้าผ่าน SSH tunnel แทน: ssh -L 9443:localhost:9443 user@vps