-
Notifications
You must be signed in to change notification settings - Fork 76
API Deployment Examples
Comprehensive examples for deploying containers and stacks via the DockMon REST API.
See API Access for authentication setup and basic API usage.
| Endpoint | Method | Purpose |
|---|---|---|
/api/deployments |
POST | Create a deployment (planning state) |
/api/deployments/{id}/execute |
POST | Execute a deployment |
/api/deployments/{id} |
GET | Get deployment status |
/api/deployments |
GET | List all deployments |
/api/deployments/{id} |
DELETE | Delete a deployment |
Two-step process:
-
Create deployment → Status:
planning(validates but doesn't deploy) -
Execute deployment → Status:
executing→running(deploys containers)
Why two steps?
- Review deployment before execution
- Catch validation errors early
- Support scheduled deployments (future feature)
Deploy a simple nginx + redis stack:
Step 1: Create deployment
curl -X POST https://dockmon.local:8001/api/deployments \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"host_id": "your-host-id-here",
"name": "nginx-redis-stack",
"deployment_type": "stack",
"definition": {
"compose_yaml": "services:\n web:\n image: nginx:alpine\n ports:\n - \"8080:80\"\n cache:\n image: redis:alpine"
},
"rollback_on_failure": true
}'Step 2: Execute deployment
# Use deployment ID from create response
curl -X POST https://dockmon.local:8001/api/deployments/DEPLOYMENT_ID/execute \
-H "Authorization: Bearer YOUR_API_KEY"Use variables for flexible deployments:
{
"host_id": "your-host-id",
"name": "webapp-stack",
"deployment_type": "stack",
"definition": {
"compose_yaml": "services:\n app:\n image: ${APP_IMAGE}\n ports:\n - \"${APP_PORT}:8080\"\n environment:\n - DB_HOST=${DB_HOST}",
"variables": {
"APP_IMAGE": "myapp:1.0",
"APP_PORT": "3000",
"DB_HOST": "postgres.local"
}
}
}Complete Plex + Tautulli stack with GPU transcoding:
{
"host_id": "your-host-id",
"name": "media-server",
"deployment_type": "stack",
"definition": {
"compose_yaml": "services:\n plex:\n image: plexinc/pms-docker:latest\n container_name: plex\n network_mode: host\n devices:\n - /dev/dri:/dev/dri:rwm\n environment:\n - PLEX_UID=1000\n - PLEX_GID=1000\n - TZ=America/New_York\n volumes:\n - /data/plex:/config\n - /data/media:/media\n\n tautulli:\n image: ghcr.io/tautulli/tautulli:latest\n container_name: tautulli\n ports:\n - \"8181:8181\"\n environment:\n - TZ=America/New_York\n volumes:\n - /data/tautulli:/config"
}
}Note: Use \n for newlines in the compose_yaml string (JSON requirement).
Gluetun VPN with qBittorrent using network sharing:
{
"host_id": "your-host-id",
"name": "vpn-torrent",
"deployment_type": "stack",
"definition": {
"compose_yaml": "services:\n gluetun:\n image: qmcgaw/gluetun:latest\n container_name: gluetun\n cap_add:\n - NET_ADMIN\n environment:\n - VPN_SERVICE_PROVIDER=protonvpn\n - OPENVPN_USER=${VPN_USER}\n - OPENVPN_PASSWORD=${VPN_PASS}\n ports:\n - \"8080:8080\"\n\n qbittorrent:\n image: linuxserver/qbittorrent:latest\n container_name: qbittorrent\n network_mode: \"service:gluetun\"\n environment:\n - PUID=1000\n - PGID=1000\n volumes:\n - /data/qbittorrent:/config\n - /data/downloads:/downloads",
"variables": {
"VPN_USER": "your-vpn-username",
"VPN_PASS": "your-vpn-password"
}
}
}DockMon supports these Docker Compose directives:
services:
vpn:
image: qmcgaw/gluetun
network_mode: host # or: bridge, none, container:other_containerJSON format:
{
"compose_yaml": "services:\n vpn:\n image: qmcgaw/gluetun\n network_mode: host"
}services:
plex:
image: plexinc/pms-docker
devices:
- /dev/dri:/dev/dri:rwm # GPU for transcodingJSON format:
{
"compose_yaml": "services:\n plex:\n image: plexinc/pms-docker\n devices:\n - /dev/dri:/dev/dri:rwm"
}services:
app:
image: myapp
extra_hosts:
- "db.local:192.168.1.100"
- "api.local:192.168.1.200"JSON format:
{
"compose_yaml": "services:\n app:\n image: myapp\n extra_hosts:\n - db.local:192.168.1.100\n - api.local:192.168.1.200"
}services:
vpn:
image: qmcgaw/gluetun
cap_add:
- NET_ADMIN # Required for VPNJSON format:
{
"compose_yaml": "services:\n vpn:\n image: qmcgaw/gluetun\n cap_add:\n - NET_ADMIN"
}You need a host ID to deploy. Get the list:
curl https://dockmon.local:8001/api/hosts \
-H "Authorization: Bearer YOUR_API_KEY"Response:
[
{
"id": "86a10392-2289-409f-899d-5f5c799086da",
"name": "Local Docker",
"url": "unix:///var/run/docker.sock",
"status": "online"
}
]Use the id field in your deployment requests.
curl https://dockmon.local:8001/api/deployments/DEPLOYMENT_ID \
-H "Authorization: Bearer YOUR_API_KEY"Response:
{
"id": "86a10392-...:c7d9d8f1b890",
"name": "nginx-redis-stack",
"status": "running",
"progress_percent": 100,
"error_message": null,
"container_ids": ["a1b2c3d4e5f6", "f6e5d4c3b2a1"]
}curl https://dockmon.local:8001/api/deployments \
-H "Authorization: Bearer YOUR_API_KEY"If your compose file has errors:
Request:
{
"definition": {
"compose_yaml": "services:\n invalid:\n network_mode: host\n networks:\n - mynetwork"
}
}Response (400 Bad Request):
{
"detail": "Compose validation failed: Service 'invalid': Cannot use both 'network_mode' and 'networks'. These options are mutually exclusive."
}| Error | Cause | Fix |
|---|---|---|
Missing required field: services |
Invalid compose YAML | Ensure compose_yaml has services: section |
Cannot use both 'network_mode' and 'networks' |
Conflicting directives | Remove either network_mode or networks
|
Stack deployment requires 'compose_yaml' |
Missing field | Add compose_yaml to definition |
Invalid port mapping |
Bad port format | Use format: "8080:80" or "127.0.0.1:8080:80"
|
- Create new request collection
- Add Authorization header to collection:
- Key:
Authorization - Value:
Bearer YOUR_API_KEY
- Key:
- Set base URL:
https://dockmon.local:8001 - Disable SSL verification (Settings → SSL certificate verification → OFF)
Create Stack:
- Method:
POST - URL:
{{base_url}}/api/deployments - Body: See examples above (select "raw" + "JSON")
Execute:
- Method:
POST - URL:
{{base_url}}/api/deployments/{{deployment_id}}/execute - Body: (none)
Get Status:
- Method:
GET - URL:
{{base_url}}/api/deployments/{{deployment_id}}
Complete Python script for deploying stacks:
import requests
import time
API_KEY = "dockmon_your_api_key_here"
BASE_URL = "https://dockmon.local:8001"
HOST_ID = "your-host-id"
# Disable SSL warnings (for self-signed certs)
import urllib3
urllib3.disable_warnings()
def deploy_stack(name, compose_yaml, variables=None):
"""Deploy a Docker Compose stack via DockMon API"""
# Step 1: Create deployment
create_response = requests.post(
f"{BASE_URL}/api/deployments",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"host_id": HOST_ID,
"name": name,
"deployment_type": "stack",
"definition": {
"compose_yaml": compose_yaml,
"variables": variables or {}
},
"rollback_on_failure": True
},
verify=False
)
if create_response.status_code != 201:
print(f"Failed to create deployment: {create_response.text}")
return None
deployment = create_response.json()
deployment_id = deployment["id"]
print(f"Created deployment: {deployment_id}")
# Step 2: Execute deployment
execute_response = requests.post(
f"{BASE_URL}/api/deployments/{deployment_id}/execute",
headers={"Authorization": f"Bearer {API_KEY}"},
verify=False
)
if execute_response.status_code != 200:
print(f"Failed to execute: {execute_response.text}")
return None
print(f"Executing deployment...")
# Step 3: Wait for completion
while True:
status_response = requests.get(
f"{BASE_URL}/api/deployments/{deployment_id}",
headers={"Authorization": f"Bearer {API_KEY}"},
verify=False
)
status = status_response.json()
state = status["status"]
progress = status["progress_percent"]
print(f"Status: {state} ({progress}%)")
if state == "running":
print("✓ Deployment successful!")
return deployment_id
elif state in ["failed", "rolled_back"]:
print(f"✗ Deployment failed: {status.get('error_message')}")
return None
time.sleep(2)
# Example usage
compose_yaml = """services:
web:
image: nginx:alpine
ports:
- "8080:80"
cache:
image: redis:alpine
"""
deployment_id = deploy_stack("my-stack", compose_yaml)If you see SSL errors:
curl:
curl -k https://dockmon.local:8001/api/hosts ...
# -k flag skips SSL verificationPython:
requests.get(url, verify=False)Production: Use proper SSL certificates or add DockMon's CA to your system trust store.
Common mistake: Breaking compose_yaml across multiple lines
❌ Wrong:
{
"compose_yaml": "services:
web:
image: nginx"
}✓ Correct:
{
"compose_yaml": "services:\n web:\n image: nginx"
}Use \n for newlines, keep the string on one line.
- API Access Guide - Authentication and API key management
- Deployments Guide - Using the web UI for deployments
- Deployment Templates - Create reusable deployment templates
Full API documentation available at: https://dockmon.local:8001/docs
Interactive Swagger UI with:
- Complete endpoint list
- Request/response schemas
- Try-it-now functionality
Getting Started
User Guide
- Dashboard
- Managing Hosts
- Container Operations
- Container Tagging
- Bulk Operations
- Stacks
- Auto-Restart
- Event Viewer
- Container Logs
Configuration
- Alert Rules
- Notifications
- Blackout Windows
- Automatic Updates
- Private Registry Credentials
- Health Checks
- Settings
Remote Monitoring
Access Control
Advanced
Development
Help