Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run undertow java app with docker

I am using undertow for my applications with docker.

I am able to do the following

  1. create fat jar

  2. create docker image from that

  3. Run that docker image

  4. Listing on 8080 and added EXPOSE 8080 in Docker file

  5. curl my url from INSIDE the CONTAINER , curl localhost:8080/sample

I am facing some weird problem,

And My compose file is

version: '2'
services:
  login:
    image: my-image
    ports:
     - "8080:8080"

with 8080 port I am not able to access the url.

My Dockerfile

FROM openjdk:8-jre
COPY ./target/*-with-dependencies.jar /jars/service-jar.jar
EXPOSE 8080
CMD java  -cp /jars/service-jar.jar my.Main 

My Undertow Listener

Undertow server = Undertow.builder()
        .addHttpListener(8080, "localhost")
        .setHandler(path)
        .build();

I got some link in google still not able to make it work

http://lists.jboss.org/pipermail/undertow-dev/2014-October/000999.html

like image 758
vimal prakash Avatar asked Mar 21 '26 04:03

vimal prakash


1 Answers

fixed the issue , by listening the ip to the docker containers ip address .

I changed my listener to

Undertow server = Undertow.builder()
        .addHttpListener(8080, InetAddress.getLocalHost().getHostAddress())
        .setHandler(path)
        .build();

Now it working fine.

"The external IP is something completely different. So in summary you must set the host server for undertow as the Internal IP in the Iptables created by docker"

I missed to read this line in my reference link (http://lists.jboss.org/pipermail/undertow-dev/2014-October/000999.html).

My boss find out that .

like image 103
vimal prakash Avatar answered Mar 23 '26 17:03

vimal prakash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!