Adventures in CI/CD [#9]: Deploying A Microservice As A Docker Container

May 18, 2020 | 4 minute read
Text Size 100%:

Welcome to the penultimate post in this continuous journey about continuous integration and continuous deployment. So far in this blog series, we have gone over a copious amount of topics related to building and automated testing and deploying of a microservice using many popular tools in the Java and open-source ecosystem. Here’s what we have covered so far.

Honestly, there is not much left to talk about as it relates to the basics of continuous integration and deployment of microservices. There is however one more topic that we would be remiss to not mention and that is building and deploying our microservice as a Docker container onto a Kubernetes Cluster. It’s not terribly complicated to do this, but we’ll break this last topic up into two separate blog posts. In this post, we’ll focus on building our Docker container.

The Dockerfile

If you’ve followed along with this series, you may or may not have noticed that way back in part one when we generated our Micronaut application there was a file named Dockerfile created in the root of the project. Let’s open that up and take a look at it. It should look very similar to this (unless you’ve used a different name for your project):

Preparing To Build The Docker Image

We’re going to need a Docker Registry to store our Docker images. You can use Docker Hub if you’d like, but a great option for hosting Docker Images in the Oracle Cloud is the Oracle Cloud Infrastructure Registry (OCIR). If you have not yet configured OCIR for your tenancy, do so now before we move forward.

Tip!  Check out The Complete Guide To Getting Up And Running With Docker And Kubernetes On The Oracle Cloud for help getting prepared for Docker & Kubernetes! 

Building The Docker Image

If we were to have built and run this Dockerfile way back before we added our dependencies it would have worked just fine. But since our DB connection requires a wallet for our Autonomous DB connection we’d have a problem if we tried to run it right now. Let’s make one simple modification to it to COPY in our wallet directory.

This will copy the wallet contents from the root of our project into our Docker container. You can drop your wallet into the root of the project and give it a shot.

Note: Do not check your wallet into version control. Make sure you add an entry to your .gitignore file to prevent accidental check-in!

To build our image, first make sure your JAR file is built locally with ./gradlew assemble and then run:

Running The Docker Build Locally

To test it out locally, export your configuration variables:

Take note of the URL above - you must use a local IP address instead of ‘localhost’ inside the Docker container!

Run it with:

Modifying The Build

Now that we’ve changed our Dockerfile and tested that it builds properly, we need to modify our GitHub Actions workflow to automate these tasks and then push the resulting Docker image to our OCIR repo. The first step is to modify to write out our Wallet to disk in the runner VM so when we run our Docker build it can be copied in. If you’ve followed along with this series, you should already have secrets in your GitHub repo for the wallet files, so modify the step we added before to write our configuration files to also write our wallet files to the runner’s workspace directory:

Next create two more secrets in GitHub, one for our OCIR_USERNAME (in the tenancy/username format) and one for the token called OCIR_PASSWORD.

Hint: If you don’t have a need for anything related to deploying to a VM and would only like to deploy to Docker, you can remove all of the previous steps related to that deployment now.

Next, add a step to login to OCIR. This step will use the actions-hub/docker/login@master action to perform the login. Substitute your appropriate URL if you are not using the PHX region!

Now let’s do the same docker build command that we tested locally from our pipeline:

And finally, push that image to OCIR:

Observe your build on GitHub and it should complete successfully:

And we can confirm this by checking our OCIR registry:


In this post, we modified our GitHub Actions workflow to build a Docker image that contains our microservice and pushed that image to our OCIR registry.


In the next post, we’ll deploy our microservice Docker image to a Kubernetes cluster in the Oracle Cloud.

Source Code

For this post can be found at

Photo by Walter Sturn on Unsplash

Todd Sharp

Todd Sharp is a developer advocate for Oracle focusing on Oracle Cloud. He has worked with dynamic JVM languages and various JavaScript frameworks for more than 14 years, originally with ColdFusion and more recently with Java/Groovy/Grails on the server side. He lives in the Appalachian mountains of north Georgia (in the United States) with his wife and two children.

Previous Post

Adventures in CI/CD [#8]: Deploying A Microservice With A Tested Persistence Tier In Place

Todd Sharp | 4 min read

Next Post

Configuring the Oracle JDBC drivers in a Helidon project

Andres Almiray | 2 min read