<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello,</p>
<p>I have a question. I am trying to read journald log files within
a docker container on a host that is using systemd.<br>
Inside the container, systemd is NOT running. I want to use a
library that uses the sd-journal API to read the logs within the
container.<br>
</p>
<p>I tried the following docker cmd:</p>
<p><i>docker run --rm --interactive --tty \</i><i><br>
</i><i> --net host \</i><i><br>
</i><i> </i><i>--privileged \</i><i><br>
</i><i> </i><i>-v /run:/run \</i><i><br>
</i><i> -v /var:/var \</i><i><br>
</i><i> --mount
type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup \</i><i><br>
</i><i> --mount
type=bind,source=/sys/fs/fuse,target=/sys/fs/fuse \<br>
myContainer:latest<br>
</i></p>
<p>When running my code inside this container, though, the log files
are always empty.<br>
Running the same code on my host machine correctly yields the log
files.</p>
<p>I know that just mounting whole /var and --privileged are bad.
This is just a proof of concept.<br>
What am I missing to make this work?</p>
<p>In case its important, this is my code to read log files (library
is go-systemd/sdjournal)</p>
<p><i>jr, err :=
sdjournal.NewJournalReader(sdjournal.JournalReaderConfig{})</i><i><br>
</i><i>if err != nil {</i><i><br>
</i><i> return</i><i><br>
</i><i>}<br>
buf := make([]byte, 1024)<br>
n, err := jr.Read(buf)<br>
if err != nil {<br>
if n > 0 {<br>
println(string(buf[:n]))<br>
}<br>
if err == io.EOF {<br>
println("EOF")<br>
err = nil<br>
}<br>
return<br>
}<br>
println(string(buf[:n]))</i></p>
<p>I also tried to supply the path to the log dir:
"/var/log/journal/<machine-id>" in the reader conf, but the
result was the same.<br>
<i></i></p>
<p>Kind regards,</p>
<p>Sebastian</p>
<p>P.S.: This is my first message on this mailing list, sorry if I
missed any rule or best practice.<br>
</p>
</body>
</html>