title: docker exec java app background attach logs
body: <p>For a Java app running inside a docker container where should I output my logs to so that docker logs -f can read the log output of the java application after its been running for a while?</p>
  
  <p>I execute the java app that is inside the active docker container with something like the following</p>
  
  <pre><code>docker exec -d container-name java -jar /path-to-jar/java-app-1.0-SNAPSHOT.jar
  </code></pre>
  
  <p>So far so good it runs my Spring Boot java app.  </p>
  
  <p><strong>Would either of the following approaches work?</strong></p>
  
  <pre><code>docker exec -d container-name java -jar /path-to-jar/java-app-1.0-SNAPSHOT.jar &gt; /var/log/docker-id.log
  </code></pre>
  
  <p>Or setting the java log path settings to a particular destination?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
      &lt;include resource="org/springframework/boot/logging/logback/defaults.xml" /&gt;
      &lt;property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/&gt;
      &lt;include resource="org/springframework/boot/logging/logback/file-appender.xml" /&gt;
      &lt;root level="INFO"&gt;
          &lt;appender-ref ref="FILE" /&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>