title: Spring boot apps port mapping in docker container
body: <p>In my application.yml file, I added the server port on 8080.</p>
  <pre><code>server:
    port: 8080
  </code></pre>
  <p>Now in my Dockerfile, I am exposing port range <strong>8080-8089</strong>.
  Here my goal is I will run this image on the different external and internal ports.</p>
  <p>My Dockerfile is given bellow</p>
  <pre><code>FROM openjdk:8-jdk-alpine
  ARG JAR_FILE=build/libs/*.jar
  COPY ${JAR_FILE} user-service.jar
  EXPOSE 8000-8089
  
  ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;/user-service.jar&quot;]
  </code></pre>
  <p>My docker image build command is given below:</p>
  <pre><code>docker image build -t user-service .
  </code></pre>
  <p>Now after building this image, my docker run command is given below:</p>
  <pre><code>docker run -d -p 8080:8080  -it user-service
  </code></pre>
  <p>Here, <strong>user-service</strong> is my docker image TAG.
  After this, I can access the app on 8080 port.</p>
  <p>But the problem is when I run another container with port mapping -p 8081:8081, the application is running but won't access using port 8081.</p>
  <p>My docker run command is:</p>
  <pre><code>docker run -d -p 8081:8081  -it user-service
  </code></pre>
  <p>Now my goal is I want to skip the application.yml server port with my external and internal port mapping in docker</p>
  <p><strong>Notes</strong>:</p>
  <ol>
  <li>This is .jar deployment. For WAR deployment we can easily skip the application.yml server port by server's configuration.</li>
  <li>I will change the port from the docker image to run container. I don't have scope to modify the application.yml file or Dockerfile after docker build</li>
  </ol>
  <p>Thanks in advance</p>