If you’re building a Micronaut application, the next step is getting it deployed. One of the easiest and most powerful ways to deploy your application is by using Docker. In this guide, we will walk you through the steps of Deploying Micronaut to Docker with Mavenβno Gradle involved.
Youβll build a Micronaut app, write a simple Dockerfile, and run the app inside a container. All code examples use the package com.kscodes.micronaut.docker for consistency.

π§° What You Need
- Java 17+
- Docker installed
- Maven 3.6+
- Micronaut CLI (optional but helpful)
π Step 1: Create the Micronaut Project
Create a new project with Micronaut and Maven:
mn create-app com.kscodes.micronaut.docker.helloservice \
--build maven \
--jdk 17
Navigate into the project folder:
cd helloservice
π Project Structure
Micronaut will generate:
.
βββ pom.xml
βββ src
β βββ main
β β βββ java
β β βββ com
β β βββ kscodes
β β βββ micronaut
β β βββ docker
β β βββ HelloController.java
β βββ resources
β βββ application.yml
π¨βπ» Step 2: Create a Simple REST Endpoint
File: com.kscodes.micronaut.docker.HelloController.java
package com.kscodes.micronaut.docker;
import io.micronaut.http.annotation.*;
@Controller("/hello")
public class HelloController {
@Get
public String greet() {
return "Hello from Micronaut + Docker!";
}
}
βοΈ Step 3: Build the JAR Using Maven
Run this command to generate the JAR file:
./mvnw clean package
This will create a JAR file in target/ like:
target/helloservice-0.1.jar
π³ Step 4: Create a Dockerfile
In the root of your project, add a file named Dockerfile:
FROM eclipse-temurin:17-jdk-jammy
WORKDIR /app
COPY target/helloservice-*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
β This Dockerfile uses a lightweight JDK 17 base image and runs your Micronaut JAR.
π Step 5: Build Docker Image
Now, build your Docker image with a custom name:
docker build -t micronaut-docker-app .
βΆοΈ Step 6: Run the Micronaut App in Docker
Start a container from the image:
docker run -d -p 8080:8080 micronaut-docker-app
Now access your endpoint:
curl http://localhost:8080/hello
Output:
Hello from Micronaut + Docker!
π§ͺ Step 7: Dockerize with Build Plugin (Optional)
If you want to automate Docker builds from Maven, add this plugin in pom.xml:
com.spotify
docker-maven-plugin
1.2.2
micronaut-docker-app
${project.basedir}
/
${project.build.directory}
${project.build.finalName}.jar
Then run:
./mvnw docker:build
π Bonus: Production Docker Best Practices
- Use
jlinkto reduce image size even more - Add health checks in
Dockerfile - Use
micronaut-runtimeprofile to optimize for containers - Donβt include
.mvn,.idea, or build directories in image
π External Resources
β Conclusion
Deploying Micronaut to Docker is fast, clean, and lightweightβjust like Micronaut itself. With only a few lines of code and a simple Dockerfile, you can run your application anywhere: local, cloud, Kubernetes, or CI/CD pipelines.
Using Maven and the com.kscodes.micronaut.docker package, you now have a production-friendly and SEO-friendly Micronaut project that runs beautifully inside containers.