#Lightweight Spring Boot Docker image based on Alpine + Docker Compose file
Features:
- Spring profiles
- Custom JAVA_OPTS
- Healthcheck
- Wrapper script that enables application to take PID 1 & receive SIGTERM signals
- Debug mode
This tag integrates an healthcheck feature to tell Docker how to check the status of the container. This feature simply executes an HTTP request to a given URL: ${SERVER_PROTOCOL}://localhost:${SERVER_PORT}/${HEALTHCHECK_CONTEXT}
Name | Default | Description |
---|---|---|
DEBUG | false | Enable or disable debug mode |
DEBUG_PORT | 8000 | Debug port |
SPRING_PROFILES_ACTIVE | dev | Active Spring profiles |
JAVA_OPTS | JAVA_OPTS | |
SERVER_PROTOCOL | http | Spring Boot application server protocol, picked by the healthcheck command to check the application status |
SERVER_PORT | 8080 | Spring Boot application server port (server.port), picked by the healthcheck command to check the application status |
HEALTHCHECK_CONTEXT | / | The context URL to check the application status, picked by the healthcheck command to check the application status |
-
Simply extend your image from
flopes/spring-boot-docker
and set your application name as an environment variable:FROM flopes/spring-boot-docker:1.0 ENV ARTIFACT_NAME my-spring-boot-application.jar
-
Copy your Spring Boot executable jar into an
assets
folder and build you image:docker build -t spring-boot-image .
-
Start your application:
-
Using Docker CLI
-
Using the provided
docker-compose.yml
in this repository:docker-compose up -d
-
docker run -d -p 8080:8080 -e JAVA_OPTS=-Xms256m -Xmx512m spring-boot-image
The docker-compose.yml
file picks its configuration from the .env
one.
Using this file, you can set the desired properties:
# Docker
IMAGE_NAME=spring-boot-docker
HEALTHCHECK_CONTEXT=/
# Application
SERVER_PROTOCOL=http
SERVER_PORT=8080
DEBUG_PORT=8000
SPRING_PROFILES_ACTIVE=dev
DEBUG=false
# -Dprop=... -Dparameter=...
JAVA_OPTS=
# Host
HOST_SERVER_PORT=8080
HOST_DEBUG_PORT=8000
To run the application in debug mode, simply set the DEBUG
variable to true in the .env
file.
Launch the application:
docker-compose up -d
By default, the debug port used is the 8000
.
By default, the application will run with dev
Spring profile
To run the application with a specific Spring profile, set the desired one in the .env
file:
SPRING_PROFILES_ACTIVE=dev