-
-
Notifications
You must be signed in to change notification settings - Fork 2
DESTROY
Deprecated:
nself destroyis a compatibility wrapper. Usenself infra destroyinstead. This stub will be removed in v1.0.0.
Command: nself infra destroy (was: nself destroy)
Safe destruction of project infrastructure with configurable scope and comprehensive safety features.
The destroy command provides a controlled way to tear down nself infrastructure with multiple safety mechanisms, selective destruction options, and intelligent cleanup.
- Multi-Level Safety: Double confirmation for data destruction
- Selective Destruction: Target specific resources (containers, volumes, networks, files)
- Dry Run Mode: Preview destruction without executing
- Force Mode: Non-interactive destruction for automation
- Intelligent Cleanup: Removes Docker resources and generated files
- Data Preservation: Option to keep volumes while removing other resources
- Detailed Reporting: Shows exactly what will be destroyed
# Interactive destruction (safest)
nself destroy
# Preview what will be destroyed
nself destroy --dry-run
# Destroy but preserve data volumes
nself destroy --keep-volumes
# Only remove containers
nself destroy --containers-only
# Only remove generated files
nself destroy --generated-only
# Non-interactive (for scripts)
nself destroy --forcenself destroy [OPTIONS]| Option | Description |
|---|---|
-f, --force |
Skip all confirmation prompts (DANGEROUS) |
-y, --yes |
Auto-confirm (same as --force) |
--dry-run |
Show what would be destroyed without executing |
--keep-volumes |
Preserve data volumes (keep databases, files, etc.) |
--containers-only |
Only remove Docker containers |
--volumes-only |
Only remove Docker volumes (requires confirmation) |
--networks-only |
Only remove Docker networks |
--generated-only |
Only remove generated files (docker-compose.yml, etc.) |
--verbose |
Show detailed output |
-h, --help |
Show help message |
Docker Resources:
- ✗ All Docker containers (running and stopped)
- ✗ All Docker volumes (databases, files, cache) - DATA LOSS!
- ✗ All Docker networks
Generated Files:
- ✗
docker-compose.yml - ✗
nginx/directory - ✗
services/directory (custom services) - ✗
monitoring/directory (if exists) - ✗
ssl/directory (if exists) - ✗
postgres/directory (init scripts) - ✗
.env.runtime
Configuration:
- ✓
.envfiles (all variants) - ✓
.env.dev,.env.staging,.env.prod - ✓
.env.secrets
Code:
- ✓ Source code and custom files
- ✓ Version control (
.git/) - ✓ Node modules and dependencies
nself destroyOutput:
╔════════════════════════════════════════════════════════════════╗
║ nself destroy ║
║ Safe destruction of project infrastructure ║
╚════════════════════════════════════════════════════════════════╝
Destruction Plan:
✗ 25 containers (24 running, 1 stopped)
✗ 8 volumes (ALL DATA WILL BE LOST)
✗ 2 networks
✗ Generated files:
- docker-compose.yml
- nginx/ directory
- services/ directory (custom services)
- monitoring/ directory (if exists)
- ssl/ directory (if exists)
Preserved:
✓ .env files (configuration)
✓ Source code and custom files
WARNING: This will permanently delete all data!
This includes:
- PostgreSQL databases
- Redis cache data
- MinIO stored files
- All other persistent data
Are you sure you want to destroy project 'myapp'? (yes/no): yes
FINAL WARNING: Type the project name 'myapp' to confirm: myapp
→ Beginning destruction sequence...
✓ Removed 25 containers
✓ Removed 8 volumes
✓ Removed 2 networks
✓ Removed 7 generated files/directories
✓ Destruction complete!
✓ Project 'myapp' has been destroyed
Next steps:
nself init - Initialize a new project
nself build - Rebuild from existing .env
nself destroy --dry-runShows exactly what would be destroyed without making any changes. Perfect for:
- Understanding impact before execution
- Verifying selective destruction options
- Automation testing
nself destroy --keep-volumesRemoves containers, networks, and generated files but preserves all data volumes:
- PostgreSQL databases remain intact
- Redis data preserved
- MinIO files preserved
- Can rebuild and restart without data loss
Use case: Clean rebuild while preserving data
nself destroy --containers-onlyOnly stops and removes Docker containers. Leaves volumes, networks, and files intact.
Use case: Force restart all containers
nself destroy --volumes-onlyOnly removes Docker volumes. Requires confirmation due to data loss.
Use case: Clean data while keeping configuration
nself destroy --networks-onlyOnly removes Docker networks. Safe operation with no data loss.
Use case: Fix network conflicts
nself destroy --generated-onlyOnly removes generated files (docker-compose.yml, nginx/, services/, etc.). No Docker operations.
Use case: Force regeneration of configs via nself build
nself destroy --forceProduction Safety: Never use --force for production environments without manual review.
By default, requires explicit confirmation:
Are you sure you want to destroy project 'myapp'? (yes/no):
When destroying volumes, requires typing the project name:
FINAL WARNING: Type the project name 'myapp' to confirm:
Preview destruction without making changes:
nself destroy --dry-run- Red (✗): Items to be destroyed
- Yellow (⚠): Data loss warnings
- Green (✓): Preserved items
Use --*-only flags to limit scope:
- Reduces blast radius
- Allows targeted cleanup
- Safer for production
# 1. Destroy infrastructure but keep data
nself destroy --keep-volumes
# 2. Rebuild configuration
nself build
# 3. Start services (data intact)
nself start# 1. Only remove containers
nself destroy --containers-only
# 2. Restart services
nself start# 1. Full destruction (interactive)
nself destroy
# 2. Re-initialize
nself init
# 3. Build and start
nself build && nself start#!/bin/bash
# Automated environment teardown (with safety backup)
# 1. Backup first (safety)
nself backup create
# 2. Destroy (non-interactive)
nself destroy --force
# 3. Clean Docker system (optional)
docker system prune -af --volumesSymptom: Some containers/volumes remain after destruction
Solutions:
# 1. Force removal manually
docker ps -a | grep myapp | awk '{print $1}' | xargs docker rm -f
docker volume ls | grep myapp | awk '{print $2}' | xargs docker volume rm
# 2. Use Docker system prune
docker system prune -af --volumes
# 3. Check with verbose mode
nself destroy --verboseSymptom: Cannot remove certain files or volumes
Solutions:
# 1. Check file ownership
ls -la
# 2. Fix permissions
sudo chown -R $USER:$USER .
# 3. Use sudo for Docker operations (if needed)
sudo nself destroySymptom: "volume is in use" errors
Solutions:
# 1. Stop all containers first
nself stop
# 2. Remove containers before volumes
nself destroy --containers-only
nself destroy --volumes-only
# 3. Force Docker cleanup
docker container prune -f
docker volume prune -f# Create backup before destruction
nself backup create
nself destroy# Preview before executing
nself destroy --dry-run
# If satisfied, execute
nself destroy# Keep databases during rebuilds
nself destroy --keep-volumes# ❌ WRONG (production)
nself destroy --force
# ✓ RIGHT (production)
nself destroy # Interactive with confirmations# Step-by-step safe rebuild
nself backup create # Safety backup
nself destroy --keep-volumes # Remove infra, keep data
nself build # Regenerate configs
nself start # Restart with data intact# Backup before destruction
nself backup create
nself destroy
# If needed, rollback
nself backup restore <backup-id># Force config regeneration
nself destroy --generated-only
nself build# Graceful vs destructive
nself stop # Stops services (safe)
nself destroy # Removes everything (destructive)
nself destroy --keep-volumes # Middle ground# Different reset strategies
nself backup reset # Database only
nself destroy --volumes-only # All volumes
nself destroy # Complete teardown| Command | Containers | Volumes | Networks | Files | Data Loss |
|---|---|---|---|---|---|
nself stop |
Stops | Keeps | Keeps | Keeps | None |
nself stop --volumes |
Stops | Removes | Keeps | Keeps | Yes |
nself destroy --keep-volumes |
Removes | Keeps | Removes | Removes | None |
nself destroy |
Removes | Removes | Removes | Removes | Yes |
| Code | Meaning |
|---|---|
| 0 | Success (all resources destroyed) |
| 1 | Partial failure (some resources remain) |
| 2 | User cancelled operation |
| 3 | docker-compose.yml not found |
-
nself stop- Stop services without removal -
nself backup create- Create backup before destruction -
nself backup restore- Restore from backup after destruction -
nself build- Rebuild configuration -
nself init- Initialize new project
-
Always backup production data:
nself backup create --env prod
-
Use --keep-volumes for development:
nself destroy --keep-volumes
-
Never use --force without review:
# Review first nself destroy --dry-run # Then execute nself destroy
Before running destroy in production:
- Backup created and verified
- Team notified of downtime
- Maintenance mode enabled
- Confirmed correct environment (not production by mistake)
- Reviewed dry-run output
- Rollback plan prepared
#!/bin/bash
set -e
# Backup with error handling
if ! nself backup create; then
echo "Backup failed - aborting destruction"
exit 1
fi
# Destroy with confirmation
if nself destroy --dry-run; then
read -p "Proceed with destruction? (yes/no): " confirm
if [[ "$confirm" == "yes" ]]; then
nself destroy --force
fi
fi# .github/workflows/teardown.yml
name: Teardown Environment
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to destroy'
required: true
type: choice
options:
- staging
- dev
jobs:
teardown:
runs-on: ubuntu-latest
steps:
- name: Backup
run: nself backup create --env ${{ inputs.environment }}
- name: Destroy
run: nself destroy --force --keep-volumesQ: Can I undo a destroy operation?
A: Only if you created a backup first. Use nself backup restore <backup-id> to recover.
Q: What's the difference between stop and destroy?
A: stop pauses services (reversible), destroy removes them (requires rebuild).
Q: Is it safe to use destroy in development?
A: Yes, with --keep-volumes flag to preserve databases.
Q: Can I destroy only one service?
A: No, destroy operates on the entire project. Use docker rm <container> for single services.
Q: What happens to .env files? A: They are always preserved (never deleted by destroy).
Q: Can I recover after accidental destruction?
A: Only data in Docker volumes is lost. Rebuild with nself build && nself start. If you had backups, use nself backup restore.
Version: nself v1.0.0+ Command Type: Destructive Safety Level: Interactive (with --force bypass) Related Docs: Backup Guide, Stop Command
ɳSelf CLI v1.0.9. MIT licensed. Docs CC BY 4.0.
GitHub · Issues · Discussions · nself.org · nself.org/docs
Getting Started
Commands
- Commands, Overview
- Lifecycle: cmd-init · cmd-build · cmd-start · cmd-stop · cmd-restart · cmd-dev
- Monitoring: cmd-status · cmd-logs · cmd-health · cmd-urls · cmd-doctor · cmd-monitor · cmd-alerts · cmd-sentry · cmd-watchdog
- Data: cmd-db · cmd-backup · cmd-dr · cmd-queue · cmd-webhooks
- Config: cmd-config · cmd-service · cmd-env · cmd-promote
- Networking: cmd-ssl · cmd-trust · cmd-dns-setup
- Security: cmd-access · cmd-security · cmd-secrets
- Tenancy: cmd-tenant · cmd-billing
- Plugins: cmd-plugin · cmd-license · cmd-dogfood (extracted, CLI-R11) · cmd-k8s (extracted, CLI-R11) · cmd-encryption (extracted, CLI-R11) · cmd-waf (extracted, CLI-R11) · cmd-federation (extracted, CLI-R11) · cmd-mail (extracted, CLI-R11) · cmd-dlq (extracted, CLI-R11)
- AI: cmd-ai · cmd-claw · cmd-model
- Templates: cmd-template
- Utilities: cmd-exec · cmd-clean · cmd-reset · cmd-update · cmd-upgrade · cmd-version · cmd-admin · cmd-migrate · cmd-migrate-firebase · cmd-migrate-supabase · cmd-completion
Features
- Features, Overview
- Feature-Auth
- Feature-Storage
- Feature-Search
- Feature-Functions
- Feature-Email
- Feature-Monitoring
- Feature-Plugins
- Feature-nClaw, AI Assistant
- Feature-nChat, Messaging
- Feature-nTV, Media Player
- Feature-nFamily, Family Social
- Feature-nCloud, Managed Hosting
- Feature-Memory-Rooms, Knowledge Organization
- Feature-Agent-Dashboard, Agent Metrics
- Feature-Image-Generation, AI Image Generation
Configuration
- Configuration, Overview
- Config-Env-Vars
- Config-Postgres
- Config-Hasura
- Config-Auth
- Config-Nginx
- Config-Optional-Services
- Config-Custom-Services
- Config-System
Plugins (87 + 10 monitoring)
Free (25)
- plugin-backup
- plugin-content-acquisition
- plugin-content-progress
- plugin-cron
- plugin-donorbox
- plugin-feature-flags
- plugin-github
- plugin-github-runner
- plugin-invitations
- plugin-jobs
- plugin-link-preview
- plugin-mdns
- plugin-mlflow
- plugin-monitoring
- plugin-notifications
- plugin-notify
- plugin-paypal
- plugin-search
- plugin-shopify
- plugin-stripe
- plugin-subtitle-manager
- plugin-tokens
- plugin-torrent-manager
- plugin-vpn
- plugin-webhooks
Pro (62)
- plugin-access-controls
- plugin-activity-feed
- plugin-admin-api
- plugin-nself-ai-gateway
- plugin-nself-ai-mcp
- plugin-nself-ai-mcp
- plugin-analytics
- plugin-auth
- plugin-backup-pro
- plugin-bots
- plugin-browser
- plugin-calendar
- plugin-cdn
- plugin-chat
- plugin-claw
- plugin-claw-budget
- plugin-claw-news
- plugin-claw-web
- plugin-cloudflare
- plugin-cms
- plugin-compliance
- plugin-cron-pro
- plugin-ddns
- plugin-devices
- plugin-documents
- plugin-donorbox-pro
- plugin-entitlements
- plugin-epg
- plugin-file-processing
- plugin-game-metadata
- plugin-geocoding
- plugin-geolocation
- plugin-google
- plugin-home
- plugin-idme
- plugin-knowledge-base
- plugin-linkedin
- plugin-livekit
- plugin-media-processing
- plugin-meetings
- plugin-moderation
- plugin-mux
- plugin-notify-pro
- plugin-object-storage
- plugin-observability
- plugin-paypal-pro
- plugin-photos
- plugin-podcast
- plugin-post
- plugin-realtime
- plugin-recording
- plugin-retro-gaming
- plugin-rom-discovery
- plugin-shopify-pro
- plugin-social
- plugin-sports
- plugin-stream-gateway
- plugin-streaming
- plugin-stripe-pro
- plugin-support
- plugin-tmdb
- plugin-voice
- plugin-web3
- plugin-workflows
Planned (26)
plugin-auditplugin-blogplugin-checkoutplugin-commerceplugin-drmplugin-exportplugin-flowplugin-importplugin-ldapplugin-mailgunplugin-mediaplugin-oauth-providersplugin-pagesplugin-postmarkplugin-rate-limitplugin-reportsplugin-samlplugin-schedulerplugin-sendgridplugin-ssoplugin-subscriptionplugin-thumbplugin-transcoderplugin-twilioplugin-wafplugin-watermark
Guides
- Guide-Production-Deployment
- Guide-SSL-Setup
- Guide-Multi-Tenancy
- Guide-Security-Hardening
- Guide-Monitoring-Setup
- Guide-Backup-Restore
- Guide-Custom-Services
- Guide-Migration-from-v1
Architecture
Reference
- API-Reference
- error-codes, Error Codes
Licensing
Security
Brand
Operations
- operations/release-cascade, Release Cascade
- operations/self-healing, Self-Healing Schema
- operations/redis-tuning, Redis Pool Tuning
- operations/meilisearch-warmup, MeiliSearch Warm-Up
- operations/jwt-rotation, JWT Key Rotation
- operations/windows-wsl2-setup, Windows / WSL2 Setup
- operations/gemini-oauth-reauth, Gemini OAuth Reauth
Contributing
Admin
- USER-ACTION-QUEUE, Pending Admin Actions
All commands (52)
- A: cmd-access · cmd-account · cmd-admin
- B: cmd-backup · cmd-build · cmd-bundle
- C: cmd-ci · cmd-clean · cmd-completion · cmd-config
- D: cmd-db · cmd-deploy · cmd-dev · cmd-doctor
- E: cmd-env · cmd-exec
- F: cmd-functions
- G: cmd-generate
- H: cmd-health · cmd-help-topics
- I: cmd-init · cmd-install
- L: cmd-license · cmd-login · cmd-logout · cmd-logs
- M: cmd-man · cmd-mcp · cmd-migrate
- O: cmd-oauth · cmd-ops
- P: cmd-plugin · cmd-promote
- R: cmd-remove · cmd-reset · cmd-restart · cmd-runner
- S: cmd-secrets · cmd-security · cmd-self-heal · cmd-server · cmd-service · cmd-start · cmd-status · cmd-stop
- T: cmd-telemetry · cmd-template · cmd-trust
- U: cmd-update · cmd-urls
- V: cmd-verify-sbom · cmd-version