<p>I am using docker to run my java war application and when I run the container I got this exception <strong>java.net.BindException: Address already in use</strong> .</p>
<p>The container expose port 8085 (8080-&gt;8085/tcp)
I executed this command to run the docker container :</p>
<blockquote>
<p>docker run -p 8080:8085/tcp  -d --name=be-app  java-app-image:latest</p>
</blockquote>
<p>this is screenshot of the error
<a href="https://i.stack.imgur.com/Hjoc0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hjoc0.png" alt="enter image description here" /></a></p>
<p>I checked the opened ports inside the container
<a href="https://i.stack.imgur.com/6YIvP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6YIvP.png" alt="enter image description here" /></a></p>
<p>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)</p>
<p>this is also what I am getting when I run command ps aux
<a href="https://i.stack.imgur.com/xItSj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xItSj.png" alt="enter image description here" /></a></p>

<p>The <code>ps</code> shows <em>two</em> java processes, possibly running Tomcat.</p>
<p>Since they would be running with the same parameters, including ports, it seems expected the second process fails with</p>
<pre><code>java.net.BindException: Address already in use
</code></pre>
<p>Make sure to <code>docker stop</code> everything first, and check the status of <code>docker ps --all</code></p>
