<p>I want to run two containers inside a k8s pod. </p>

<ol>
<li>tomcat exporter ( which runs on port 8080 )</li>
<li>tomcat application ( which also runs on the port 8080 )</li>
</ol>

<p>As multiple running containers inside a pod cant share a same port , I am looking forward to build a custom tomcat image with a different port ( say 9090 ( default tomcat port is : 8080 )) </p>

<p>This is what the Dockerfile I have used. </p>

<pre><code>cat Dockerfile 
FROM tomcat:9.0.34
RUN sed -i 's/8080/9090/' /usr/local/tomcat/conf/server.xml
EXPOSE 9090
</code></pre>

<p>After building that image and running a container, I see that 9090 port has been assigned , but I also see 8080 is also still existing. </p>

<pre><code>CONTAINER ID        IMAGE                             COMMAND             CREATED             STATUS              PORTS                              NAMES
b66e1e9c3db8        chakilams3/tomcatchangedport:v1   "catalina.sh run"   3 seconds ago       Up 2 seconds        8080/tcp, 0.0.0.0:9090-&gt;9090/tcp   test
</code></pre>

<p>I am wondering from where does this 8080/tcp port comes from , even after I have changed all refferences of 8080 to 9090 in the server.xml file </p>

<p>Any thoughts are appreciated. </p>

<p>With lots of effort, I found the solution to change the internal port of tomcat
container</p>
<p>my Dockerfile is</p>
<pre><code>FROM tomcat:7.0.107
RUN sed -i 's/port=&quot;8080&quot;/port=&quot;4287&quot;/' ${CATALINA_HOME}/conf/server.xml
ADD ./tomcat-cas/war/ ${CATALINA_HOME}/webapps/
CMD [&quot;catalina.sh&quot;, &quot;run&quot;]
</code></pre>
<p>Here
<code>ADD ./tomcat-cas/war/ ${CATALINA_HOME}/webapps/</code> part is not necessary unless you want to initially deploy some war files. And also I don't add <code>EXPOSE 4287</code>, because if I did so, the tomcat server not binding to the port 4287 then it always binding to the 8080 default port.</p>
<p>Just build the image and run <br>
<code>docker build -f Dockerfile -t test/tomcat-test:1.0 .</code> <br>
<code>docker run -d -p 4287:4287 --name tomcat-test test/tomcat-test:1.0</code></p>
