Hello everyone, I am new to Docker. I have a question here and hope I can get some help.
I have a spring boot project with slf4j logging API for logging. In my logback.xml, I configured so that a log file app.log should be generated in c:\tmp on-fly.
When I run this project from IntelliJ or command line, I can see the log file app.log is generated successfully in c:\tmp. Then, I built a docker image for this project. I ran the docker image with this command: $docker run -p 8080:8080 -t myProject
The image also runs very well, but I can no longer see app.log in c:\tmp. Does anybody know how to log into a log file with docker? Thank you very much!
Are you looking at the c:\tmp of your host? You would have to look inside your container for the log file, unless you already set mounted volumes.
By default, the container and therefore its process won’t write outside of this container. Also, make sure that whichever path you choose for the logging existing in the container. Meaning, c:\tmp exists on your host, but does it exists in the container?
You have a few choices:
docker exec into the container and look for your log file
use volumes to let the container write to a folder which is actually on the host
log to stdout/stderr and grab that output somehow (via log shipping or by attaching a tty to the container)
Hi Alexandre, thank you very much for the reply. It is very helpful. Actually, yesterday after i posted the question, I did some more research and guessed some reason that was confirmed by your reply. I am now looking into the docker logging drivers to send my logging info into Logstash. Do you recommend syslog or gelf?
Syslog is in my opinion the easiest, but I’ve heard good things about gelf. I guess it depends how familiar you are with each and how much time you want to invest into this.
I need to create a SLF4J log file for my microservices and no luck so far. It would be great if you suggest me or provide sample for me for creating log file in docker environment. My docker running on Windows for DEV and Linux for PROD.