docs / guides/dockerizespring-cli

Generate Docker files ​

Run dockerize from a spring-cli project to create a Dockerfile, docker-compose.yml, and .dockerignore:

bash
spring-cli dockerize

The generated Dockerfile packages the Maven application into a JAR, then runs it in a smaller Java runtime image as a non-root user. The Compose service maps port 8080 and defaults SPRING_PROFILES_ACTIVE to default.

To build and start the generated configuration with Docker Compose:

bash
docker compose up --build

Stop it with Ctrl+C; use docker compose down to remove the running service container.

Java version ​

The generated Dockerfile uses the Java version in spring-cli.json for both its Maven build image and runtime image.

Existing files ​

The command refuses to overwrite any of the three generated files. Pass --force to replace them:

bash
spring-cli dockerize --force

Review existing Docker files before using the force option.

dockerize only writes the configuration files. Docker must be installed separately, and this command does not build or start the image itself.