在开发环境中通过docker启动playframework 2.7.2

时间:2019-05-14 13:27:34

标签: java scala docker playframework sbt

我正在尝试在docker中使用playframework 2.7.2启动项目,但此刻,但是sbt run命令启动服务器然后停止,所以我真的不明白如何通过docker启动我的项目? / p>

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

1 个答案:

答案 0 :(得分:0)

您可以按照此处的指南

创建部署档案文件

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>

要在开发人员中运行它,您可以使用一个小的实用程序脚本(它非常难看),但是应该可以工作

#!/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"]