MatchbookLab / local-persist

Create named local volumes that persist in the location(s) you want
MIT License
852 stars 123 forks source link

Relative mountpoint in compose file #78

Open Flying--Dutchman opened 4 years ago

Flying--Dutchman commented 4 years ago

Is it possible to use relative paths in the docker-compose.yaml file? So, something like:

version: '3' 
  services:  
    mariadb:  
        image: 'mariadb'  
        container_name: mariadb1
        environment:
            - MYSQL_DATABASE=default
        volumes:
            - data-volume:/var/lib/mysql
volumes:
   data-volume:
        driver: local-persist
        driver_opts:
            mountpoint: ./mariadb

When I execute docker-compose up ., I'm getting following error:

ERROR: for mariadb Cannot start service mariadb: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\"/run/containerd/io.containerd.runtime.v1.linux/moby/db5c3688b835f041024a9982ec4e0d3ad8fe2f5e13a3514b410a6db74938f5a9/mariadb\\" to rootfs \\"/var/lib/docker/overlay2/598a206cbdf4c4a99ed293eaf7fbca8a67b61beddb901ce646a2265580bf758d/merged\\" at \\"/var/lib/mysql\\" caused \\"stat /run/containerd/io.containerd.runtime.v1.linux/moby/db5c3688b835f041024a9982ec4e0d3ad8fe2f5e13a3514b410a6db74938f5a9/mariadb: no such file or directory\\"\"": unknown

EDIT: local-persist was installed using the "Quick way", with the install script in README.

CWSpear commented 4 years ago

docker-compose expands directories to the full path by default... I'll have to look closer, but it is probably the case that compose doesn't know that mountpoint is a directory, so it doesn't expand it (i.e., it's just trying to pass in to the plugin directly).

I don't think I can get the path that the docker-compose.yml is in to be able to expand it correctly myself... so at first blush, I don't think it's possible, but is probably worth digging into a bit more.

In the meantime, some systems will pass through the PWD environment variables to compose, so you can try this: mountpoint: ${PWD}/mariadb

Flying--Dutchman commented 4 years ago

Thats too bad, hope it will be possible in the future. Thank you very much for your help.

In the meantime, some systems will pass through the PWD environment variables to compose, so you can try this: mountpoint: ${PWD}/mariadb

~~Unfortunately, this is throwing the same error. Will stick to fixed paths then.~~

${PWD} is working, thank you 👍

Flying--Dutchman commented 4 years ago

Closing issue...

Problem was apparently not the dot, but an orphaned container. As it seems, relative paths are working as expacted.

Only thing ist, missing directories are not automaticly created.

CWSpear commented 4 years ago

It does attempt to create the directory, but there are things that can happen such that it won't work: https://github.com/MatchbookLab/local-persist/blob/a8e9cdd7e345b28d09dee47f3bc77d0e0ffb13eb/driver.go#L110-L116

You could try looking at the driver's logs (i.e. journelctl for systemd or whatever it is...) to see what the error there says.

Flying--Dutchman commented 4 years ago

Thank you.

I noticed in Portainer, the following:

image

So, apparently relative paths, starting with a dot are not working. When using ${PWD}, the volume creates just fine.

For the time beeing, maybe add it to the readme?