【发布时间】:2019-10-01 13:16:22
【问题描述】:
我正在尝试在 docker 中使用 playframework 2.7.2 启动一个项目,但目前 sbt run 命令启动服务器然后停止,所以我真的不明白如何通过 docker 启动我的项目?
Dockerfile:
FROM bigtruedata/scala:2.10.6
RUN apt-get update && apt-get install git
RUN wget -O- "https://piccolo.link/sbt-1.2.8.tgz" \
| tar xzf - -C /usr/local --strip-components=1 \
&& sbt exit
WORKDIR /app
EXPOSE 9000 9443
RUN sbt update
COPY app/ .
CMD ["sbt", "run"]
docker-compose.yaml
version: '3.2'
services:
play:
build:
context: .
dockerfile: docker/play/Dockerfile
volumes:
- ./app:/app
ports:
- "9000:9000"
- "9443:9443"
command: "sbt run"
我从 docker 开始的标准输出:
play_1 | [info] [SUCCESSFUL ] com.typesafe.play#play-docs_2.12;2.7.2!play-docs_2.12.jar (692ms)
play_1 | [info] [SUCCESSFUL ] com.typesafe.play#play-omnidoc_2.12;2.7.2!play-omnidoc_2.12.jar (831ms)
play_1 | [info] Done updating.
play_1 | [warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
play_1 |
play_1 | --- (Running the application, auto-reloading is enabled) ---
play_1 |
play_1 | [info] p.c.s.AkkaHttpServer - Listening for HTTP on /0.0.0.0:9000
play_1 |
play_1 | (Server started, use Enter to stop and go back to the console...)
play_1 |
play_1 | [info] p.c.s.AkkaHttpServer - Stopping server...
play_1 | [info] Compiling 7 Scala sources and 1 Java source to /app/target/scala-2.12/classes ...
play_1 | [info] Non-compiled module 'compiler-bridge_2.12' for Scala 2.12.8. Compiling...
play_1 | [info] Compilation completed in 18.801s.
play_1 | [info] Done compiling.
play_1 | [info] p.a.h.EnabledFilters - Enabled Filters (see <https://www.playframework.com/documentation/latest/Filters>):
play_1 |
play_1 | play.filters.csrf.CSRFFilter
play_1 | play.filters.headers.SecurityHeadersFilter
play_1 | play.filters.hosts.AllowedHostsFilter
play_1 |
play_1 | [info] play.api.Play - Application started (Dev) (no global state)
play_1 |
play_1 | [success] Total time: 53 s, completed May 14, 2019 1:12:39 PM
【问题讨论】:
-
没有真正回答你的问题,但
sbt run应该只用于本地开发。sbt dist可用于部署(无论是否使用 docker)。在这里阅读更多:playframework.com/documentation/2.7.x/… -
是的,是本地开发,但服务器在尝试启动后很快停止。
-
好的。你是怎么运行的?
-
通过 CMD ["sbt", "run"]
-
好的,我找到了,为什么没用。您必须激活 tty。 tty: 在你的 docker-compose.yaml 中为真
标签: java scala docker playframework sbt