5

I have a small node script wherein I use bunyan to handle application logging. The logger writes to local storage. I'd like to send the logs to elasticsearch using filebeat (both of which are new tech to me).

I've made a dockerfile that containerizes the app (below), but I'm unsure how/where to insert the necessary instructions. Is there a way to send my logs to elasticsearch from within the docker? And while I'm at it, also send whatever logs the docker container & os emit?

# dockerfile. 
# installations and entrypoint are to run nightmarejs headless
FROM node:latest

RUN apt-get update &&\
    apt-get install -y libgtk2.0-0 libgconf-2-4 \
    libasound2 libxtst6 libxss1 libnss3 xvfb

WORKDIR /app
COPY ./dist .

# enable installation of private npm modules
ARG NPM_TOKEN  
COPY .npmrc .npmrc  
COPY package.json .
RUN npm i
RUN rm -f .npmrc
COPY entrypoint /
RUN chmod +x /entrypoint
ENTRYPOINT ["/entrypoint"]

CMD DEBUG=nightmare node ./app.js

and for completeness' sake, entrypoint.js:

#!/usr/bin/env bash
set -e

# Start Xvfb
Xvfb -ac -screen scrn 1280x2000x24 :9.0 &
export DISPLAY=:9.0

exec "$@"

if it matters, I'll be deploying the container to a service where I won't have ssh access to the os.

[ETA: a lot of answers already cover how to grab docker logs from outside of the container--eg, running filebeat in a separate container. I'm hoping to run it within the same container, though]

Brandon
  • 7,736
  • 9
  • 47
  • 72
  • check [this](http://stackoverflow.com/a/24629857/2586595) – Mohsen ZareZardeyni Nov 27 '16 at 05:57
  • Maybe this tutorial helps: http://eembsen.github.io/2015/12/05/docker-es-filebeat/ . Basically you have to config filebeat to read log from local storage (should be the place your application store the logs). To collect "whatever logs the docker container & os emit", you may have to config your container and app to output all logs to stand solution like stdout, then use some tools to collect log from stdout. – Haoming Zhang Nov 27 '16 at 06:14
  • 1
    thanks all. I think both of those solutions assume the `filebeat` is running _outside_ of the dockerized app, but I was hoping to keep the filebeat process _and_ the app within the same docker container. But beyond that, it looks like both those solutions deal with capturing the logs that the docker container emits. how can I insert my application's logs into that stream? do i have to write them to a specific directory within the docker, and then let the docker handle them alongside the logs it emits? Or do I have to use `stdout`? – Brandon Nov 27 '16 at 14:47
  • @Brandon Could you please "at" the person whose you want to reply next time? So the person could got a notification...You can put filebeat in either a independent container or the same container with your app, as long as you config the filebeat to check the correct log directory. To capture the logs of your app, you can mount a container volume to your app container, and let your app write logs to this volume, then let filebeat to read the log directory from this volume. Or you can use stdout with other tools. Processing container log is hard, so good luck... – Haoming Zhang Nov 28 '16 at 05:33

0 Answers0