Play framework auto-loading in docker container Play framework auto-loading in docker container docker docker

Play framework auto-loading in docker container


I solved the problem (sort of). The issue is not specific to either docker or play framework, but is related to how changes to files are detected using JNotify (play uses this library). Changes are detected by using native file system hooks. These hooks are not available in shared folders for virtual machines (I run the docker service in a VM machine since I'm on OSX). This means that the only way of automatically detecting file changes is to use a polling strategy. Play framework supports in version 2.3.2 and later. To enable, add this to your build.sbt:

PlayKeys.playWatchService := play.sbtplugin.run.PlayWatchService.sbt(pollInterval.value)

The answer is taken from an issue post on github: Play 2.3.2 auto reload is not working on shared folder

Update for play 2.4:Play 2.4 renames the config parameter. This is how to enable polling in 2.4:

PlayKeys.fileWatchService := play.runsupport.FileWatchService.sbt(pollInterval.value)

Thanks to philipphoffmann for his answer with the updated info. Added it to my answer to provide a solution for both 2.3 and 2.4.

Update:I just discovered a handy tool for OSX users: docker-osx-dev. It uses rsync to keep the host and virtual file systems in sync. This will trigger file system change on your virtual machine.


For play 2.4 this would be:

PlayKeys.fileWatchService := play.runsupport.FileWatchService.sbt(pollInterval.value)