I am a beginner for docker implementation, I have created a simple "hello world" example to test my docker,
package com.example.demo;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class DockerTestingApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(DockerTestingApplication.class, args);
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
Logger logger = LoggerFactory.getLogger(DockerTestingApplication.class);
logger.info(timeStamp +" :: Docker File is running Ok");
}
}
When I run the application locally it works fine and it logs it perfectly in the log file.
Now, the issue is when i try to run in the application inside a docker, with cron tab added on it. On console the application(jar ) is executed as I assume it is as I have given a cron time period of 5 minutes and after every 5 min it exectues the jar. But how I will verify its working?
- Where to log the logs of the application process?
- How to give the locations of logs?
DOCKER FILE :-
FROM openjdk:8-jre-alpine
RUN apk add --no-cache bash
ENV LOG_LOCATION /var/log/applogs
RUN rm -rf /var/cache/apk/* \
&& mkdir /etc/test && mkdir /var/log/applogs
ADD crontab /etc/cron.d/crontab
ADD jar/ /etc/test/
CMD chmod +777 /var/log/applogs
RUN crontab /etc/cron.d/crontab
CMD ["/usr/sbin/crond", "-f", "-d", "0"]
CRONTAB:-
#!/bin/bash
*/5 * * * * root java -Dlogfile.location="/var/log/applogs/Log.log" -jar /etc/test/DockerTesting-0.0.1-SNAPSHOT.jar
# An empty line is required at the end of this file for a valid cron file.
I even logged in the docker container and reached the log location I have given but it doesn't creates the log.log file , I have searched a lot but didn't reached the solution.
Hope to find the solution.