Shashi Shekhar
Shashi Shekhar

Reputation: 307

Docker: Play framework application exits with code 0

I am working on dockerizing my scala play framework application. Docker builds successfully but docker run exits with code 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

My Dockerfile

FROM sshek2019/docker-scala

WORKDIR '/app'

COPY

EXPOSE 9004

CMD ["sbt", "run"]

My docker-compose file

version: "3.7"

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

Upvotes: 2

Views: 307

Answers (1)

Mateusz Kubuszok
Mateusz Kubuszok

Reputation: 27545

Your config says that on enter/closed std-in you app should be closed, which terminates it right after turning it on. You should disable development mode for docker image.

For instance you can use test instance mode:

CMD ["sbt", "runProd"]

However, you should rather run sbt in Docker in interactive mode so that std-in won't be immediately closed.

docker run --it ...

Upvotes: 1

Related Questions