You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support nerdctl logs for the containers running without -d #1657
Support nerdctl logs for the containers running without -d
README.md already stated it is not supported yet. So opening a feature request instead of a bug report.
Reproducd by building source code from main branch.
$ sudo ./_output/nerdctl run -it ubuntu
# open a new terminal
$ sudo ./output/nerdctl ps # get the container id
$ sudo ./_output/nerdctl logs ccc97467def7
FATA[0000] failed to load logging config: failed to read log config file "/var/lib/nerdctl/1935db59/containers/default/ccc97467def7dd95330c6e872917e130180a1de2e4d6c34bdebeb16af434a5a6/log-config.json": open /var/lib/nerdctl/1935db59/containers/default/ccc97467def7dd95330c6e872917e130180a1de2e4d6c34bdebeb16af434a5a6/log-config.json: no such file or directory
Describe the solution you'd like
Add the feature to support logs command with the container running without -d.
When the container is run with -it(or without -d),log data is output to nerdctl process stdout.
If want to get logs through nerdctl logs, it may be necessary to copy the log to the log file(or other log drivers) in another goroutine.
I spent some time looking at this and based on what @ningziwen has already mentioned, I tried to create a multiwriter and create a ioCreator out of it but it's messy and didn't work primarily because uri.String() dir tree isn't setup yet or isn't the right path at the point of execution in NewTask.
@yzxiu when you say we need to copy the logs over explicitly, shouldn't that piece go into containerd? I'm new to this project so still trying to understand the demarcations. Sorry If I missed anything.
As per SCOPE.md which states that “Logging can be build on top of containerd because the container’s STDIO will be provided to the clients and they can persist any way they see fit. There is no io copying of container STDIO in containerd.” So this rules out modifying/creating the NewTask(context.Context, cio.Creator, ...NewTaskOpts) (Task, error) interface in containerd.This needs to be handled on the client side(i.e nerdctl) similar to what is done by cri plugin.
A proposal to solve this is for nerdctl to implement it's own cio.Creator which can start the logging binary process as and send stdout and stederr streams to it using pipes, i.e mimic the behavior of shim logging in the cio.Creator implementation.
sudo nerdctl run --name interactive alpine sh -c "echo hello"
hello
$ sudo nerdctl logs interactive
hello
$ sudo nerdctl run -it --name itty alpine
/ # ls
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/ # pwd
/
/ # exit
$ sudo nerdctl logs itty
/ # ls
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/ # pwd
/
/ # exit
cc @fahedouch@AkihiroSuda Let me know if this approach is okay and I can work on getting my PR merged. Thanks!
Activity
ningziwen commentedon Dec 15, 2022
/assign
ningziwen commentedon Dec 20, 2022
Trying error log tracing in
nerdctl logscommand.nerdctl logs -> log_viewer.InitContainerLogViewer() -> logging.LoadLogConfig()
The error is failed in
os.ReadFile(logConfigFilePath)withoutno such file or directoryThe logConfigFilePath is the log-config.json in current container's dataStore dir.
log-config.json's directory of the container running by
sudo ./_output/nerdctl run -it ubuntulog-config.json's directory of the container running by
sudo ./_output/nerdctl run -d ubuntuFound the line to write log-config.json.
ningziwen commentedon Dec 21, 2022
Just found this recent merged PR fixed the error. The log-config.json appears in the container ran by
nerdctl run -itnow.However, there is no log in the container ran by
nerdctl run -it.Ran
while true; do $(echo date); sleep 1; donein terminal of -it container. Thennerdctl logsreturns empty.Ran
sudo ./_output/nerdctl -d ubuntu sh -c "while true; do $(echo date); sleep 1; done", thennerdctl logsreturns printed date lines.yzxiu commentedon Dec 22, 2022
When the container is run with
-it(or without-d),log data is output to nerdctl process stdout.If want to get logs through
nerdctl logs, it may be necessary to copy the log to the log file(or other log drivers) in another goroutine.ningziwen commentedon Dec 22, 2022
Currently, -it uses the ioCreator to write stdOut to console.Current().
-d uses the ioCreator to write to uri.String().
AkihiroSuda commentedon Jan 28, 2023
@ningziwen Do you still plan to work on this?
ningziwen commentedon Jan 28, 2023
Yes but it will take some time. Feel free to take over if you have urgent need of this feature.
danishprakash commentedon Feb 15, 2023
@ningziwen I can work on this if it's okay.
ningziwen commentedon Feb 15, 2023
@danishprakash Sure go ahead.
danishprakash commentedon Feb 17, 2023
I spent some time looking at this and based on what @ningziwen has already mentioned, I tried to create a multiwriter and create a ioCreator out of it but it's messy and didn't work primarily because
uri.String()dir tree isn't setup yet or isn't the right path at the point of execution inNewTask.@yzxiu when you say we need to copy the logs over explicitly, shouldn't that piece go into containerd? I'm new to this project so still trying to understand the demarcations. Sorry If I missed anything.
fahedouch commentedon Feb 17, 2023
I tried to fix this here but stucked because of this <= containerd-dev slack thread
It looks like containerd io limitation
danishprakash commentedon Feb 17, 2023
I think this issue can be closed then in lieu of #1946
AkihiroSuda commentedon Feb 17, 2023
No, that one is a different topic
vsiravar commentedon Dec 5, 2023
As per SCOPE.md which states that “Logging can be build on top of containerd because the container’s STDIO will be provided to the clients and they can persist any way they see fit. There is no io copying of container STDIO in containerd.” So this rules out modifying/creating the
NewTask(context.Context, cio.Creator, ...NewTaskOpts) (Task, error)interface in containerd.This needs to be handled on the client side(i.e nerdctl) similar to what is done by cri plugin.A proposal to solve this is for nerdctl to implement it's own
cio.Creatorwhich can start the logging binary process as and send stdout and stederr streams to it using pipes, i.e mimic the behavior of shim logging in thecio.Creatorimplementation.I made draft PR: #2683 and ran some sanity tests
cc @fahedouch @AkihiroSuda Let me know if this approach is okay and I can work on getting my PR merged. Thanks!