Hello from ToraCode.

Now that we are set up with Docker virtualisation software. Let’s modify our pom.xml a little bit so that we can build our docker image.

We have to add Docker Maven Plugin in our pom.xml file.

Inside our <plugins> </plugins> tag we need to add this plugin.

Look a this code. For the image name we choose toracode/example-app, you can change it to your image name. For base image we wrote java:8.

Remember, we talked about our image is built on top on a base image here. We see java:8 is our base image here. Since spring boot needs Java 8 to run, we can’t use older versions than Java 8.

The <resources> tag tell what to copy into the root of the file system, in this case its build jar file of our application and the <entryPoint> tag is what we need to run this jar file inside the container.

Now open your Terminal and cd to your project directory. And Run this command to build the image.

In my case my project location is

/Documents/springspace/eampleapp

And I’m using mac. I’m using those commands:

if you get exception like this:

then add java 8 to as your system variable. For mac you can use this command to temporarily add java as a system variable

or if you are on windows i’m referring you here.

Building new docker image will take some time. After build is success you’ll see this success message on your terminal.

Screen Shot 2016-08-03 at 2.36.57 PM

and you’ve successfully built your software image on top of java 8 system image.

Wait what?? where is Java 8 image then?

Okay let me show you something. Scroll up your terminal and let’s see if you can find the docker is downloading Java 8 image from their repository. If you found this you’re awesome, but if not it’s not my fault. Please consult an eye specialist 😛

If you want to verify if your docker image is built, you can run this command:

you’ll find your image on images list.

Now it’s time to finally run our application on our local machine. To run this docker image we have to execute this command:

Here -it stands for interactive terminal, -p is port, since docker is running on host machine that has port 80 and you container is listening port 8080, we have to map that two port so that on host machine it listens port 80 and maps that port on port 8080.

If everything is okay the your app is deployed successfully.

You’ll find a gretting like this:

Screen Shot 2016-08-03 at 2.59.23 PM

Open a browser, and enter your ip address on address bar. Bamn!! you’re app is running!!

Look at my screen! I’m awesome, aren’t I?

 

Deployed Spring Boot App using Docker

2 thoughts on “Deploying sample spring boot app using Docker

  1. That saves me. Thanks for being so sesnebli!

  2. […] was easy, right? May be you may like some other articles like deploying Spring Boot app using Docker, or Authenticating users using Spring […]

Leave a Comment