Push a Docker Image of a Micronaut application to Oracle Cloud Container Registry

Learn how to push a Docker Image of a Micronaut application to Oracle Cloud Container Registry

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.

Oracle Cloud Container Registry

In this guide, we push a docker image of a Micronaut Application to Oracle Cloud Container Registry

Create a repository in an OCI compartment.

oci container registry create repository

Annotate the namespace:

oci container registry repository namespace

5. Auth Token

  • In the top-right corner of the Console, open the Profile menu, and then select User settings (or My Profile or your account name) to view the details. On the Auth Tokens page, select Generate Token.

  • Enter a friendly description for the auth token. Avoid entering confidential information.

  • Select Generate Token. The new auth token is displayed.

  • Copy the auth token immediately to a secure location from where you can retrieve it later, because you won’t see the auth token again in the Console.

  • Close the Generate Token dialog.

Micronaut Gradle Plugin

6. Registry Credentials Configuration

Modify the build file and configure the registry credentials using the Docker plugin extension.

The following code samples uses the Gradle Kotlin DSL. You will need to set the environment variable REGISTRY_TOKEN to the auth token you created previously, set the OCI email address, the region and namespace you obtained earlier.

val ociRegion = "eu-madrid-1"
val ociEmail = "email@example.com"
val registryUrl = "ocir.${ociRegion}.oci.oraclecloud.com"
val namespace = "bzcsmyxwoeez"
val image = "${registryUrl}/${namespace}/micronaut-guides"
docker {
    registryCredentials {
        url.set(registryUrl)
        username.set("${namespace}/${ociEmail}")
        password.set(System.getenv("REGISTRY_TOKEN"))
    }
}

7. Docker Image Configuration

Configure the dockerBuild and dockerPush tasks to set the images.

Gradle Groovy DSL

tasks.named("dockerBuild") {
    images = [image]
}

Gradle Kotlin DSL

tasks.named<DockerBuildImage>("dockerBuild") {
    images.set(listOf(image))
}

8. Docker Push

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

./gradlew dockerPush

9. 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…​).