Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect output of docker cron to stdout #2663

Closed
asbiin opened this issue May 9, 2019 · 5 comments
Closed

Redirect output of docker cron to stdout #2663

asbiin opened this issue May 9, 2019 · 5 comments
Labels

Comments

@asbiin
Copy link
Member

asbiin commented May 9, 2019

No description provided.

@Brice187
Copy link

Could you please specify this issue? i know some docker :)

@asbiin
Copy link
Member Author

asbiin commented May 21, 2019

Currently the only logs shown on docker logs comes from apache output.
I would like to output the logs from the 'cron' task on the docker logs too. I tried with redirecting the output on /dev/stdout but it's not working.

@asbiin asbiin added the docker label May 30, 2019
@pzl
Copy link

pzl commented Oct 24, 2019

So docker logs are listening to the stdout of process pid 1 in the container. Since that's what docker is primarily "executing" (even though other things can run in the container namespace, like cron). This is the important part. PID 1

When cron runs, it might be pid 5 or 7 or something. So writing to /dev/stdout from the cron process perspective, will be a symlink to it's own process's stdout. Same as just normally printing to stdout with > or echo or anything else. Here's a quick exercise to demonstrate:

$ ls -la /dev/stdout
lrwxrwxrwx 1 root root 15 Oct 18 21:52 /dev/stdout -> /proc/self/fd/1

We can see this goes to /proc/self/fd/1. Where the 1 here is not about PIDs, but rather that stdout is file descriptor number 1 (stdin is 0, stdout is 1, stderr is 2).

But /proc/self itself, is a symlinked directory.

$ ls -la /proc/self
lrwxrwxrwx 1 root root 0 Oct 18 21:52 /proc/self -> 306584

so /dev/stdout is really pointing to /proc/306584/fd/1, your current process's stdout (so for cron, cron's already existing stdout).

Docker is listening to /proc/1/fd/1 so you're welcome to print right to that.

@asbiin
Copy link
Member Author

asbiin commented Oct 25, 2019

Thanks @pzl ! I was able to fix this in #3129

@asbiin asbiin closed this as completed Oct 25, 2019
@github-actions
Copy link

github-actions bot commented Jan 9, 2021

This issue has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants