Where do you create application logs of app running in Docker so that I can map them later to host system ?
It's unclear in documentation for me whether I should create logs in some directory accessible without root permissions (then which one?) or I somehow can chown directory I need.
I tried using /var/log/case
and /opt/case/logs
with no success. Here is my minified SBT script
object build extends Build {
lazy val root = Project(
id = "case-server",
base = file("."),
settings = Defaults.coreDefaultSettings ++ graphSettings ++ Revolver.settings ++ Seq(
version := "1.15",
scalaVersion := "2.11.7",
libraryDependencies ++= {
val akkaV = "2.4.1"
val akkaStreamV = "2.0.1"
val scalaTestV = "2.2.5"
Seq(
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2",
"ch.qos.logback" % "logback-classic" % "1.1.+",
"org.scalatest" %% "scalatest" % scalaTestV % "test"
)
},
dockerBaseImage := "develar/java",
dockerCommands := dockerCommands.value.flatMap {
case cmd@Cmd("FROM", _) => List(cmd, Cmd("RUN", "apk update && apk add bash"))
case other => List(other)
},
dockerExposedVolumes := Seq("/opt/case/logs"),
version in Docker := version.value
)
).enablePlugins(AssemblyPlugin).enablePlugins(JavaAppPackaging).enablePlugins(DockerPlugin)
}
What is the correct approach to do this ?
You don't want your application log to be written on files on the container filesystem. The other solutions are:
stdout
(so that they will be forwarded to the Docker engine and available with the docker logs
command)Furthermore, if your application is writing its log entries to stdout
, you can rely on Docker logging drivers to send those logs to syslog
, journald
, gelf
, fluentd
, awslogs
, json files, or any log collecting system that provides a docker logging driver.
A trick to make an application write to stdout
instead of to a file is to configure it to write to the special file /proc/self/fd/1
. Anything written to this special file will be sent to stdout
.