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:
1 2 3 4 5 6 |
mn create-app com.kscodes.micronaut.docker.helloservice \ --build maven \ --jdk 17 |
Navigate into the project folder:
1 2 3 4 |
cd helloservice |
π Project Structure
Micronaut will generate:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
. βββ 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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:
1 2 3 4 |
./mvnw clean package |
This will create a JAR file in target/
like:
1 2 3 4 |
target/helloservice-0.1.jar |
π³ Step 4: Create a Dockerfile
In the root of your project, add a file named Dockerfile
:
1 2 3 4 5 6 7 8 9 10 11 12 |
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:
1 2 3 4 |
docker build -t micronaut-docker-app . |
βΆοΈ Step 6: Run the Micronaut App in Docker
Start a container from the image:
1 2 3 4 |
docker run -d -p 8080:8080 micronaut-docker-app |
Now access your endpoint:
1 2 3 4 |
curl http://localhost:8080/hello |
Output:
1 2 3 4 |
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
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.2.2</version> <configuration> <imageName>micronaut-docker-app</imageName> <dockerDirectory>${project.basedir}</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> |
Then run:
1 2 3 4 |
./mvnw docker:build |
π Bonus: Production Docker Best Practices
- Use
jlink
to reduce image size even more - Add health checks in
Dockerfile
- Use
micronaut-runtime
profile 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.