Public | Automated Build

Last pushed: 5 months ago
Short Description
Dockerized Fluentd Log Server
Full Description

Dockerized Fluentd

Dockerized Fluentd can be used by Docker Logging Driver or simply attached to logs!

Supported tags and respective Dockerfile links

Leave a message and ask questions on Hipchat: blacklabelops/hipchat

Bundle Version Tags Dockerfile Readme Example
Fluentd latest latest Dockerfile Readme blacklabelops/fluentd:latest
Loggly latest loggly Dockerfile Readme blacklabelops/fluentd:loggly

Make It Short

  1. In short, this container can be simply run as a docker log driver server:
$ docker run -d \
    -p 24224:24224 \
    -e "FLUENTD_SOURCE_TCP=true" \
    --name fluentd \

Fluentd will be now accessible as a logging driver server.

Now run your docker container and log to fluentd

$ docker run -d -p 80:8080 \
        --log-driver=fluentd \
      --name jenkins \

Will start an example Jenkins Server

View your logs by running:

$ docker logs fluentd

Running Behind a Firewall

If you expose the port with -p 24224:24224 it will be accesible on the internet. You can restrict this with -p

$ docker run -d \
        -p \
        -e "FLUENTD_SOURCE_TCP=true" \
        -e "FLUENTD_OUTPUT_STDOUT_PATTERN=docker.**" \
        --name fluentd \

Will only be accessible by local docker installation

Docker Log Driver Parameters

Read this documentation on available options: Fluentd logging driver

Attaching Fluentd To Logfiles

  1. In short, this container can collect all logs from your complete docker environment. Just by running:
$ docker run -d \
    -v /var/lib/docker/containers:/var/lib/docker/containers \
    -v /var/log/docker:/var/log/docker \
    -v $(pwd)/logs:/opt/fluentd/logs \
    -e "TAIL_LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \

Mounts the docker system logs and attaches to all log files in the respective directories. The output will be written inside the
current folder under /logs.

Now list the log files:

$ ls logs/

How To Attach Containers and Logs

In order to attach the side-car container to your logs you have to put your container's log inside
Docker volumes. Simply add -v /var/log to your container's run command.

Here's an example with my blacklabelops/jenkins container:

$ docker run -d -p 8090:8080 \
  -v /var/log \
  --name jenkins \

Container logs to /var/log/jenkins.log.

Now attach the container simply by mounting it's volume. The container attaches by default to any file ending with .log inside the folder /var/log

$ docker run -d \
  --volumes-from jenkins \
  --name fluentd \

Now grab logs by typing docker logs fluentd

You should find something like this inside your log:

$ docker logs fluentd
2015-07-24 18:53:44 +0000 [info]: plugin/in_tail.rb:477:initialize: following tail of /var/log/jenkins.log

Log File Pattern

Log file pattern with the ability to define file patterns.

$ docker run -d \
  --volumes-from jenkins \
  -e "TAIL_LOGS_DIRECTORIES=/var/log" \
  --name fluentd \

Attaches to all files inside those folders

Customize Log Folder

You can define your own log folders. The container will by default crawl for
files ending with .log. log folder have to be separated by empty spaces. This is useful when you mount volumes from several containers.

$ docker run -d \
  --volumes-from jenkins \
  -e "TAIL_LOGS_DIRECTORIES=/var/log /jenkins" \
  --name fluentd \

Will crawl for log files inside /var/log and /jenkins

Customize Log File Ending


Customize Log File Format

You can customize the file fomat. The container will by default use the format none. This can be overriden by
the parameter LOG_FILE_FORMAT:

$ docker run -d \
  --volumes-from jenkins \
    -e "TAIL_LOG_FILE_FORMAT=none" \
  --name fluentd \

This parameter will be set for ALL logfiles. For more formats and regexes check the Fluentd Documentation.

Pos Files

Pose Files will be written to Docker Volume /opt/fluentd

How To Customize the Log

This container is using the fluentd file Output plugin in order to write the aggregated logfiles.

The full documentation can be found here: file Output Plugin

You can override parameters with the following environment variables, see the plugin documentation for valid values:

  • TAIL_FILE_LOG_PATH corresponds to plugin parameter path.
  • TAIL_FILE_LOG_TIME_SLICE_FORMAT corresponds to plugin parameter time_slice_format.
  • TAIL_FILE_LOG_TIME_SLICE_WAIT corresponds to plugin parameter time_slice_wait.
  • TAIL_FILE_LOG_TIME_FORMAT corresponds to plugin parameter time_format.
  • TAIL_FILE_LOG_FLUSH_INTERVAL corresponds to plugin parameter flush_interval.
  • TAIL_FILE_LOG_COMPRESS corresponds to plugin parameter compress
  • TAIL_FILE_LOG_APPEND corresponds to plugin parameter append
  • TAIL_FILE_LOG_FORMAT corresponds to plugin parameter format

Full example:

$ docker run -d \
    -v /var/lib/docker/containers:/var/lib/docker/containers \
    -v /var/log/docker:/var/log/docker \
    -v $(pwd)/logs:/opt/fluentd/logs \
    -e "TAIL_LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
    -e "TAIL_FILE_LOG_PATH=/opt/fluentd/logs/container" \
    -e "TAIL_FILE_LOG_TIME_FORMAT=%Y-%m-%d-%H-%M-%S" \
    -e "TAIL_FILE_LOG_COMPRESS=true" \
    -e "TAIL_FILE_LOG_APPEND=true" \
    -e "TAIL_FILE_LOG_FORMAT=out_file" \

Logs all docker logs with the specified plugin parameters.

How To Extend This Image

Use this Dockerfile template:

FROM blacklabelops/fluentd

#Install plugins and tools
RUN gem install ...

#Put some config to include
COPY your-config-file /opt/fluentd/conf.d/yourconf.conf

# disable file logging from base container

WORKDIR /opt/fluentd
COPY /your/locations/
ENTRYPOINT ["/bin/tini","--","/your/locations/"]
CMD ["fluentd"]

Write your entrypoint like this:


# your instructions

# Invoke entrypoint of parent container
if [ "$1" = 'fluentd' ]; then
  exec /opt/fluentd/ $@

exec "$@"


Vagrant is fabulous tool for pulling and spinning up virtual machines like docker with containers. I can configure my development and test environment and simply pull it online. And so can you! Install Vagrant and Virtualbox and spin it up. Change into the project folder and build the project on the spot!

$ vagrant up
$ vagrant ssh
[vagrant@localhost ~]$ cd /vagrant
[vagrant@localhost ~]$ ./scripts/

Will build the container from source.

Vagrant does not leave any docker artifacts on your beloved desktop and the vagrant image can simply be destroyed and repulled if anything goes wrong. Test my project to your heart's content!

First install:


Docker Pull Command
Source Repository