1

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.

Tibebes. M
  • 6,940
  • 5
  • 15
  • 36

2 Answers2

2

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

-1

At first glance, you did everything correct except for the address you are trying to reach. Even if the service is exposed you are not in the "localhost" of the container, hence you should use the ip of the container.

TLDR, instead of http://localhost:8081/doctorservice?wsdl try this http://<_CONTAINER_IP_ADDRESS_>:8081/doctorservice?wsdl

Check this answer to fetch the IP address of your container:

How to get a Docker container's IP address from the host

Marco Massetti
  • 539
  • 4
  • 12