How Can I Stop Docker Compose from Creating Empty Directories for Volumes?

0
1
Asked By CuriousCat123 On

I'm running a Jellyfin server using Docker Compose, but I'm facing an annoying issue. I have a drive, let's call it HardDikDrive, that sometimes isn't mounted when Jellyfin starts up (I'm running this on my main PC, not a dedicated server). In my Docker Compose file, I specify volumes like this:

- ./Jellyfin/Config:/config
- ./Jellyfin/Cache:/cache
- /run/media/username/HardDikDrive/Jellyfin/Shows:/Shows

The problem occurs when Jellyfin starts before the drive is connected. Instead of just connecting to a non-existent directory (which would show as empty in the container), Docker actually creates an empty directory at /run/media/username/HardDikDrive/Jellyfin/Shows. If I then mount the HardDikDrive, it ends up automounting to /run/media/username/HardDikDrive1/ instead of the original path. This leads to complications since the media files won't appear in the intended directory. Is there a way to configure the container so that if the source directory doesn't exist, it doesn't create a new one on the host?

4 Answers

Answered By TechieTim2020 On

You might want to try using a `depends_on` condition in your Docker Compose file. I had a similar issue with my setup where my downloaders were trying to create folders instead of using the existing ones. I configured my service to wait until the necessary paths were available. It requires some tweaking, but it could solve your problem.

Answered By MountMaster99 On

Another approach could be to set your bind mount to read-only. Additionally, you can modify the entrypoint of your container to check if the mount exists and stop the container with an error message if it doesn't. This would give you more control over how your service starts.

Answered By SystemdSage On

Consider using systemd service files to explicitly manage the start order. You can create a service definition that makes your compose stack wait for the drive to be mounted before starting. Add a line like `RequiresMountsFor=/run/media/username/HardDikDrive` to ensure it waits for your disk.

Answered By DockerDynamo42 On

Unfortunately, there isn't a built-in option to prevent this in Docker. It's really about the race condition between when Docker starts your container and when your drive mounts. The best workaround is to adjust your system so that the Docker container only starts after your drive is ready. The method to do this will depend on your OS and how you set things up. You might find more in-depth help in other forums, but sharing your system details could lead to more specific advice.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.