question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docker image from `sbt docker:publishLocal` fails with "Failed to create parent directories for [/opt/docker/./logs/application.json]"

See original GitHub issue

Expected behaviour

A docker image built by sbt docker:publishLocal fails to run succesfully.

Actual behaviour

sbt docker:publishLocal creates a docker image, but that image fails with the following:

08:07:18,293 |-ERROR in ch.qos.logback.core.FileAppender[JSON] - Failed to create parent directories for [/opt/docker/./logs/application.json]
08:07:18,293 |-ERROR in ch.qos.logback.core.FileAppender[JSON] - openFile(./logs/application.json,true) call failed. java.io.FileNotFoundException: ./logs/application.json (No such file or directory)

Information

  • What sbt-native-packager are you using
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.4")
  • What sbt version
1.3.4
  • What is your build system (e.g. Ubuntu, MacOS, Windows, Debian ) Ubuntu 18.04
  • What package are you building (e.g. docker, rpm, …) docker image from sbt docker:publishLocal

Error Logs

sbt docker:publishLocal creates an image locally:

$ docker image ls
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
play-scala-rest-api-example   1.0-SNAPSHOT        ac947d225da3        7 hours ago         561MB

When I try to run this image with

docker run -p 5000:9000 play-scala-rest-api-example:1.0-SNAPSHOT 

I get the following errors:

08:07:17,922 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
08:07:17,922 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
08:07:17,922 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/opt/docker/conf/logback.xml]
08:07:17,965 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
08:07:17,965 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word coloredLevel with class [play.api.libs.logback.ColoredLevel]
08:07:17,966 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
08:07:17,973 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
08:07:17,980 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
08:07:18,006 |-INFO in ch.qos.logback.core.FileAppender[FILE] - File property is set to [./logs/application.log]
08:07:18,006 |-ERROR in ch.qos.logback.core.FileAppender[FILE] - Failed to create parent directories for [/opt/docker/./logs/application.log]
08:07:18,007 |-ERROR in ch.qos.logback.core.FileAppender[FILE] - openFile(./logs/application.log,true) call failed. java.io.FileNotFoundException: ./logs/application.log (No such file or directory)
        at java.io.FileNotFoundException: ./logs/application.log (No such file or directory)
        at      at java.io.FileOutputStream.open0(Native Method)
        at      at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at      at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at      at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:26)
        at      at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:204)
        at      at ch.qos.logback.core.FileAppender.start(FileAppender.java:127)
        at      at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
        at      at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
        at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
        at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
        at      at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
        at      at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
        at      at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
        at      at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at      at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
        at      at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at      at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at      at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
        at      at play.api.Logger$.<clinit>(Logger.scala:265)
        at      at play.api.Configuration$.<clinit>(Configuration.scala:164)
        at      at play.core.server.ProdServerStart$.readServerConfigSettings(ProdServerStart.scala:103)
        at      at play.core.server.ProdServerStart$.start(ProdServerStart.scala:43)
        at      at play.core.server.ProdServerStart$.main(ProdServerStart.scala:30)
        at      at play.core.server.ProdServerStart.main(ProdServerStart.scala)
08:07:18,007 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
08:07:18,007 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [JSON]
08:07:18,019 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.LoggingEventJsonProviders] for [providers] property
08:07:18,032 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.LoggingEventFormattedTimestampJsonProvider] for [timestamp] property
08:07:18,033 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.LogLevelJsonProvider] for [logLevel] property
08:07:18,034 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.LoggerNameJsonProvider] for [loggerName] property
08:07:18,034 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.ThreadNameJsonProvider] for [threadName] property
08:07:18,034 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.MessageJsonProvider] for [message] property
08:07:18,035 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.LogstashMarkersJsonProvider] for [logstashMarkers] property
08:07:18,035 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.ArgumentsJsonProvider] for [arguments] property
08:07:18,035 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [net.logstash.logback.composite.loggingevent.StackTraceJsonProvider] for [stackTrace] property
08:07:18,293 |-INFO in ch.qos.logback.core.FileAppender[JSON] - File property is set to [./logs/application.json]
08:07:18,293 |-ERROR in ch.qos.logback.core.FileAppender[JSON] - Failed to create parent directories for [/opt/docker/./logs/application.json]
08:07:18,293 |-ERROR in ch.qos.logback.core.FileAppender[JSON] - openFile(./logs/application.json,true) call failed. java.io.FileNotFoundException: ./logs/application.json (No such file or directory)
        at java.io.FileNotFoundException: ./logs/application.json (No such file or directory)
        at      at java.io.FileOutputStream.open0(Native Method)
        at      at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at      at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at      at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:26)
        at      at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:204)
        at      at ch.qos.logback.core.FileAppender.start(FileAppender.java:127)
        at      at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
        at      at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
        at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
        at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
        at      at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
        at      at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
        at      at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
        at      at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at      at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
        at      at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at      at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at      at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
        at      at play.api.Logger$.<clinit>(Logger.scala:265)
        at      at play.api.Configuration$.<clinit>(Configuration.scala:164)
        at      at play.core.server.ProdServerStart$.readServerConfigSettings(ProdServerStart.scala:103)
        at      at play.core.server.ProdServerStart$.start(ProdServerStart.scala:43)
        at      at play.core.server.ProdServerStart$.main(ProdServerStart.scala:30)
        at      at play.core.server.ProdServerStart.main(ProdServerStart.scala)
08:07:18,293 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
08:07:18,293 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [METRICS]
08:07:18,293 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
08:07:18,294 |-INFO in ch.qos.logback.core.FileAppender[METRICS] - File property is set to [./logs/metrics.log]
08:07:18,294 |-ERROR in ch.qos.logback.core.FileAppender[METRICS] - Failed to create parent directories for [/opt/docker/./logs/metrics.log]
08:07:18,294 |-ERROR in ch.qos.logback.core.FileAppender[METRICS] - openFile(./logs/metrics.log,true) call failed. java.io.FileNotFoundException: ./logs/metrics.log (No such file or directory)
        at java.io.FileNotFoundException: ./logs/metrics.log (No such file or directory)
        at      at java.io.FileOutputStream.open0(Native Method)
        at      at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at      at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at      at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:26)
        at      at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:204)
        at      at ch.qos.logback.core.FileAppender.start(FileAppender.java:127)
        at      at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
        at      at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
        at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
        at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
        at      at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
        at      at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
        at      at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
        at      at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at      at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
        at      at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at      at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at      at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
        at      at play.api.Logger$.<clinit>(Logger.scala:265)
        at      at play.api.Configuration$.<clinit>(Configuration.scala:164)
        at      at play.core.server.ProdServerStart$.readServerConfigSettings(ProdServerStart.scala:103)
        at      at play.core.server.ProdServerStart$.start(ProdServerStart.scala:43)
        at      at play.core.server.ProdServerStart$.main(ProdServerStart.scala:30)
        at      at play.core.server.ProdServerStart.main(ProdServerStart.scala)
08:07:18,294 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
08:07:18,296 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
08:07:18,296 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
08:07:18,298 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender]
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ASYNCFILE]
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to ch.qos.logback.classic.AsyncAppender[ASYNCFILE]
08:07:18,299 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNCFILE] - Attaching appender named [FILE] to AsyncAppender.
08:07:18,299 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNCFILE] - Setting discardingThreshold to 51
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender]
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ASYNCJSON]
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [JSON] to ch.qos.logback.classic.AsyncAppender[ASYNCJSON]
08:07:18,299 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNCJSON] - Attaching appender named [JSON] to AsyncAppender.
08:07:18,299 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNCJSON] - Setting discardingThreshold to 51
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender]
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ASYNCSTDOUT]
08:07:18,299 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to ch.qos.logback.classic.AsyncAppender[ASYNCSTDOUT]
08:07:18,299 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNCSTDOUT] - Attaching appender named [STDOUT] to AsyncAppender.
08:07:18,299 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNCSTDOUT] - Setting discardingThreshold to 51
08:07:18,300 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [play] to INFO
08:07:18,300 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [application] to DEBUG
08:07:18,300 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [v1.post] to TRACE
08:07:18,300 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN
08:07:18,300 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ASYNCFILE] to Logger[ROOT]
08:07:18,300 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ASYNCJSON] to Logger[ROOT]
08:07:18,300 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ASYNCSTDOUT] to Logger[ROOT]
08:07:18,300 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
08:07:18,300 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@6fdbe764 - Registering current configuration as safe fallback point

Oops, cannot start the server.
java.nio.file.AccessDeniedException: /opt/docker/RUNNING_PID
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
        at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
        at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
        at java.nio.file.Files.newOutputStream(Files.java:216)
        at play.core.server.ProdServerStart$.createPidFile(ProdServerStart.scala:148)
        at play.core.server.ProdServerStart$.start(ProdServerStart.scala:46)
        at play.core.server.ProdServerStart$.main(ProdServerStart.scala:30)
        at play.core.server.ProdServerStart.main(ProdServerStart.scala)

Also, here is the result of sbt docker:stage:

FROM openjdk:8 as stage0
LABEL snp-multi-stage="intermediate"
LABEL snp-multi-stage-id="1b33f71f-1ea4-431e-9fb1-16f5bc1e4ab2"
WORKDIR /opt/docker
COPY opt /opt
COPY 1/opt /1/opt
USER root
RUN ["chmod", "-R", "u=rX,g=rX", "/opt/docker"]
RUN ["chmod", "-R", "u=rX,g=rX", "/1/opt/docker"]
RUN ["chmod", "u+x,g+x", "/1/opt/docker/bin/play-scala-rest-api-example"]

FROM openjdk:8 as mainstage
USER root
RUN id -u demiourgos728 1>/dev/null 2>&1 || (( getent group 0 1>/dev/null 2>&1 || ( type groupadd 1>/dev/null 2>&1 && groupadd -g 0 root || addgroup -g 0 -S root )) && ( type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 || adduser -S -u 1001 -G root demiourgos728 ))
WORKDIR /opt/docker
COPY --from=stage0 --chown=demiourgos728:root /opt/docker /opt/docker
COPY --from=stage0 --chown=demiourgos728:root /1/opt/docker /opt/docker
USER 1001:0
ENTRYPOINT ["/opt/docker/bin/play-scala-rest-api-example"]
CMD []

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
briancaffeycommented, Aug 20, 2020

Thank you @muuki88 I’ll try working through this with your suggestions.

0reactions
eugeniykcommented, Aug 24, 2021

You can manually create folders inside docker?

dockerCommands ++= Seq(
  // Optional step - declare folders for logs if not mounted to the host
  ExecCmd("RUN", "mkdir", "-p", "/opt/docker/logs/"),
  ExecCmd("RUN", "chmod", "+w", "-R", "/opt/docker/logs/")
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Play framework sbt docker:publishLocal showing Errors
Docker prints some of its output to stderr and the internal logger renders it as an error. No Error though. There are a...
Read more >
Docker Plugin — sbt-native-packager 1.9.0 documentation
Docker images describe how to set up a container for running an application, including what files are present, and what program to run....
Read more >
Docker Plugin — sbt-native-packager 1.0a1 documentation
Generates a directory with the Dockerfile and environment prepared for creating a Docker image. Docker / publishLocal: Builds an image using the local...
Read more >
Dockerize the app | Play Framework Tutorial
open terminal and run docker images playground to see that an image was created with the version specified in build.sbt . the size...
Read more >
Yet another sbt-docker introduction - Medium
Recently, the team has been looking at creating, in an automatic fashion, the Docker images that are used in our Docker environment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found