how to centralized log file on docker container?

2/15/2016

How to centralized log file on docker container?

This log file is not in /var/lib/docker/container/*/

This log file is like catalina.out or another log file in container. (this file can be stdout/err or not).

Many solution is almost about stdout/err( /var/lib/docker/container/* ).

But I want to centralized log file in container to use ELK or Fluentd.

Help me please.

-- 2blikeCaesar
containers
docker
kubernetes

1 Answer

2/15/2016

You could use a forwarder container inside your pod and share a volume for the log directory, as follows:

kind: ReplicationController
apiVersion: v1
metadata:
  name: tomcat
  labels:
    app: tomcat
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: tomcat
    spec:
      containers:
      - name: tomcat
        image: tomcat
        volumeMounts:
        - name: tomcat-logs
          mountPath: /tomcat/log
          readOnly: false
      - name: logstash-forwarder
        image: apopelo/logstash-forwarder
        volumeMounts:
        - name: tomcat-logs
          mountPath: /var/log/tomcat
          readOnly: true
      volumes:
      - name: tomcat-logs
        emptyDir: {}

The tomcat container runs the app, while logstash-forwarder forwards tomcat logs.

-- Antoine Cotten
Source: StackOverflow