<p>I am trying to package a war file using a tomcat Docker image.
I'm trying to expose the tomcat port in the image for it to be accessed externally.</p>

<p>This is my docker file</p>

<pre><code> FROM tomcat8:3.0.0

 COPY target/hello-world-war-1.0.0.war /usr/local/tomcat/webapps

 EXPOSE 8080
</code></pre>

<p>However, when I build this image, run it and try to access from my host browser (localhost:8080) it doesn't hit the endpoint, therefore it does not work as expected</p>

<p>I still have to expose the port externally with the -p switch.</p>

<p>What have I missed? or is the usage of EXPOSE something else?</p>

<p>My end need is to be able to deploy this in kubernetes.</p>

<blockquote>
  <p>What have I missed?</p>
</blockquote>

<p>You need to publish port in some way:</p>

<ul>
<li><p>either by directly publishing it in <code>docker run</code> command remapping the <code>EXPOSE</code> Dockerfile directive to different host port using (note lowercase p):</p>

<pre><code>-p=[]      : Publish a container᾿s port or a range of ports to the host
</code></pre></li>
<li><p>or, as stated in <a href="https://docs.docker.com/engine/reference/run/#overriding-dockerfile-image-defaults" rel="nofollow noreferrer">docker documentation</a>, implicitly publish ports listed in the <code>EXPOSE</code> Dockerfile directive using (note capital P):</p>

<pre><code>-P         : Publish all exposed ports to the host interfaces
</code></pre></li>
</ul>

<blockquote>
  <p>My end need is to be able to deploy this in kubernetes.</p>
</blockquote>

<p>And to that goal you will be using ports listed in k8s manifests in similar fashion. Say, you expose port 8080 in your docker image (and publish it with -p or -P), you will then be using it in container spec (exact manifest depending on chosen k8s object type) and very probably later in service manifest, and in each layer you can change port mapping (similar to <code>docker run -p</code> mapping host:docker port to different values if you require to do so). So as far as k8s is concerned if you <code>EXPOSE</code> port in Dockerfile and it works correctly locally in container and also on host through any means of publishing it (<code>docker run</code> with -p or -P) it will function in kubernetes as well (as far as you list it in proper manifest files).</p>
