To keep Docker data across restarts and rebuilds, store it in named volumes or bind mounts, never only inside the container; then back those volumes up off the server. This guide sets that up on an Ubuntu VPS with Docker Compose and a Traefik reverse proxy.
A container's own filesystem is thrown away when the container is removed or recreated. Anything you need to keep, such as database files or uploads, must live in a volume.
Bind mounts vs. volumes
Bind mounts map a host folder (for example /opt/app/data ) into the container. Handy for config files you edit by hand.
Named volumes are managed by Docker under /var/lib/docker/volumes . They're the usual choice for database data such as PostgreSQL or MySQL.
Step 1: Install Docker
Install Docker Engine and the Compose plugin with Docker's official convenience script:
curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh
Enter fullscreen mode
Exit fullscreen mode
You can read get-docker.sh before running it.…