My Docker container produces multiple application logs.
docker logs command only shows the app startup logs. Is there a way to redirect the other log files so they are shown by the docker logs command?
EDIT:
I'm using the WebSphere traditional docker image. Docker logs only shows the startServer.log but there are other logs like SystemOut.log ....
We need more information, like which application, your Dockerfile, etc.
As a general answer you must have an entry point script which will send your application log to stdout:
runapp &
tail -f logfile
Something like that.
Regards
docker logs will display all the stdout and stderr from the application running in the container. Configure the application to log to stderr instead of a log file and the logs will be visible from docker logs.
Related
This is the command to check the docker container logs(info level by default) live:
docker logs -f CONTAINER_ID
But what if I want to check the live debug logs which I have logged in my code at debug level?
This is the command to check the docker container logs(info level by
default) live:
docker logs -f CONTAINER_ID
Not really, docker logs CONTAINER_ID doesn't cope with verbosity level.
It simply output the container STDOUT and STDERR.
But what if I want to check the live debug logs which I have logged in
my code at debug level?
That is a very good question.
You could statically (via configuration file) configure your logger appender to write to stdout for all logs (debug and above).
But as side effect, it will log always with that level. For a simple test, it is fine but for a long time running container it may be annoying.
In that case, a dynamic approach to set the logger level is be better (a basic rest controller may very well do the job).
And in that way docker logs -F CONTAINER_ID will output more or less logs according to the current level.
You can run the container in foreground mode so you will able to see log.
docker run -it --rm my_node_app
-it keep the container running in foreground as a result you will able to see your container logs.
You will able to see live logs same like running application in terminal.
But what if I want to check the live debug logs which I have logged in
my code at debug level?
The container output logs totally depend upon the stdout/stderr of the main process that is defined in CMD.
You can filter Debug logs from the log output, as docker does not know the logs format it just print the logs which is available in the form of stdout/stderr.
You can try
docker logs -f container_id | grep "Debug"
If the logs formate contains debug or similar pattern.
I am using tomcat:9.0-jre8-alpine image to deploy my application. when i run the below command it works perfectly and displays logs.
docker logs -f <containername>
but after a few hours logs gets struck and whatever the operation we do on the application it does not display new logs. Container is running as expected and there is enough ram and disk space on the VM.
Note: I run the same container on 3 different VMs. Only 1 VM has this problem.
How can I debug/resolve the issue?
check you docker version, is it too old that you may meet
https://github.com/moby/moby/issues/35332 It's a dead lock caused by github.com/fsnotify/fsnotify pkg. fsnotify PR
check the daemon config in /etc/docker/daemon.json for docker log configuration.
and you need to check container configuration with docker inspect to see the log options.
Sometimes I try to look into the /var/lib/docker/containers/Container-ID/Container-ID.json to see the log if you use json-file log format.
If you use journald, you may find the log in /var/log/messages
I have 2 nodes, 1 manager and 1 worker. Worker has around 15 spring boot services. All the services seem to be running fine when we use the UI to test the application. However when I am trying to check the logs using the docker service logs nothing is printed. When I ssh into the worker and try to check logs for individual images the logs are not printed. However when I ssh into the running container I can see a log folder with the generated logs.
This was working a couple of days back. We just redeployed some images and had to scale images from 1 to 0 and back to 1 instances. Not sure why the logs are not printed? Any hints on how we can debug or fix this?
The command docker logs <container> only outputs STDOUT and STDERR. You need to configure your logs to push to one of these. Read more about it here https://stackoverflow.com/a/36790613/10632970
Can I be able to audit log the processes inside the docker in global log events so that process inside the docker?
What are the changes to be provided to include the log events of docker to be viewed in global?
Docker currently only provides log access to single containers.
docker logs <container>
However there are solutions like the ELK-Stack for centralized logging. See this description.
You can use Sysdig to see all logs:
$ sudo sysdig -pc -cspy_logs
When I start my docker daemon with service docker start or docker -d, I usually get my shell terminal. But when there's docker daemon log need to be output, log is printed directly on my screen and I lost my shell terminal. I press ENTER and get shell terminal again. I don't want this. Printing docker daemon log into log files will be better to me. How to print my docker log into logfiles rather than STDOUT?
Unix has a concept of 'redirection', so you can ask stdout to go to a file instead using a command like this:
docker -d > my_logfile
(you would probably also want to redirect stderr)
Now,a more complicated version of this is exactly what the docker service startup script does:
start-stop-daemon [...] >> "$DOCKER_LOGFILE" 2>&1
so I'm not sure why you are seeing output to your terminal if you use that route.