Accessing Spring Boot Logs in Docker

Accessing Spring Boot Logs in Docker

A quick and practical tutorial to accessing Spring Boot Docker logs. We'll explain how to access Spring Boot logs in Docker, from local development to sustainable multi-container solutions.

1. Overview

In this tutorial, we'll explain how to access Spring Boot logs in Docker, from local development to sustainable multi-container solutions.

2. Basic Console Output

To begin with, let's build our Spring Boot Docker image from our previous article:

$> mvn spring-boot:build-image

Then, when we run our container, we can immediately see STDOUT logs in the console:

$> docker run --name=demo-container docker.io/library/spring-boot-docker:0.0.1-SNAPSHOT
Setting Active Processor Count to 1
WARNING: Container memory limit unset. Configuring JVM for 1G container.

This command follows the logs like Linux shell tail -f command.

Now, let's configure our Spring Boot application with a log file appender by adding a line to the application.properties file:

logging.file.path=logs

Then, we can obtain the same result by running the tail -f command in our running container:

$> docker exec -it demo-container tail -f /workspace/logs/spring.log > $HOME/spring.log
Setting Active Processor Count to 1
WARNING: Container memory limit unset. Configuring JVM for 1G container.

That's it for single-container solutions. In the next chapters, we'll learn how to analyze log history and log output from composed containers.

docker spring-boot developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Build and Deploy a Spring Boot App on Kubernetes | spring Boot Docker Kubernetes

You will learn how to deploy a Java 11 Spring Boot application on a Kubernetes cluster and how to build and deploy a spring boot application on kubernetes us...

Deploying Spring Boot and MongoDB as Containers Using Docker and Docker Compose

In this video you will learn how to Dockerize spring boot with mongodb and Dockerize a Spring Boot with mongodb using docker-compose in ubuntu mahcine. GitHu...

Top 10 Advanced Java and Spring Boot Courses for Full-Stack Java Developers

These are best online courses to learn Spring Boot, Advanced Java, Docker, React, Microservices, DEvops, and Angular to become full stack Java developer.

Spring Boot with PostgreSQL and Docker Compose | RESTful CRUD API Example

You will learn how to create a Spring Boot + JPA/Hibernate + PostgreSQL RESTful CRUD API Example with a PostgreSQL database to run inside a Docker container ...

Spring Boot with PostgreSQL and Docker Compose | RESTful CRUD API Example | Spring Data JPA Auditing

In this video, You will learn how to create a Spring Boot + JPA/Hibernate + PostgreSQL RESTful CRUD API Example with a PostgreSQL database to run inside a Docker container and how to auditing, tracking and logging user activity across the application project by using JPA Auditing