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?
Thanks for your answer. I tried mounting it to a folder inside the one I'm using in the compose file but strangely it didn't work. So I thought that the only way that wouldn't need to delay docker start is to restart the container just after the drive has been mounted.
And that's what I ended up doing as the drive mount is a systemd service and therefore I can use
ExecStartPost
to restart the container. That way this doesn't affect other containers and also lets this one start even if the drive has not been mounted which I want in case there's no internet connection