Logs file is empty in spring boot application docker container

I have a spring-boot application running inside a docker container & its working fine. But the thing is application log file is empty inside the docker container. In logback-spring.xml log path has been configured to /var/log. When I go to /var/log directory inside the docker container, I can see log file has been created like “myservice.log” but when I “cat” the file to see the content, that is completely empty. Also when I execute

**docker logs <container-id>**

it returns nothing.

And also I checked the docker root directory in the server.

**/apps/docker/containers/<container-id>/<container-id-json.log>**

that is also empty.

my Dockerfile has the following structure.

**From private-docker-repo/openjdk:11-jre-slim**

**WORKDIR /opt/services**

**COPY target/my-service-0.0.1-SNAPSHOT.jar /opt/services/my-service.jar**

**CMD java -Dspring.profiles.active=dev -Dserver.port=61016 -jar my-service.jar**

**EXPOSE 61016**

What can be the reason for being the log file is empty here. Highly appreciate if anyone can point me out.

Edit - when I deploy the same jar using a linux systemd service logs are just writing fine. I want to know why the same jar not printing any logs inside the docker container

Thanks in advance…!

Your logging framework needs to log to STDOUT and STDERR in order to be shown by docker logs.

So if I understand you correctly the problem is that you don’t have logs inside the container not just that docker logs whows you an empty result.

@meyay is right about docker logs, but if your application log is empty too that is an erro that you should look for at application level. Maybe you don’t close the log files properly or have wrong variables so you write empty string into the log file, or you create the log file and write the content to an other. Unfortunately we can’t help you with that.

The reason could alos be something Docker-related but since I don’t use spring-boot based on the information you shared I can’t see any sign of that.

I think Tomcat would show something on standard output and error stream even if your app log doesn’t work so you would see something as a result of docker logs but I don’t know about spring boot.

I can only link this guide if it helps:
https://spring.io/guides/gs/spring-boot-docker/