[英]Can't use `systemd-cat` inside Docker container
I am trying to test logging to journald
from inside my container. 我想测试记录到journald
从我的容器内。 I want this to work inside a container since our build system runs inside a container. 我希望它在容器内工作,因为我们的构建系统在容器内运行。 I need to test a script that uses journalctl
and I need to generate output for it to parse. 我需要测试一个使用journalctl
的脚本,并且需要生成用于解析的输出。 The test script needs to run in the container. 测试脚本需要在容器中运行。
I am launching my container like this: 我正在这样启动我的容器:
$ docker run --rm -it -v $(pwd):/home/edge -w /home/edge --log-driver=journald ubuntu /bin/bash
root@78b56defde31:/home/edge# systemd-cat -t overflow ls /etc
Failed to create stream fd: No such file or directory
If I run the same command in the Debian host it works: 如果我在Debian主机中运行相同的命令,它将起作用:
$ systemd-cat -t overflow ls /etc
$ sudo journalctl | grep overflow
Nov 01 08:09:53 nanode64 overflow[9037]: acpi
Nov 01 08:09:53 nanode64 overflow[9037]: adduser.conf
Nov 01 08:09:53 nanode64 overflow[9037]: adjtime
Nov 01 08:09:53 nanode64 overflow[9037]: aliases
Nov 01 08:09:53 nanode64 overflow[9037]: alternatives
Nov 01 08:09:53 nanode64 overflow[9037]: anacrontab
Nov 01 08:09:53 nanode64 overflow[9037]: apache2
Nov 01 08:09:53 nanode64 overflow[9037]: apg.conf
Nov 01 08:09:53 nanode64 overflow[9037]: apm
Nov 01 08:09:53 nanode64 overflow[9037]: apt
...
There is nothing running inside your container other than bash
. 除了bash
之外,容器中没有其他东西在运行。 There is no journald
running inside the container, and thus no socket for systemd-cat
to communicate with. 容器内部没有运行journald
,因此没有套接字与systemd-cat
通信。 I suspect that your attempt to use systemd-cat
may stem from a misunderstanding of how the journald
log driver works. 我怀疑您尝试使用systemd-cat
可能是由于journald
日志记录日志驱动程序的工作方式有误解。
You're using Docker's journald
logging driver, which means that anything output by your container to stdout/stderr will show up in your host journal. 您使用的码头工人journald
记录的驱动程序,这意味着你的容器到stdout / stderr输出任何东西会在你的主机日志显示出来。 That is, if you were to run: 也就是说,如果您要运行:
docker run --rm -v $(pwd):/home/edge -w /home/edge --log-driver=journald ubuntu echo this is a test
You would, on the host, see: 您将在主机上看到:
# journalctl -fl
...
Nov 01 11:45:08 lkellogg-pc0dzzve dockerd[3736]: this is a test
...
If you were to show that message using -o verbose
you would see that it actually contains a variety of additional metadata, such as the container id and container name: 如果使用-o verbose
显示该消息,则会看到它实际上包含各种其他元数据,例如容器ID和容器名称:
# journalctl -fl -o verbose MESSAGE='this is a test'
Wed 2017-11-01 11:48:02.002147 EDT [s=9a99c0d26c3548a2ba6a6416bc37094c;i=15c9cce1;b=3f2b2d45203c485f9fa4373148c81925;m=219ad310e0d;t=55cedcbef19b3;x=6f1641d7b8ebf7ee]
PRIORITY=6
_TRANSPORT=journal
_UID=0
_GID=0
_SYSTEMD_SLICE=system.slice
_BOOT_ID=3f2b2d45203c485f9fa4373148c81925
_MACHINE_ID=229916fba5b54252ad4d08efbc581213
_HOSTNAME=lkellogg-pc0dzzve
_CAP_EFFECTIVE=3fffffffff
_PID=3736
_COMM=dockerd
_EXE=/usr/bin/dockerd
_CMDLINE=/usr/bin/dockerd -G docker --dns 172.23.254.1 --log-driver journald -s overlay2
_SYSTEMD_CGROUP=/system.slice/docker.service
_SYSTEMD_UNIT=docker.service
_SELINUX_CONTEXT=system_u:system_r:unconfined_service_t:s0
MESSAGE=this is a test
CONTAINER_ID=5d20a635fcff
CONTAINER_ID_FULL=5d20a635fcff5c57212a65d5d0ebd77f3fd9529a8fd4fe6b718238877ecf5173
CONTAINER_NAME=optimistic_easley
CONTAINER_TAG=5d20a635fcff
_SOURCE_REALTIME_TIMESTAMP=1509551282002147
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.