【问题标题】:start playframework 2.7.2 via docker in dev environment在开发环境中通过 docker 启动 playframework 2.7.2
【发布时间】: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


【解决方案1】:

您可以按照此处的指南创建部署存档

https://www.playframework.com/documentation/2.7.x/Deploying

一旦你有了 tar 或 zip,你可以创建一个 dockerfile,如下所示

FROM openjdk:8u151-jre-slim
ADD playBinary.tar app    
CMD ["./app/playBinary/bin/playBinary"]

然后您可以像这样启动应用程序

docker run -d -p 8080:8080 <image-name>

为了在 dev 中运行它,你可以有一个小的实用脚本(它很丑)但它应该可以工作

#!/bin/bash
sbt run
function finish {
        sleep infinity
}
trap finish EXIT

并将以下几行添加到您的 Dockerfile 中

COPY ./init-script.sh /init-script.sh
RUN chmod +x /init-script.sh
CMD ["/init-script.sh"]

【讨论】:

  • 我不想部署。我现在只想通过 docker 我的项目运行
  • 抱歉我错过了,更新了答案!让我知道它是否有效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-12
  • 2022-09-25
  • 2021-06-27
  • 2021-12-17
  • 1970-01-01
相关资源
最近更新 更多