How to make containerd forward logs to journald - docker

I am using k8s where I am using containerd as CRI.
How to make containerd forward logs to journald ?
Which and what configuration i must do ?

This is alerady the case, nothing to do.
You can get the logs using:
journalctl -u containerd

Related

Program in docker logging with syslog does not generate log files

I am using a centos 7.9 for my docker. I'm running a C++ program in my docker image which writes logging via syslog.
However, I cannot find these log anywhere when I run it in docker. On my centos machine, the logging would by default go to /var/log/messages, but on docker /var/log/messages is empty. I've tried setting the docker logging driver to syslog (in the docker run command) and I can see rsyslogd running in the docker container as well with ps -aux.
On my host machine, /var/log/syslog does not receive the logs either.
How do I get the log files to write to the /var/log/messages on the docker environment (or to my host machine, if storing them on the docker environment is not advisable)?
Thanks.
Since docker does not support systemd, it's very likelly that syslog is not running on your container
My suggestion is... start a shell at your container
make sure syslog is installed using
yum list --installed
or
rpm -qa
Them run the syslog daemon from the shell manually
after that, start a new terminal and run your code
ps: since I'm on my phone, i can't be more helpful
I'll try to edit it as soon as possible

Docker logs with log-driver

I am running a new container using the following command:
docker run -d --log-driver=gelf --log-opt gelf-address=tcp://<my_log_server> nginx
Looking at the documentation, this should send the logs to my_log_server, and if I run the docker logs <my_container> command I shoult NOT see any logs.
But actually I do, and I don't want this.
Do you have any idea why this is happening?
I'm testing it with Docker version 20.10.8, build 3967b7d
According to the docker documentation - https://docs.docker.com/config/containers/logging/configure/
When using Docker Engine 19.03 or older, the docker logs command is only functional for the local, json-file and journald logging drivers. Docker 20.10 and up introduces “dual logging”, which uses a local buffer that allows you to use the docker logs command for any logging driver. Refer to reading logs when using remote logging drivers for details.
Hope it clarifies.

Does docker log-level impact logging driver or only logs of docker daemon?

I have my logging driver setup of journald. Does the log-level config in daemon.json file impact logs when using a logging driver or only the container logs when using docker logs <container_name> ?
For example, docker and journald have documentation showing how to set log level/priority.
Docker's default setting is info: log-level: info.
With journald I can also use -p to set the log priority to info: journalctl -p info.
If my docker logging driver is journald with log priority set to info, do I even need to worry about setting log-level to info in daemon.json file?
I think maybe you confused the following concepts: logs of docker daemon, logs of container(s) and logs print with journalctl command.
The configuration in docker.json file impact logs of docker
daemon.
The logs of container(s) would be only impacted by your application
configuration in that container.
The command journalctl -p ONLY impact the logs showing on your
screen, which means -p only do the filtering thing. No matter what
level you've indicated, err or info, the logs are there already.
Hope this would be helpful.

See instance journalctl logs in docker container

I want to be able run docker container and see all instance journalctl logs.
In other words I want to see the same output of journalctl logs in Instance and in Docker container.
I was trying to mount the journald socket but still I don't see the journal logs from the instance
Thanks for the help.
If journalctl -u <service>.service and not giving you the journal logs you want from your container, you can run machinectl -l to find the container's UUID and then run a journalctl -M $UUID on the container uuid to see logs.
~# machinectl -l
MACHINE CLASS SERVICE OS VERSION ADDRESSES
rkt-6d427a1c-6961-45a2-a055-721edddb8558 container rkt - - -
~# journalctl -M rkt-6d427a1c-6961-45a2-a055-721edddb8558
If your systemd service starting your docker container is not listed under machinectl list, then add the following to your systemd service file that is starting your container:
[Service]
Slice=machine.slice
Cheers!

configure syslog in Docker to write container logs into a file

I try to use syslog as driver to collect logs
using following command:
docker run --log-driver syslog --log-opt syslog-address=udp://localhost:514 --log-opt tag=expconf app-1
Where does the syslog write this log?
I want the logs to be written into a specific file/ location. How to achieve this?

Resources