How to create named volume in docker compose file for mounted external ntfs drive?

I have a mounted external ntfs drive to my raspberry pi 4 (mounted at /media/onetouch5t). I use the line in fstab to automount it at startup:

UUID=<not important> /media/onetouch5t  ntfs  uid=82,gid=82,auto,nofail,rw 0 0

I’m trying to run the this docker-compose.yml file with the named volume for nextcloud. What I expect to see is docker creating the folders for nextcloud at /media/onetouch5t/pi4/data/nextcloud/html and …/db, but I’m not sure where I did it wrong making it giving the following error message:

Error response from daemon: failed to populate volume: error while mounting volume '/var/lib/docker/volumes/nextcloud-database/_data': failed to mount local volume: mount /media/onetouch5t/pi4/data/nextcloud/db:/var/lib/docker/volumes/nextcloud-database/_data, flags: 0x1000: no such file or directory

If I don’t use the named volume everything will be working just fine.
Can someone tell me what’s wrong with it?

Have you tried the same with an ext4 filesystem? I wouldn’t use ntfs for a Linux container, but I’m not entirely sure what the problem is.

Doesn’t seem to matter if it is ext4 or ntfs actually.

I think the problem is more about me using this IOTstack. They might have do something to how docker interprets relative path and absolute path. For instance, when I ask docker to put my portainer container volume at ./volumes/portainer-ce, it actually put it inside of ~/IOTstack/volumes/portainer-ce. I wonder if they could do something to the named volume and change the way it is being used.

Sorry for the late reply, and thanks for helping out.

I tried today and now the error code becomes this:

Error response from daemon: failed to populate volume: error while mounting volume '/var/lib/docker/volumes/Vol_nextcloud_db/_data': failed to mount local volume: mount /media/onetouch5t/pi4/data/nextcloud/db:/var/lib/docker/volumes/Vol_nextcloud_db/_data, flags: 0x1000: no such file or directory

Does the folders have to exist before I start docker compose?
It seems like if I create an empty folder it will run fine

Yes, when you use named volumes with custom source path, the volume source has to exist. The folder created by Docker will be just a symlink to the original folder. Also when you run docker compose down -v which would remove named volumes as well, only the fodler with the symlink in the docker data root will be removed, but Docker will not touch your original folder.

That explains why it didn’t work out.

Is there a way I can store the path somewhere in docker compose file (not another .env file or Dockerfile) and use it all the time including let docker create the html folder if it doesn’t exist?

The extensions part sort of meet my needs if I can store /media/…/html into a variable and use it all the time, but I’m not sure how to use it correctly in this case.
Maybe this is another separated question. I can open another topic if you like.

Thanks.

You can use extensions, but that could also overcomplicate things and it will not help you to create folders.
You will have to create the folder before running the compose project and although so you can have a script that prepares everything and executes the compose project. I do the same in my projects. I also use a template system to generate the compose file instead of extensions.

If you want to discuss extensions (or templating) further, I would indeed recommend a new topic.

For those who can’t see the code when I removed my repo, here is the short version of my docker compose file:

volumes:
  Vol_nextcloud_html:
    driver: local
    driver_opts:
      type: none
      device: /media/onetouch5t/pi4/data/nextcloud/html
      o: bind

services:
  nextcloud:
    volumes:
    - Vol_nextcloud_html:/var/www/html:z
1 Like