this post was submitted on 02 Sep 2024
8 points (100.0% liked)

Docker

1128 readers
1 users here now

founded 2 years ago
MODERATORS
 

I have a docker compose file with a bind volume. It basically mounts /media/user/drive/media to the container's /mnt.

It works as expected when /media/user/drive/ is mounted and its media folder has the files I want the container to see.

However, as it's a network drive, the container usually tries to start before it is mounted, so it would throw the error that /media/user/drive/media doesn't exist. So I created an empty folder in /media/user/drive called media while the drive was not mounted so that at least the container starts with the volume /mnt being empty until the network drive gets mounted and all the files appear at /media/user/drive/media.

To my surprise, when the drive gets mounted, even though if I do ls /media/user/drive/media it lists the drive contents correctly, the container still sees /mnt empty.

How would I go about getting the drive files inside the docker container when it automatically starts?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 3 months ago (2 children)

Thanks for your suggestion. That's what I first thought but there are some issues.

I have other containers that do not require this drive to be mounted. Main problem is that if for some reason the drive cannot be mounted (e.g. no internet connection), then docker would not start any of those containers.

That's why I need a particular solution. While writing this it has come my mind that I've got a container which mounts / as a read-only volume in its /mnt and it seems to work fine there. Maybe if I set the volume to mount /media/user instead of the drive it would work?

[–] [email protected] 2 points 3 months ago

Last suggestion: This document suggests that there may be an rclone volume plugin for docker, which could run the mount only when your specific container starts up: https://rclone.org/docker/

[–] [email protected] 1 points 3 months ago

Nevermind, what I ended up doing is restarting the container just after the drive has been mounted. Which is easy because it's a systemd service so I could use ExecStartPost