Stacks and templates
Chapter objectives
- Deploy Docker Compose stacks
- Use application templates
- Create custom templates
- Manage deployments
1 - What is a Stack?
Definition
A stack in Portainer is a set of services deployed together, defined by a Docker Compose file.
┌─────────────────────────────────────────────────────────────────┐
│ Stack "wordpress" │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ wordpress │ ────▶ │ mysql │ │
│ │ :8080 │ │ :3306 │ │
│ └─────────────┘ └─────────────┘ │
│ │ │
│ ┌──────▼──────┐ │
│ │ Volume │ │
│ │ mysql_data │ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────── ──────────────────────┘
Advantages
| Advantage | Description |
|---|---|
| Simplicity | One deployment = multiple containers |
| Consistency | Version-controlled compose file |
| Management | Start/stop everything together |
| Reproducibility | Same configuration every time |
2 - Create a stack
Creation interface
┌─────────────────────────────────────────────────────────────────┐
│ + Add Stack │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Name: [my-wordpress ] │
│ │
│ Build method: │
│ (•) Web editor │
│ ( ) Upload │
│ ( ) Repository │
│ ( ) Custom template │
│ │
└─────────────────────────────────────────────────────────────────┘
Creation methods
| Method | Description |
|---|---|
| Web editor | Write the compose directly |
| Upload | Upload a .yml file |
| Repository | Clone from Git |
| Custom template | Use an existing template |
Stack editor
┌─────────────────────────────────────────────────────────────────┐
│ Web editor │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ version: "3.9" │ │
│ │ │ │
│ │ services: │ │
│ │ wordpress: │ │
│ │ image: wordpress:latest │ │
│ │ ports: │ │
│ │ - "8080:80" │ │
│ │ environment: │ │
│ │ WORDPRESS_DB_HOST: db │ │
│ │ WORDPRESS_DB_USER: wordpress │ │
│ │ WORDPRESS_DB_PASSWORD: ${DB_PASSWORD} │ │
│ │ WORDPRESS_DB_NAME: wordpress │ │
│ │ depends_on: │ │
│ │ - db │ │
│ │ │ │
│ │ db: │ │
│ │ image: mysql:8 │ │
│ │ environment: │ │
│ │ MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} │ │
│ │ MYSQL_DATABASE: wordpress │ │
│ │ MYSQL_USER: wordpress │ │
│ │ MYSQL_PASSWORD: ${DB_PASSWORD} │ │
│ │ volumes: │ │
│ │ - db_data:/var/lib/mysql │ │
│ │ │ │
│ │ volumes: │ │
│ │ db_data: │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Environment variables: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ [DB_PASSWORD ] = [secret123 ] [+ Add] │ │
│ │ [DB_ROOT_PASSWORD] = [rootsecret ] │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ [Deploy the stack] │
│ │
└─────────────────────────────────────────────────────────────────┘
3 - Manage stacks
List of stacks
┌─────────────────────────────────────────────────────────────────┐
│ 📚 Stacks [+ Add stack] │
├─────────────────────────────────────────────────────────────────┤