How to setup local syslog-ng in docker container o

2019-06-07 16:31发布

问题:

I want to isolate a testing environment in docker, I did that on CentOS 6 How to let syslog workable in docker?

In CentOS 7, the syslog-ng's configuration is different, when I run

/usr/sbin/syslog-ng -F -p /var/run/syslogd.pid 

It appears the following error message, but there is no proc/kmsg in config files.

syslog-ng: Error setting capabilities, capability management disabled; error='Operation not permitted' 
Error opening file for reading; filename='/proc/kmsg', error='Operation not permitted (1)'

The Dockerfile

FROM centos
RUN yum update --exclude=systemd -y \
  && yum install -y yum-plugin-ovl \
  && yum install -y epel-release
RUN yum install -y syslog-ng syslog-ng-libdbi

The test process:

docker build -t t1 .
docker run --rm -i -t t1 /bin/bash

In container, run following commands

# check config, no keyword like proc/kmsg
cd /etc/syslog-ng
grep -r -E 'proc|kmsg'

/usr/sbin/syslog-ng -F -p /var/run/syslogd.pid 

回答1:

Change /etc/syslog-ng/syslog-ng.conf from

source s_sys {
  system();
  internal();
};

to

source s_sys {
  unix-stream("/dev/log");
  internal();
};

It still show error message, but running instead of exit

syslog-ng: Error setting capabilities, capability management disabled; error='Operation not permitted' 

To solve this, just run with --no-caps option

/usr/sbin/syslog-ng --no-caps -F -p /var/run/syslogd.pid