Over a million developers have joined DZone.

Deploying a Spring Boot Application to Bluemix in 20 Minutes via Docker

Everyone loves Spring, and creating cloud-ready applications with the framework is pretty simple

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

I really want to learn more about the Java framework Spring. The simplicity to build enterprise applications together with Spring's momentum makes it really interesting. So I started with a simple tutorial and deployed that Spring application to Bluemix

Spring provides a simple hello world Spring Boot with Docker tutorial with a Spring Boot application with one REST API. Maven and Gradle can be used, not only to build the Java application but also a Docker image which can be deployed to Bluemix. 

The Spring tutorial states that you need 15 minutes for the tutorial. In my case that was true since I had the prerequisites JDK 1.8, Maven and Docker already installed. For the deployment of the application you don't need more than 5 additional minutes. 

I won't repeat all the steps from the Spring tutorial here, but essentially this is what you need to do: 

- Clone a Github project. Use the 'complete' version of the application 

- Build the project via Maven or Gradle 

- Optional: Run the application locally: Run the built jar file which comes with Tomcat and your application 

- Build the Docker image via Maven or Gradle plugins 

The tutorial describes how to push the image to Docker Hub (via "docker push springio/gs-spring-boot-docker"). To push the image to Bluemix follow the next steps instead. 

> cf login 

> cf ic login 

> docker tag springio/gs-spring-boot-docker registry.ng.bluemix.net/nheidloff/gs-spring-boot-docker <- change the namespace 

> docker push registry.ng.bluemix.net/nheidloff/gs-spring-boot-docker <- change the namespace 

After this you'll see the image on Bluemix. 

In order to run a container invoke these commands: 

> cf ic run --name gs-spring-boot-docker -p 8080:8080 -d -t registry.ng.bluemix.net/nheidloff/gs-spring-boot-docker <- change the namespace 

> cf ic ip request 

> cf ic ip list -a 

> cf ic ip bind gs-spring-boot-docker <- change the IP 

Alternatively you can use the Bluemix UI to create a container. Choose the new image, define the port 8080 and bind an IP address. 

Open the application in a web browser via yourIP:8080.

The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.

spring ,bluemix ,docker

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}