Monday, May 8, 2023

Externalization of Logs from Docker Container

For Docker , if we want to persist any data after the container is removed we can use the following command format:

docker run -d -p 9090:8080 -v <OS File Path>:<Docker container Path> tomcat-test-webapp

Here the logs with be stored in OS file/folder path instead of storing in  Docker container path

docker build -t tomcat-test-webapp .

docker run -d -p 9090:8080 -v F:/docker_data/logs:/usr/local/tomcat/logs tomcat-test-webapp


The -v option is used to create volume which persists in OS even after the container is removed.


With container name & Catalina Options it should look like below:

docker run -d --name testDockerWebApp -p 9090:8080 -v F:/docker_data/logs:/usr/local/tomcat/logs -e CATALINA_OPTS="-Xms512M -Xmx512M" tomcat-test-webapp

Format with log, connection pool, properties file externalization:

docker run -d --name <image_name> -p <external_port>:<Docker Internal Port> -v /opt/app_log/<app_name>:/usr/local/tomcat/logs -v /opt/app_cp/<app_name>:/usr/local/tomcat/conf/Catalina/localhost -v /opt/app_prop/<app_name>:/usr/local/properties/<app_name> -e CATALINA_OPTS="-Xms512M -Xmx512M" <docker_hub_image_name>

No comments:

Convert Java Project from Log4j 1 to Log4j2

Many times while working on old Java projects we find Log4j 1.x is used. But as the Log4j2 is the new one; hence to upgrade to Log4j2 we nee...