I have an application which publishes a web service and I tried to deploy it on a docker container but it doesn't work. I used @WebService and @WebMethod from javax.jws to declare my service and I published it with
Endpoint.publish("http://localhost:8081/doctorservice",
new DoctorServiceImplementation());
The contents of my Dockerfile are
FROM openjdk:8
ADD target/service-publisher.jar service-publisher.jar
EXPOSE 8081
ENTRYPOINT ["java","-jar","service-publisher.jar"]
I created the docker image with
docker build -f Dockerfile -t webservice .
And run it with
docker run --name webservice -p 8081:8081 -d webservice
The container runs and the ports are exposed but when I try to access http://localhost:8081/doctorservice?wsdl from the browser it doesn't work.
I found the solution to my problem: I had to publish the service to 0.0.0.0 instead of localhost so I replaced
Endpoint.publish("http://localhost:8081/doctorservice",
new DoctorServiceImplementation());
with
Endpoint.publish("http://0.0.0.0:8081/doctorservice",
new DoctorServiceImplementation());
for the app running inside the docker container