How to run a container if a volume mount point is not yet ready?

Hi everyone. Here’s my use case

  • I’m running a Tvheadend container and it records tv shows to a samba share.

  • Recording is not always needed and not important. Therefore that samba server is not always running.

  • I’m using systemd automount service to auto mount the samba share on the TVBOX when it’s online.

With this setup above, docker runs fine. My problem is that when samba server is offline, tvheadend container doesn’t start because the samba share mount point on the TVBOX doesn’t exist as a volume on docker.

How can I make docker to ignore a volume if it’s not ready yet?

Impossible with volumes. Though you could use a bind and bind the mount point itself, instead of a subfolder of the remote share.

Let’s assume you have a remote share x with a folder y. You mount it into the mountpoint /mnt/x (which always exists). Instead of binding /mnt/x/y (which only exists when the remote share is mounted) into the container, you would need to bind /mnt/x instead and adjust the relative path inside the application.

In order for the container to see changes to the mount point (see: Bind mounts | Docker Documentation) you will need to set the mount propagation (All modes except private and rprivate should do the trick). This can be used with binds like this -v /mnt/x:{target}:private, which can also be applied to a compose file.

WOW it’s working, thank you @meyay
Leaving the docker command here in case anyone having the same problem.

docker create \
  --name=tvheadend \
  -e PUID=0 \
  -e PGID=0 \
  -e TZ=Europe/Istanbul \
  --net=host \
  -v /storage/dockers/tvheadend/config:/config \
  -v /storage/dockers/tvheadend/picons:/picons \
  -v /storage/external:/external:rshared \
  --restart=unless-stopped \
  --privileged \