Auto frame loading in docker container

I am trying to set up a development environment for developing a game application in a docker container. I created an image with sbt installed. Then I map the project folder on my host to a container like that and launch the shell interactively:

docker run -v /Users/jorgen/dev/play-sbt-docker/app:/data/app -w /data/app -p 9999:9000 -i -t jorgenfb/sbt /bin/bash 

Then I launch the playback application by running sbt ~run . The game server starts to just find, it even recompiles when I edit my files on the host:

 [info] Compiling 1 Scala source to /data/app/target/scala-2.10/classes... [success] Compiled in 2s 

The problem is that the changes are not displayed in the browser during the update. No caching since I disabled caching. If I run the application from my host, everything will be fine.

Edit: This is my Dockerfile used to create a container with sbt:

 FROM dockerfile/java:oracle-java8 MAINTAINER JΓΈrgen Borgesen ENV SBT_VERSION 0.13.5 # Install sbt RUN cd /tmp && \ wget https://dl.bintray.com/sbt/native-packages/sbt/$SBT_VERSION/sbt-$SBT_VERSION.zip && \ unzip sbt-$SBT_VERSION.zip -d /usr/local && \ rm sbt-$SBT_VERSION.zip 

I did some more research. Inside the docker container, I launch the playback application as follows:

 [ root@aa1f2327d938 :/data/app ]$ /usr/local/sbt/bin/sbt [info] Loading project definition from /data/app/project [info] Set current project to my-first-app (in build file:/data/app/) [my-first-app] $ ~run --- (Running the application from SBT, auto-reloading is enabled) --- [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 (Server started, use Ctrl+D to stop and go back to the console...) [success] Compiled in 740ms 

Page loading in my browser works fine. Then I change the index file to the host. This causes recompilation inside the container:

 [info] Compiling 1 Scala source to /data/app/target/scala-2.10/classes... [success] Compiled in 1s 

Updating my browser still shows the initial index file. Even if the changes were caused by the playback application in the container. I also checked the compiled files in target/scala-2.10/classes/views/html (on my host, since I am running the playback application in the container, and I'm not sure how to connect multiple terminals to it). Compiled files have changed.

The next thing I did was hit Ctrl-D. This should take my back to the sbt console according to the printed message above "(Server started, use Ctrl + D to stop and return to the console ...)". However, this leads to the following result:

 [success] Total time: 455 s, completed Sep 25, 2014 7:40:35 AM 1. Waiting for source changes... (press enter to interrupt) --- (Running the application from SBT, auto-reloading is enabled) --- [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 (Server started, use Ctrl+D to stop and go back to the console...) [info] play - Application started (Dev) 

Now the changes that I made earlier are reflected in the browser after the update.

+7
docker boot2docker development-environment playframework
source share
2 answers

I solved the problem (sort of). This problem does not apply to the docker platform, nor to the playback platform, but is related to how file changes were detected using JNotify (playback uses this library). Changes are detected using the built-in file system hooks. These interceptors are not available in shared folders for virtual machines (I am running the docker service on a VM machine since I am on OSX). This means that the only way to automatically detect file changes is to use a polling strategy. Platform support supports version 2.3.2 and later. To enable, add this to your build.sbt file:

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

The answer is taken from the github issue report: Play 2.3.2 startup does not work in the shared folder

Update for game 2.4: Play 2.4 renames the configuration parameter. Here's how to enable polling in 2.4:

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

Thanks to philipphoffmann for his reply with updated information. Added it to my answer to provide a solution for 2.3 and 2.4.

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

+10
source share

For 2.4 playback, this would be:

 PlayKeys.fileWatchService := play.runsupport.FileWatchService.sbt(pollInterval.value) 
+3
source share

All Articles