First of all, this scenario is not in a working production environment, so the operation is rather random, but I mainly want to introduce some things related to docker logs.
While running a project, I found that the business was not working properly, and then I wanted to see what errors the logs output.
[[email protected].io]# docker logs -f xxx
Surprisingly found no log content, which is rather confusing, because even if there are no errors, at least the startup information these or i should be there, so is the application not up?
First of all, I confirmed that the Docker Container is running normally, which is fine; then I looked at the port the application is listening on to see if it is running.
[[email protected].io]# ss -anlp | grep 222
tcp LISTEN 0 4096 127.0.0.1:2222 *:* users:(("server",pid=27069,fd=10))
The port is also listening, at least in the business to this step, then the application must be output logs, then the problem is at the infrature level.
Next, let’s see if Docker itself is abnormal, let’s look at the docker logs first.
[[email protected].io]# journalctl -xu docker
Journal file /var/log/journal/ae6603ff6b1849af8525fbf6688811fd/system.journal uses an unsupported feature, ignoring file.
Use SYSTEMD_LOG_LEVEL=debug journalctl --file=/var/log/journal/ae6603ff6b1849af8525fbf6688811fd/system.journal to see the details.
-- No entries --
As it turns out, the problem is with Docker’s own journal, which looks like it’s related to the journal, and then the good thing is that there are hints here, so you can look at.
[[email protected].io]# SYSTEMD_LOG_LEVEL=debug journalctl --file=/var/log/journal/ae6603ff6b1849af8525fbf6688811fd/system.journal
Journal effective settings seal=no keyed_hash=yes compress=no compress_threshold_bytes=8B
Journal file /var/log/journal/ae6603ff6b1849af8525fbf6688811fd/system.journal uses incompatible flag xz-compressed disabled at compilation time.
Failed to open journal file /var/log/journal/ae6603ff6b1849af8525fbf6688811fd/system.journal: Protocol not supported
mmap cache statistics: 0 hit, 1 miss
Failed to open files: Protocol not supported
OK, the problem here looks like I recompiled systemd (CentOS7 upgrade systemd 242/243 ), and then it looks like I missed some compression options, so I need to recompile systemd.
docker logging configuration
I found the reason why Docker’s own logging was not working, but why was the container not logging, so I had to look at the logging configuration in docker, and after some searching I determined that it was here.
[[email protected].io]# grep -ir log /etc/sysconfig/docker
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
# Controls the /etc/cron.daily/docker-logrotate cron job status.
It turns out that the default docker log uses journal logs, so journal logs are not available, and docker’s own logs are not viewable. So now, in addition to solving the journal logging problem, you can also look at other logging drivers supported by docker (Driver list supported-logging-drivers). Then you may want to try it by selecting Local logging first.
After checking the documentation, I found that instead of modifying the global configuration, it was possible to modify the configuration of a single container, so I ran a
[[email protected].io]# docker run \
--log-driver local --log-opt max-size=10m \
alpine echo hello world
/usr/bin/docker-current: Error response from daemon: logger: no log driver named 'local' is registered.
See '/usr/bin/docker-current run --help'.
However, the reality is that the run failed, and then I looked at the detailed description in the documentation and found no special instructions, but after looking at my docker version, I found that it was already very old, so I simply upgraded to the latest version 20.10.5 and found that the docker logs were back to normal.
This article is pretty much like this, not too many amazing things, but for the processing of docker logs really did not pay too much attention before, this time is also considered a posture up. The official documentation says that if you don’t set the rotate of log, it won’t clean up the log by default, so you need to pay attention to it yourself.