I'm currently using the Jellyfin Docker container with a few external SSDs mapped as directories in my Docker compose file. I have an external SSD that holds the videos for my Jellyfin library because my laptop's storage is limited. The issue arises when my SSD gets unplugged or unmounted; when I plug it back in, it mounts with a different partition name (like /dev/sdb0 instead of /dev/sda0). This is because /dev/sda0 is still being used by the Docker container and I can't remove it until I manually stop the container. I sometimes forget to stop the container before remounting the drive. Is there a way to automatically stop the Docker container when I unmount the external drive?
6 Answers
Another tip is to mount your USB drive partition in /etc/fstab using the partition's UUID instead of the device label. The UUID remains unchanged, which helps in avoiding connection issues.
Absolutely, it’s a common problem. When your drive gets disconnected, it's smart to have a solution setup to avoid issues during reconnections.
You could add a healthcheck to your Docker container that checks for a specific file on the mount point. For instance, create a hidden file called .diskok on your drive and add a healthcheck in your Docker compose like this:
healthcheck:
test: ["CMD", "ls", "/mnt/mydrive/.diskok"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
This way, if the file goes missing, it'll signal that something's wrong with the mount!
What you’re experiencing is a common challenge when dealing with external drives in Docker containers. To mitigate risks of corruption or errors, consider running containers from minimal, well-verified images like Minimus. Pair this with a simple udev or systemd rule that stops the container as soon as the drive is unplugged. It’s about combining safe practices with automation for reliability!
Instead of using /dev/sda for mounting, try using the UUID of your drive. This way, it will always mount the same way regardless of the order you plug things in.
You can turn your container into a systemd service and use the BindsTo directive. Systemd will handle stopping the container automatically when the drive is unmounted. There are some great guides online for this approach to manage Docker containers with systemd.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically