How to make Docker data persistent across reboots
How to make Docker data persistent: The new container best practice is to create folders on the host to store the app’s data. This assumes you are using docker compose YAML files and docker run commands
With docker-compose.yml:
services:
myapp: # generic example
image: myimage:latest #generic example
restart: unless-stopped
volumes:
- ./data:/var/lib/myapp # <- app’s data dir inside container. ./ = current directory - home, in this case
Bring up the containers.
Verify it’s persistent - using [adguardhome] as the container name
You should see your host path mapped to the container path.
Existing container (already running, but NOT persistent yet) Create host folders:
Example: Using Adguard as the example.
Copy data out of the running container (so you don’t lose current settings):
Example: Using Adguard as the example.
docker cp adguardhome:/opt/adguardhome/work ~/adguard-home/
docker cp adguardhome:/opt/adguardhome/conf ~/adguard-home/
sudo chown -R $USER:$USER ~/adguard-home/work ~/adguard-home/conf
Edit docker-compose.yml to add the volumes:
Then:
Verify mounts (same inspect command as above).
Notes you’ll need exactly once Pick the right container path: every app has a data dir; check its docs or container README. (AdGuard: /opt/adguardhome/work and /opt/adguardhome/conf.)
Permissions: if you hit “permission denied” when backing up or copying, fix ownership on the host:
Backups: once persistent, back up the host folders (e.g., with your rsync command).
That’s it. New or existing, the core idea is the same: bind‑mount a host folder into the container’s data directory so the data lives outside the container and survives rebuilds/reboots.