All docker files look something like this

services:
  service_name:
    image: author/project:latest
    container_name: service_name
    volumes:
      - service_data:/app/data/

volumes:
  service_data:

Yes, this makes the data to persist, but it creates a directory with a random name inside /var/lib/docker/volumes/
This makes it really hard to actually have ownership of the data of the service (for example to create backups, or to migrate to another host)

Why is it standard practice to use this instead of having a directory mounted inside at the same level you have your docker-compose.yml?
Like this - ./service_data:/app/data

  • Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    23
    arrow-down
    3
    ·
    3 days ago

    I change them all to bind mounts. Managed volumes is where data goes to die, if it’s not in my file tree I’ll forget it.

    • cotlovan@lemm.ee
      link
      fedilink
      English
      arrow-up
      1
      ·
      12 hours ago

      I always wondered if it safe to do so, but never trusted myself, since I don’t want to risk the data that’s already there.