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

  • BrianTheeBiscuiteer@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    2 days ago

    For me it really depends on the use-case. A lot of times I want persistence but don’t really care to access the data outside of the container. So rather than using the extra brainpower to make up folders myself and ensure paths don’t change I just let Docker handle those details for me. Also I use Podman a fair amount and it seems to be more troublesome when it comes to bind mounts.