Push a Docker Image of a Micronaut application to Docker Hub

Learn how to push a Docker Image of a Micronaut application to Docker Hub

Authors: Sergio del Amo

Micronaut Version: 4.7.6

1. Getting Started

In this guide, we will create a Micronaut application written in Java.

2. What you will need

To complete this guide, you will need the following:

3. Solution

We recommend that you follow the instructions in the next sections and create the application step by step. However, you can go right to the completed example.

4. Writing the Application

Create an application using the Micronaut Command Line Interface or with Micronaut Launch.

mn create-app example.micronaut.micronautguide --build=gradle --lang=java
If you don’t specify the --build argument, Gradle with the Kotlin DSL is used as the build tool.
If you don’t specify the --lang argument, Java is used as the language.
If you don’t specify the --test argument, JUnit is used for Java and Kotlin, and Spock is used for Groovy.

The previous command creates a Micronaut application with the default package example.micronaut in a directory named micronautguide.

Docker Hub

Create an account in Docker Hub, and create a new repository for the project. Note down the namespace and name:

docker hub create repository

After creating the repository, go to Account Settings / Personal Access Tokens and Generate an access token with scope Read, Write, Delete.

Micronaut Gradle Plugin

5. Docker Image Configuration

Configure the dockerBuild and dockerPush tasks to set the images.

Gradle Groovy DSL

tasks.named("dockerBuild") {
    images = ["dockerHubNamespace/repositoryName"]
}

Gradle Kotlin DSL

tasks.named<DockerBuildImage>("dockerBuild") {
    images.set(listOf("dockerHubNamespace/repositoryName"))
}

6. Docker Push

You can push to Docker Hub via the dockerPush Gradle Task.

./gradlew dockerPush

7. License

All guides are released with an Apache license 2.0 license for the code and a Creative Commons Attribution 4.0 license for the writing and media (images…​).