Why Container Apps on Your NAS Lose Configuration After Restarts: Root Causes and Fixes

    Deploying stateful services on a NAS often leads to a frustrating problem: after a restart, admin accounts, connection settings, task history, or license keys vanish. This article explains why the issue usually stems from state being written to ephemeral layers rather than from the restart itself, breaks down seven common deployment patterns and their failure models, and provides a unified baseline for directory layout, declarative manifests, startup validation, idempotent initialization, and backup testing so configuration persistence becomes verifiable and reproducible.

    Why “Restart Lost My Config” Is Really a State Management Problem

    When you deploy services with admin interfaces, account systems, task records, or local state databases on a NAS, “configuration resets to defaults after a restart” is rarely a single bug. It is usually a mismatch between the deployment model and how the application manages state. Typical symptoms include: admin accounts being reset, connection parameters disappearing, task history wiped, licenses or keys lost, logs and uploads invisible, or—after repeated re-initialization—database locks or version conflicts.

    Start by distinguishing four lifecycle types:

    1. Process restart: Only the application process restarts; the container or runtime is not recreated. If configuration is still lost here, the app is likely writing config to memory-mapped directories, temp directories, or a startup script overwrites the config file on every launch.
    2. Instance recreation: The running instance is deleted and recreated, wiping the image’s writable layer. If config directories, state databases, and upload paths are not mounted to stable host paths, data loss is inevitable.
    3. Host reboot: Shared folders, encrypted volumes, external storage, or permission services on the NAS may start later than the application. The app starts first and writes to the “mount point”; once the real storage mounts, earlier writes are shadowed—making it look like config was lost.
    4. Upgrade, rollback, or snapshot restore: A new image version may be incompatible with the existing config structure; rollback may restore the program but not the config; snapshot restores may pull the state database, keys, and config from different points in time.

    The real fix is not “prevent restarts” but ensuring all necessary state lives outside the instance lifecycle and can be remounted reliably and verifiably.

    Seven Common Deployment Patterns and Their Failure Models

    1. One-Click GUI Deployment: Parameters Live Only in the Interface

    Many NAS devices offer graphical app installers. You fill in ports, accounts, and passwords and the service starts—simple, but critical parameters may exist only in the device’s management database or the instance’s environment variables. During upgrade, repair, migration, or recreation, those parameters are not guaranteed to carry over.

    Typical risks:

    • Only a few directories are mapped; the app’s default config directory is not.
    • The “install path” shown in the UI differs from the instance’s actual working directory.
    • Recreation assigns new random ports or fresh directories.
    • Environment variables and account keys are not backed up independently.

    Remedy: Treat GUI deployment as a launch entry point, not the source of truth. After installation, export the actual runtime parameters into a standalone declarative manifest; document every mount source and target; store env files, key files, and version numbers in a controlled directory. Rebuild from auditable manifests going forward, not from remembered UI fields.

    2. Single Run Command: CLI Arguments Are Not Persisted

    When launching containers manually, ports, accounts, database paths, and startup flags often exist only in the command line. Once the instance is updated, recreated, or cleaned up, that command history is not reusable config—you refill everything from memory and conclude the “app lost its config.”

    Worse, some apps silently fall back to built-in defaults when no writable config directory is found, without a visible error. The app appears to start successfully while actually running in a temporary mode.

    Remedy: Solidify run commands into version-controlled declarative files, recording at minimum the image version, run user, mount points, env var sources, health checks, startup dependencies, and storage paths. Command history is not a deployment basis. Every change needs a diff record so recreation is reproducible.

    3. Relative Paths and Working Directories: Config Written to the Wrong Place

    Applications typically default to a config subdirectory under “the current directory.” If the host does not explicitly mount that path—or you mount a parent directory but the app’s working directory changes—the config lands in the instance’s writable layer. The UI says “saved successfully,” but the settings vanish as soon as the instance is recreated.

    Typical signs:

    • The config directory exists but is empty after instance recreation.
    • Logs show config written successfully, but the backup directory has no such files.
    • The same service behaves inconsistently when launched from different entry points.
    • After an upgrade, changes in path casing, symlinks, or working directories make historical configs unreadable.

    Remedy: Use absolute paths for all mounts; map application config paths one-to-one to host directories; never rely on “.” or relative parent paths. For apps that resolve symlinks, pin real paths and avoid mounting an empty directory and letting the app fill it first. After deployment, verify the actual write location via the app’s config export, file checksums, or state markers.

    4. Stateful Applications Treated as Stateless Images

    Apps with embedded single-file databases, session tables, uploaded attachments, certificates, keys, index files, or task queues are inherently stateful. Mapping a single “config directory” is often not enough: the database may live elsewhere, keys in the run user’s home directory, attachments in a temp upload folder.

    Common omissions:

    • Mounting the config file but not the database and business data.
    • Backing up config but not keys or migration versions.
    • Mounting the upload directory read-only, so the app falls back to an in-instance temp directory.
    • Mixing cache and production data, then deleting necessary state during cache cleanup.

    Remedy: Build a state inventory and classify what the app may write into four categories:

    State Category Typical Contents Must Persist? Backup Guidance
    Configuration Admin settings, feature flags, connection info Yes Back up after every change; keep history
    Identity & secrets Accounts, tokens, certificates, encryption keys Yes Encrypted backups; strict access control
    Business state Databases, task queues, indexes, attachments Yes Consistency backups; periodic restore drills
    Temporary data Page caches, thumbnails, download intermediates Optional Generally excluded from critical recovery

    First-time initialization must be idempotent: generate default config only when the target directory is empty and no version marker exists; if the directory is non-empty or a marker exists, refuse to overwrite and fail with a clear error. Never implement initialization as “copy default config on every startup.”

    5. Permissions, User Mapping, and Filesystem Semantics

    NAS environments typically have a mismatch between the run user and shared folder permissions. The app may run as a fixed UID while the host directory belongs to another user; or the directory is readable but not writable, and the app silently falls back to an in-instance default path after a failed save. You see “config not saved” but struggle to find the root cause in logs.

    Watch for:

    • Whether run UID/GID match the directory owner;
    • Missing execute/traverse permissions on parent directories;
    • Whether inherited permissions on shared folders cover newly created files;
    • Whether file casing, symlinks, and cross-filesystem moves are supported;
    • Whether a mounted directory is read-only, pushing the app to temp directories;
    • Whether cleanup policies delete hidden files, version markers, or database logs.

    Remedy: Pin a dedicated run user and group per app; pre-create config, data, log, and backup directories with least-privilege permissions. Do not “solve” the problem with root or fully open permissions. Run a writability check before startup: create a temp probe file in the target directory as the app’s run user, confirm success, then delete it. Permission changes belong in the deployment process, not manual fixes after restarts.

    6. Storage Mounting vs. Startup Order Mismatch

    On host reboot, the app may start before shared storage, encrypted volumes, or external drives. The mount point is then just an ordinary empty directory, so the app writes initialization config into it; the real storage mounts afterward and shadows the path, hiding what was written. Alternatively, storage may be briefly unavailable; the app detects the failure and switches to a local temp directory, creating “dual writes” or fallback writes.

    This is highly deceptive: logs show a successful startup, config existed at some point, yet a subset of settings disappears after every reboot.

    Remedy: Place a mount marker file in the storage volume that must not be casually overwritten; the app’s startup script validates the marker, directory writability, and version info before starting. On validation failure, wait and retry or exit with an explicit error—never fall back to temp directories. For shared-folder dependencies, configure startup dependencies at the deployment layer so storage is ready before the app launches. For services needing multiple directories, avoid half-mounted states where some directories are ready and others are not.

    7. Missing Version Contracts for Upgrades, Rollbacks, and Snapshot Restores

    Config loss often strikes not during ordinary restarts but after image upgrades, instance recreation, bulk cleanup, or snapshot restores. A new version may change config fields, causing the migration script to fail on the old config and silently regenerate defaults; rollback may restore the program image without the matching config version; snapshot restores may pair a database and config files from different points in time.

    Remedy: Maintain explicit schema versions and upgrade records for config directories. Before upgrading, stop writes or enter maintenance mode, take a consistent backup, then run a one-shot migration; migrations must be idempotent and preserve the originals on failure. Rollbacks must restore program version, config version, and database state together. Cleanup policies should only touch clearly defined cache directories—never perform indiscriminate deletion on config, data, or key directories.

    A Unified Deployment Baseline: One Directory Tree, One Manifest, One Validation

    Establish a stable root directory for each stateful service, for example:

    1. /srv/application/
    2. conf/ # config files, env vars, schema version
    3. data/ # business databases, attachments, indexes
    4. state/ # runtime state, queues, lock files
    5. secrets/ # keys, certificates, tokens
    6. logs/ # logs and audit records
    7. backups/ # backup manifests and restore points
    8. deploy.yaml # deployment manifest

    The key to this layout is not the names but separation of responsibilities: config changes, business data growth, log rotation, and key rotation each deserve their own backup strategy. All instances use only this stable root; nothing is written directly to the writable layer that comes and goes with each instance.

    An illustrative manifest (structure only, not platform-specific syntax):

    1. service:
    2. image: local/stateful-app:stable
    3. run_as: "1000:1000"
    4. env_file: /srv/application/conf/runtime.env
    5. mounts:
    6. - source: /srv/application/conf
    7. target: /opt/app/conf
    8. mode: rw
    9. - source: /srv/application/data
    10. target: /opt/app/data
    11. mode: rw
    12. - source: /srv/application/secrets
    13. target: /opt/app/secrets
    14. mode: ro
    15. - source: /srv/application/logs
    16. target: /opt/app/logs
    17. mode: rw
    18. checks:
    19. - required_path: /opt/app/conf
    20. writable: true
    21. - required_path: /opt/app/data
    22. writable: true
    23. - marker_file: /opt/app/data/.volume_ready

    Startup validation, expressed as pseudocode:

    1. for each required directory:
    2. confirm the directory exists
    3. confirm the run user can traverse it
    4. for writable directories, perform a probe write
    5. confirm the mount marker file exists and the version matches
    6. if any check fails:
    7. emit a clear error
    8. wait or exit
    9. never fall back to in-instance default directories
    10. if no config version marker exists and the directory is empty:
    11. copy the default template
    12. write the current schema version
    13. else:
    14. load the existing config and run compatibility checks
    15. run idempotent migration only when the version requires it

    This validation layer dramatically reduces the hidden failure mode of “startup succeeded but is actually running on temporary config.”

    Key Deployment and Operations Practices

    1. Manage Configuration as Code

    Config files, environment variable templates, and migration notes belong in version control; sensitive values live separately in a controlled secrets directory, never baked into images. Record the app version, config version, mapped directories, and backup location with every change. Then recreation and rollback can be executed from the manifest rather than from memory.

    2. Keep Initialization and Upgrades Idempotent

    First startup only creates missing files and never overwrites existing ones; upgrade scripts detect the version first, migrate in order, then write the new schema version. If a migration is interrupted, it must be recoverable from temp files or backups. Never assume the app can safely overwrite old config on every startup.

    3. Take Consistent Backups of Databases and Attachments

    Config files can be copied directly; databases cannot rely on naive live copying. Prefer the application’s export capability, or back up after pausing writes and flushing to disk. Attachments and databases should share the same recovery point. Backups should include at least config, business data, secrets, version manifests, and restore instructions—and be rehearsed periodically in an isolated directory.

    4. Run All Three Test Types: Restart, Recreate, Upgrade

    Clicking “restart” in a UI does not prove config persistence. Validate in this order:

    1. Write a unique test marker into the config;
    2. Restart the process and confirm the marker survives;
    3. Delete and recreate the instance, confirming mount mappings are correct;
    4. Cold-reboot the host, confirming storage mount order and startup dependencies hold;
    5. Upgrade to a new version and roll back, confirming config and database version compatibility;
    6. Simulate an unwritable storage path and confirm the app refuses to start without generating temporary defaults;
    7. Restore from backup into a fresh directory, confirming accounts, keys, business data, and config are fully intact.

    Only when all these scenarios pass can you consider the config-loss problem closed.

    Conclusion

    When deploying stateful services on a NAS, “config lost after restart” is usually the combined result of ephemeral writable layers, incorrect mount paths, permission mismatches, storage startup ordering, overwrite-prone initialization, and upgrades lacking version contracts. A one-off manual fix may restore things temporarily, but the next recreation will reintroduce the problem.

    The more reliable path is a unified baseline: stable absolute paths for config, data, secrets, and logs; declarative manifests that pin deployment parameters; startup validation that blocks temporary fallbacks; idempotent initialization and versioned migrations that protect existing state; and consistent backups with restore drills that cover disaster scenarios. Once these mechanisms are in place, restarts, recreations, upgrades, and host reboots no longer depend on individual memory—and configuration persistence gains verifiable, reproducible engineering guarantees.