A story stuck with log output in Docker + Play framework environment

This article is the 15th day of WebCrew Advent Calendar 2020. Yesterday was @ piwi's "I was worried when I created a site with private Nuxt.js (coder)".

Introduction

I'm usually a person doing server-side implementation. I have a chance to touch the front desk a little. Most recently, I'm doing scala, java, nuxtjs, etc. I couldn't come up with the right material, so recently I'll write about some problems with the environment settings and how to deal with them.

Log output and rolling settings

environment CentOS Docker + Playframework(scala) + Logback

Issue: When replacing a tool in a new environment, I want to set the log file output as part of the production / development environment settings.

Assumption: Log confirmation with stdout has already been done at the time of implementation. Log output is Logback (default)

First thing I did

--Change log file output settings in logback.xml --Added mount settings for output destination folder to docker-compose.yml ↓ Additions and changes (Note that the xml file before the change is almost the same as logback.xml that was automatically generated when it was initialized with the play framework)

logback.xml


  <property name="LOG_HOME" value="/home/appserver" />

  <appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_HOME}/logs/rolling_application.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- Daily rollover with compression -->
      <fileNamePattern>${LOG_HOME}/logs/application-log-%d{yyyy-MM-dd}.gz</fileNamePattern>
      <!-- keep 90 days worth of history -->
      <maxHistory>90</maxHistory>
    </rollingPolicy>
    <encoder>
      <pattern>%date{yyyy-MM-dd HH:mm:ss ZZZZ} [%level] from %logger in %thread - %message%n%xException</pattern>
    </encoder>
  </appender>

  <appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="ROLLING" />          <!--Change-->
  </appender>

  <root level="WARN">
    <appender-ref ref="ASYNCFILE" />        <!--Change-->
    <appender-ref ref="ASYNCSTDOUT" />
  </root>

docker-compose.yml


version: '3'

services:
  play-runtime:
    image: play-runtime:latest
    container_name: play-runtime
    restart: always
    ports:
      - "9000:9000"
    stdin_open: true
    volumes:                                <!--add to-->
      - ./logs:/home/appserver/logs         <!--add to-->

For confirmation, I tried setting the log rolling setting in minutes on my own PC to see if there was a problem. I checked the operation locally and there was no problem, so when I uploaded it to the development environment, the log was not output and I twisted my head. By the way, to separate files by minutes, fileNamePattern ends with % d {yyyy-MM-dd} to % d {yyyy-MM-dd-HH-mm}.

The problem that seems to have occurred

The corresponding log folder was created, but the file was not output. It is expected that the owner authority of the folder is a bottleneck, referring to the following article. By the way, in docker, a general user (user name appserver) is created to start the container and application. https://qiita.com/yohm/items/047b2e68d008ebb0f001

RUN groupadd --gid 1001 appserver \
 && useradd --gid 1001 --uid 1001 -m appserver

USER appserver 

Correspondence

Added a command to create a folder in Dockerfil.

RUN mkdir -p -m 777 /home/appserver/logs \              #add to
 && chown appserver:appserver /home/appserver/logs

I was able to confirm the log output safely. You may create it with the application startup script as in the reference article.

Correspondence that tried and did not work

For reference only.

Create a directory in Dockerfile before switching users → give ownership to general users I tried both chmod and chown, but when I checked the authority with exec after starting the container, only the root user was given possession / write authority and could not output the log.

Also, the reason why there was no problem in the local environment is that docker for mac seems to be able to improve the authority without permission, and in the same way, linux is not good for Mac environment! There was a person who wrote an article like this.

Tomorrow is @ ee4839! Thank you.

Recommended Posts

A story stuck with log output in Docker + Play framework environment
[Note] Build a Python3 environment with Docker in EC2
A story stuck with NotSerializableException
A story that got stuck with an error during migration in docker PHP laravel
Create a Vue3 environment with Docker!
Build a Node.js environment with Docker
Build a PureScript development environment with Docker
Edit Mysql with commands in Docker environment
Create a MySQL environment with Docker from 0-> 1
Play Framework 2.6 (Java) environment construction in Eclipse
Build a Wordpress development environment with Docker
I built a rails environment with docker and mysql, but I got stuck
I tried to build a Firebase application development environment with Docker in 2020
[Memo] Create a CentOS 8 environment easily with Docker
Self-hosting with Docker of AuteMuteUs in Windows environment
Build a Laravel / Docker environment with VSCode devcontainer
Prepare a scraping environment with Docker and Java
Handle JSON in cross domain with Play Framework
Create a Spring Boot development environment with docker
Points stuck when running vite + Nginx in Docker environment
Easily build a Vue.js environment with Docker + Vue CLI
[Note] Create a java environment from scratch with docker
Output true with if (a == 1 && a == 2 && a == 3) in Java (Invisible Identifier)
A story about introducing Evolutions into the Play Framework
Docker command to create Rails project with a single blow in environment without Ruby
Database environment construction with Docker in Spring boot (IntellJ)
Log output in Json format using lograge / lograge-sql with RubyOnRails
Install / run a standalone robot simulator in wsl2 / docker environment!
I made a development environment with rails6 + docker + postgreSQL + Materialize.
When there is no output to stdout in docker log
I searched for a web framework with Gem in Ruby
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I tried to create a padrino development environment with Docker
Pytorch execution environment with Docker
[Docker] Rails 5.2 environment construction with docker
React environment construction with Docker
Validation function in Play Framework
Install gem in Serverless Framework and AWS Lambda with Ruby environment
A funny story stuck in a mess when trying to import fx-clj
[Beginner] Procedure to log in to the virtual environment built with Vagrant
A solution to Docker errors that beginners tend to get stuck in
Can't output PDF in production environment (EC2, Amazon Linux) with Rails
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Prepare a transcendentally simple PHP & Apache environment on Mac with Docker
(For myself) Try creating a C # environment with docker + code-server, cloud9
Build a browser test environment using Capybara in the Docker development environment
I tried deploying a Docker container on Lambda with Serverless Framework
Build a development environment for Django + MySQL + nginx with Docker Compose
We will build a Spring Framework development environment in the on-premises environment.
A story that addresses the problem that REMOTE_ADDR cannot be acquired in a cluster built with Docker Swarm + Traefik (1.7).
Command line that can create a directory structure for building a Laravel environment with Docker in one shot
Node.js environment construction with Docker Compose
Deploy a Docker application with Greengrass
Build Couchbase local environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Environment construction with Docker for beginners
Build PlantUML environment with VSCode + Docker
Play Framework 2.6 (Java) development environment creation
Double submit measures with Play Framework
Build environment with vue.js + rails + docker
Create a database in a production environment