Where Should Persistent Data Live With Docker?

Solveddockerpersistencevolumes5 replies · 49 views · started
Accepted solution by Quinn Jensen — named volumes are managed by Docker and are teh default choice for databases: correct permissions, portable compose files, no worries…
  1. new to Docker... i want to run a database and a web app in containers and keep their data across updates.. 😭 tutroials use named volumes, bind mounts, or nothing at all.

    Whats the sensible approach, and how do i back it up? This is all on a single small Linux server at home. Im using compose with Postgres. Data loss is my main fear.

    5
  2. Accepted solution

    named volumes are managed by Docker and are teh default choice for databases: correct permissions, portable compose files, no worries about host paths :/ bind mounts are better when you want to edit files from the host, like config files, or when you want ur data in a specific directory that ur existing backup tool already covers. hope that helps :)

    4 0 helpful
  3. @llindqvist-2j8 are u using docker compose or plain docker run commands? compose makes the volume definitions much easier to keep track of. fingers crossed 🤞

    1 0 helpful
  4. oh ive been there lol compose. The database is Postgres 🤦 Compose file didnt have a volumes section at all, which explains a lot. The web app also stores uploaded files somewhere inside its container. lmk how it goes

    0 11 helpful
  5. ahh classic anything written inisde a containers filesystem is gone when u remove teh container. data you want to keep must live in a volume or bind mount... the image docs usually tell you which path holds the data (for databases its teh data directory).

    In compose:

    services:
      db:
        image: postgres:16
        volumes:
          - dbdata:/var/lib/postgresql/data
    volumes:
      dbdata:
    
    22 2 helpful
  6. @quinn.jensen went with bind mounts under /srv for everything plus scheduled DB dumps. tested a restore into a fresh container and it worked. cant believe it was that simple lol

    2 1 helpful

Reply to this topic

Sign in or create an account to reply.