How to stream some logs over TCP from rsyslog in Docker?

STF asked:

I need a very simple thing (for an integration test of a larger system, orchestrated by docker-compose): to setup a Debian based Docker image with rsyslog inside, so that when it is run, rsyslog will emit some syslog messages over TCP to another machine (container). How do I do this?

I know Dockerfile, the question is about rsyslog configuration and how do I generate some syslog messages? Ideally if they could be predefined (to match them at the other end of the integration test).

I just tried adding the following line:

*.* @@remote-machine

at the end of /etc/rsyslog.conf inside my Docker image, but then apparently I get no message. Is the configuration wrong? Is the TCP port 514 assumed here? Or is there just no syslog message available when I run this container using docker-compose?

My Dockerfile looks like:

FROM debian:10.4

RUN apt-get update && apt-get -y upgrade
RUN apt-get -y install rsyslog

# ... modify /etc/rsyslog.conf :
#   - append the *.* @@remote-machine line (see above)
#   - disable imklog which is causing errors

ENTRYPOINT ["/etc/init.d/rsyslog"]
CMD ["start"]

Thanks!

My answer:


You can use the logger command to create arbitrary syslog messages. For example:

logger --server 172.17.0.2 --priority local7.info --tag TEST Sample log message

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.