我正在尝试建立一个开发环境,用于在 docker 容器中开发 play 应用程序。我创建了一个安装了 sbt 的图像。然后,我将主机上的项目文件夹作为卷映射到容器,并以交互模式运行 shell:
docker run -v /Users/jorgen/dev/play-sbt-docker/app:/data/app -w /data/app -p 9999:9000 -i -t jorgenfb/sbt /bin/bash
然后我通过运行启动播放应用程序sbt ~run
。播放服务器开始只是找到,当我在主机上编辑我的文件时它甚至会重新编译:
[info] Compiling 1 Scala source to /data/app/target/scala-2.10/classes...
[success] Compiled in 2s
问题是刷新时更改不会出现在浏览器中。由于我禁用了缓存,因此没有缓存问题。如果我从主机运行应用程序,一切正常。
编辑:这是我用于使用 sbt 创建容器的 Dockerfile:
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
我做了更多的研究。在 docker 容器中,我像这样启动 play 应用程序:
[ 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
在我的浏览器中加载页面工作正常。然后我在主机上更改我的索引文件。这会触发容器内的重新编译:
[info] Compiling 1 Scala source to /data/app/target/scala-2.10/classes...
[success] Compiled in 1s
刷新我的浏览器仍然显示初始索引文件。即使容器内的播放应用程序获取了更改。我还检查了target/scala-2.10/classes/views/html
(在我的主机上,因为我在容器中运行播放应用程序并且我不确定如何将多个终端附加到它)中的编译文件。编译的文件已更改。
我做的下一件事是按Ctrl-D。根据上面打印的消息“(服务器已启动,使用 Ctrl+D 停止并返回控制台...)”,这应该让我回到 sbt 控制台。但是,这会导致以下输出:
[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)
现在我之前所做的更改会在刷新后反映在浏览器中。