1

I am using docker to run my java war application and when I run the container I got this exception java.net.BindException: Address already in use .

The container expose port 8085 (8080->8085/tcp) I executed this command to run the docker container :

docker run -p 8080:8085/tcp -d --name=be-app java-app-image:latest

this is screenshot of the error enter image description here

I checked the opened ports inside the container enter image description here

I cannot restart the tomcat inside the container because it will stop , I thought about changing the 8085 port in the server.xml file , but I think that I should change the exposed port also. Is there any solution to avoid this exception ? ( java.net.BindException: Address already in use)

this is also what I am getting when I run command ps aux enter image description here

7
  • Seems your only options are to run on a port that isn't in use or change the application that is using 8085 to another port. There is no way to bind two applications to one port, if that is what you're after. Commented Apr 10, 2022 at 18:48
  • exposing another port instead of 8085? or changing this port in server.xml file? @theherk Commented Apr 10, 2022 at 18:53
  • Since it's a Java exception, the exception must occur inside the container. It seems very strange that port 8085 should be taken inside the container. All ports should be available. It almost seems like you might be running 2 instances of Tomcat in the container? Commented Apr 10, 2022 at 19:49
  • @HansKilian I am running one instance in tomcat , I am running catalina.sh start command . Commented Apr 10, 2022 at 20:13
  • @HansKilian I updated the question I added the output of ps command Commented Apr 10, 2022 at 20:57

1 Answer 1

2

The ps shows two java processes, possibly running Tomcat.

Since they would be running with the same parameters, including ports, it seems expected the second process fails with

java.net.BindException: Address already in use

Make sure to docker stop everything first, and check the status of docker ps --all

Sign up to request clarification or add additional context in comments.

2 Comments

Hello , thank you for responding me. I stoped the container, and I builded also another image and I runned it with docker-compose . the same error occured , java.net.BindException: Address already in use.
@Y.hadj.younes Than it is possible your ENTRYPOINT step is running a script which launches the java process twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.