Docker: Play 框架应用程序退出,代码为 0

Docker: Play framework application exits with code 0

我正在 docker 调整我的 scala play 框架应用程序。 Docker 构建成功但 docker 运行 退出代码 0.

user-service | [info] Loading project definition from /app/project
user-service | [info] Set current project to user-service (in build file:/app/)
user-service | 
user-service | SLF4J: Class path contains multiple SLF4J bindings.
user-service | SLF4J: Found binding in [jar:file:/app/lib/logback-classic-1.2.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
user-service | SLF4J: Found binding in [jar:file:/root/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
user-service | SLF4J: Found binding in [jar:file:/root/.ivy2/cache/org.slf4j/slf4j-nop/jars/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
user-service | SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
user-service | SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
user-service | --- (Running the application, auto-reloading is enabled) ---
user-service | 
user-service | [info] p.c.s.AkkaHttpServer - Listening for HTTP on /0.0.0.0:9004
user-service | 
user-service | (Server started, use Enter to stop and go back to the console...)
user-service | 
user-service | [info] p.c.s.AkkaHttpServer - Stopping server...
user-service | 
user-service | [success] Total time: 4 s, completed Apr 2, 2020 10:40:20 AM
user-service exited with code 0

我的Docker文件

FROM sshek2019/docker-scala

WORKDIR '/app'

COPY

EXPOSE 9004

CMD ["sbt", "run"]

我的docker-撰写文件

version: "3.7"

services:
  api:
    build: .
    container_name: user-service
    expose:
      - "9004"
    ports:
      - "9004:9004"

您的配置表明在 enter/closed std-in 上您的应用程序应该关闭,这会在打开它后立即终止它。您应该为 docker 图像禁用 development mode

例如你可以使用test instance mode:

CMD ["sbt", "runProd"]

但是,您应该在交互模式下 运行 sbt in Docker 这样 std-in 就不会立即关闭。

docker run --it ...