docker,

Resolve 'Are you trying to mount a directory onto a file (or vice-versa)?' in Docker

Jul 18, 2023 · 1 min read · Post a comment

The error message Are you trying to mount a directory onto a file (or vice-versa)? in Docker Compose typically occurs when there is a mismatch between the source and destination paths specified for a volume mount.

Prerequisites

  • Docker
  • Docker Compose

Solution(s)

  • Try updating Docker and Docker Compose to the latest version.
  • Restart Docker Compose stack.
  • Validate there are no typos.
  • Run docker system prune.
  • Run docker volume prune.
  • Make sure that the host (source) path exists.
  • This issue could appear if running multiple Compose files and these bind mounts with relative paths are not being part of the first specified Compose file. See here why. Update relative paths or use absolute paths.

Conclusion

In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.