Dockerize Java RESTful Application

Please follow the below steps to dockerize your java RESTful application –

Prerequisites : Please insure that Docker, java and mvn is installed on your machine.

  1. Create Dockerfile : Go to the root of the application where pom.xml is contained. Below is the content of my Dockerfile –

cd yourProjectFolder -> vi Dockerfile

#Fetch the base Jav8 image

FROM java:8

#Expose the local application port


#Place the jar file to the docker location

ADD /target/lookupService-1.0-SNAPSHOT.jar lookupService-1.0-SNAPSHOT.jar

#Place the config file as a part of application

ADD /src/main/java/com/test/config/

#execute the application

ENTRYPOINT [“java”,”-jar”,”yourService-1.0-SNAPSHOT.jar”]

  1.  Build Docker Image :

docker build -f Dockerfile -t yourservice .

  1. Run the Docker Image :

docker run -p 8088:8088 -tyourservice

Option -p publishes or maps host system port 18080 to container port 8080.

Note* Please don’t forget to change your base uri that is localhost:8088 to network interface created inside the container listen to all available address.

Few important commands of docker to know :

  1. To find the Id of your running container –

docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES

77558fabec6c       yourservice       “java -jar lookupS…”   38 minutes ago      Up 38 minutes>8088/tcp   affectionate_brahmagupta

  1. To kill the process inside the docker using container is –

docker container kill 77558fabec6c(Container Id)

Now you can test your RESt call on port using any of the REST client . Hope it helps 🙂


Expose a local web server to the internet

ngrok allows you to expose a web server running on your local machine to the internet. Just tell ngrok what port your web server is listening on.

If you don’t know what port your web server is listening on, it’s probably port 80, the default for HTTP.

Example: Expose a web server on port 9876 of your local machine to the internet
ngrok http 9876

When you start ngrok, it will display a UI in your terminal with the public URL of your tunnel and other status and metrics information about connections made over your tunnel.

The ngrok console UI
ngrok by @inconshreveable
Tunnel Status                 online
Version                       2.0/2.0
Web Interface       
Forwarding           -> localhost:9876
Forwarding           -> localhost:9876
Connnections                  ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

Hope it helps. For more details, you can refer

Way to redirect the url from HTML page getting in the response of REST call through AJAX

Problem Statement – I have one CDN server (mylocalmachinedomain:8022) hosted through XAMPP (Apache) on my local machine. In parallel to it, I have written the micro-service (  to expose it’s REST end point hosted on tomcat server on my local machine. Now First I have to make a REST call (expose end point written in my micro-service) from the HTML page through AJAX. Secondly while exposing the REST call, it would redirect to some other page. So that I need to handle in the HTML page through AJAX. There are 2 ways to do the same –

My micro-service end point java code-



    @ApiOperation(value = “Displays a message”, notes = “The message is read from the properties”, response = Test.class )

    @ApiResponses(value = { @ApiResponse(code = 500, message = “Something went wrong”, response=Test.class) })


    public Response authCall() throws Exception {“This is a log to check oAuth api”);

        //HttpsURLConnection conn = null;

        String url = “;

        URI uri=new URI(url);

        return Response.status(Status.TEMPORARY_REDIRECT).location(uri).header(“Content-Type”, “application/json;charset=UTF-8”).build();


 1st way –



  type: “GET”,

  url: ““,

  success: function(data){






2nd way –

var xmlhttp;

    function init() {

       // put more code here in case you are concerned about browsers that do not provide XMLHttpRequest object directly

       xmlhttp = new XMLHttpRequest();

        var url =”“;‘GET’,url,true);


        xmlhttp.onreadystatechange = function() {

               if (xmlhttp.readyState == 4) {

                  if ( xmlhttp.status == 200) {






                       alert(“Error ->” + xmlhttp.responseText);




<body onload=”init()”> 


Hope it helps 🙂

Git – Permission denied (publickey) Error while cloning the repo on Windows.

The above error comes when either you haven’t made any SSH keys on your local machine or those keys are expired. So to solve this, Please follow the below steps –

  1. Open git bash.
  2. Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users\[YOUR-USER-NAME]\.ssh\ on Windows)
  3. Within the .ssh folder, there should be these two files: id_rsa and
  4. Copy the content of with no extra spaces or lines and paste it into GitHub under the Account Settings > SSH Keys. You can name as per your convenience.
  5. Now git clone or git pull should work.

In case the above files are not created, you can use the below command to do so –

cd ~/.ssh && ssh-keygen

Now follow all the above mentioned steps. Hope it will solve your problem.

How to redirect an URL using REST Java

There are multiple ways to perform redirection. Actually 3x family of HTTP plays a vital role while performing URL redirection in the below ways –

1. 301 Moved Permanently

String url =;;

URI uri=new URI(url);

return Response.status(Status.MOVED_PERMANENTLY).location(uri).build();

Now it’ll redirect you to your localhost endpoint defined in the parameter redirect_uri permanently.

2. 307 Temporary Redirect

return Response.temporaryRedirect(uri).build();


How to enable SSL/HTTPS in Java Micro-Service/Spring-Boot application

  1. Generate SSL certificate –

keytool -genkey -alias <alias> -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650

  1. Add the below lines in your file –

server.port: 8443

server.ssl.key-store: classpath : keystore.p12

server.ssl.key-store-password: <keystore password>

server.ssl.keyStoreType: PKCS12

server.ssl.keyAlias: <alias>

3. Restart your java application. Now you’ll be able to access your application over HTTPS on https://localhost:8443 instead of http://localhost:8080.

Windows VMware Issue: VMware Workstation and Hyper-V are not compatible. Remove the Hyper-V role from the system before running VMware Workstation.

Recently I have gotten into this issue after updating my windows. Before updating my windows machine, I was able to boot up my virtual machine. After that it got failed saying “VMware Workstation and Hyper-V are not compatible. Remove the Hyper-V role from the system before running VMware Workstation.”. Below is the required steps to solve this issue –

1.) Go to “Programs and Features” icon on your windows machine.

2.) Click on “Turn Windows features on or off”.

3.) When the new window opens, uncheck the checkbox labelled as “Hyper-V”.

4.) Now it will ask you to reboot your system.

5.) After the PC restarts, try to launch VMWare again. I worked for me. Hope it helps you as well. 🙂