Nagev
Nagev

Reputation: 13285

How to start syslogd in nginx container

I'm using an Nginx docker container as base image for an application. I'm redirecting Nginx logs to syslog but I'm not sure what is the best way to have the busybox syslogd started. It all works if I start it manually, I just need it to run as a daemon automatically when the container runs.

Seeing that nginx is in init.d I tried this in my Dockerfile:

RUN ln -s /bin/busybox syslogd /etc/init.d/syslogd || :

But syslogd still didn't run on start-up. Since the documentation says that only one [CMD] is allowed I have the following hack:

FROM nginx:mainline-alpine
CMD nginx & busybox syslogd -n

This works, locally at least, but I'm wondering what is the proper solution. By default the container already symlinks log files to stdout and stderr but I don't want to use docker's syslog logging driver, because the application will be deployed to Kubernetes so I need a self-contained solution, that will work in the pod. Thank you!

Upvotes: 1

Views: 1907

Answers (1)

David Maze
David Maze

Reputation: 159750

Have your container log to stdout, but collect the logs elsewhere.

One option is to configure Docker itself to send container logs to syslog:

docker run --log-driver=syslog --log-opt syslog-address=udp://... ... nginx

Since the Docker daemon itself is configuring this, the syslog-address needs to be something that can be reached from the host. If you're running syslogd in a separate container, this option needs to point at a published port.

Another option is to use the standard Docker JSON-format logging, but use another tool to forward the logs to somewhere else. This has the downside of needing an additional tool, but the upside of docker logs working unmodified. Fluentd is a prominent open-source option. (Logstash is another, but doesn't seem to directly have a Docker integration.)

Upvotes: 3

Related Questions