Access journal log files within Docker Container using sd-journal API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I have a question. I am trying to read journald log files within a docker container on a host that is using systemd.
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.

I tried the following docker cmd:

docker run --rm --interactive --tty \
        --net host \
        --privileged \
        -v /run:/run \
        -v /var:/var \
        --mount type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup \
        --mount type=bind,source=/sys/fs/fuse,target=/sys/fs/fuse \
        myContainer:latest

When running my code inside this container, though, the log files are always empty.
Running the same code on my host machine correctly yields the log files.

I know that just mounting whole /var and --privileged are bad. This is just a proof of concept.
What am I missing to make this work?

In case its important, this is my code to read log files (library is go-systemd/sdjournal)

jr, err := sdjournal.NewJournalReader(sdjournal.JournalReaderConfig{})
if err != nil {
    return
}
buf := make([]byte, 1024)
n, err := jr.Read(buf)
if err != nil {
    if n > 0 {
        println(string(buf[:n]))
    }
    if err == io.EOF {
        println("EOF")
        err = nil
    }
    return
}
println(string(buf[:n]))

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.

Kind regards,

Sebastian

P.S.: This is my first message on this mailing list, sorry if I missed any rule or best practice.

_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux