chameerar
chameerar

Reputation: 367

Unable to access Java SOAP service when deployed using Docker

I have this simple Java SOAP service which works fine in the local machine.

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class EchoService {
    @WebMethod
    public String echo(@WebParam(name = "message") String message) {
        return message;
    }

    public static void main(String[] args) {
        Endpoint.publish("http://localhost:8080/echoservice", new EchoService());
        System.out.println("Service published at http://localhost:8080/echoservice");
    }
}

When I start this locally, I can reach the service via http://localhost:8080/echoservice

Then I tried to use docker and deploy a containerised version. This is my Dockerfile

FROM maven:3.8.4-openjdk-11 AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline

COPY src ./src
RUN mvn package

FROM openjdk:11-jre-slim
WORKDIR /app
COPY --from=build /app/target/*.jar ./app.jar
COPY --from=build /app/target/libs ./libs
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

These are my docker commands.

docker build -t java-soap:1.0 . 

docker run -p 8080:8080 java-soap:1.0

After starting the container, I can see the server is running but it is no longer reachable via http://localhost:8080/echoservice.

What should be the issue here? Is this related to Docker network interfaces? Is there a way to fix this?

Upvotes: 0

Views: 176

Answers (2)

chameerar
chameerar

Reputation: 367

This worked fine when I changed localhost to 0.0.0.0.

Corrected code,

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class EchoService {
    @WebMethod
    public String echo(@WebParam(name = "message") String message) {
        return message;
    }

    public static void main(String[] args) {
        Endpoint.publish("http://0.0.0.0:8080/echoservice", new EchoService());
        System.out.println("Service published at http://localhost:8080/echoservice");
    }
}

Upvotes: 0

Andrian Soluk
Andrian Soluk

Reputation: 474

Can you please try to use the following host:

host.docker.internal

instead of

localhost

https://stackoverflow.com/a/24326540/10620689

Upvotes: 0

Related Questions