title: The server.port property of a Spring Boot web application is ignored by Docker Engine on Windows
body: <p><strong>TL;DR</strong></p>
  
  <p>The <code>server.port</code> property defined in a <em>Spring Boot</em> application.properties file is not getting honored by the Docker engine when running a web application in Tomcat.</p>
  
  <hr>
  
  <p><strong>Background :</strong></p>
  
  <p>I have a simple Spring Boot application containing a single rest endpoint. I am able to run this application in Eclipse and access the rest endpoint successfully from the browser.</p>
  
  <p>However, when I try to deploy the same application in a Docker container, I am unable to access the rest endpoint from the browser. </p>
  
  <p><strong>Dockerfile :</strong></p>
  
  <pre><code>FROM tomcat
  EXPOSE 8000
  RUN rm -rf /user/local/tomcat/webapps/*
  COPY ./target/my-web-app.war /usr/local/tomcat/webapps/ROOT.war
  CMD ["catalina.sh","run"]
  </code></pre>
  
  <p><strong>Spring Boot application.properties :</strong> </p>
  
  <pre><code>spring.application.name=my-web-app
  server.port=8000
  spring.jpa.show-sql=true
  spring.h2.console.enabled=true
  </code></pre>
  
  <p><strong>Docker images output :</strong></p>
  
  <pre><code>CK@Ping MINGW64 /c/Program Files/Docker Toolbox
  $ docker images
  REPOSITORY           TAG                  IMAGE ID            CREATED             SIZE
  myrepo/my-web-app    0.0.1-SNAPSHOT       625e9d889139        4 minutes ago       694MB
  </code></pre>
  
  <p><strong>Start the container :</strong></p>
  
  <p>Note that I map the <code>server.port</code> of my <em>Spring Boot</em> <code>application.properties</code> file to the external port.</p>
  
  <pre><code>docker run -p 8000:8000 -d myrepo/my-web-app:0.0.1-SNAPSHOT
  </code></pre>
  
  <p><strong>docker container ls output :</strong></p>
  
  <pre><code>CONTAINER ID        IMAGE                                                COMMAND                  CREATED                  STATUS              PORTS                               NAMES
  3eff09347de3      myrep/my-web-app:0.0.1-SNAPSHOT              "catalina.sh run"        Less than a second ago            Up 4 seconds        0.0.0.0:8000-&gt;8000/tcp, 8080/tcp    hardcore
  </code></pre>
  
  <p><strong>Error in the Browser :</strong></p>
  
  <pre><code>This site can’t be reached
  </code></pre>
  
  <p><strong>I am trying to access the URL using :</strong> </p>
  
  <pre><code>http://192.168.99.100:8000/my-web-app/getResults
  </code></pre>
  
  <p>The same app works just fine when launched from Eclipse instead of a Docker container and I am able to access the rest end point using :</p>
  
  <pre><code>http://localhost:8000/my-web-app/getResults
  </code></pre>
  
  <hr>
  
  <p><strong>Update/Edit:</strong></p>
  
  <p>I found the root cause. I need to map port <strong>8000 to 8080</strong> instead of mapping <strong>8000 to 8000</strong> itself :</p>
  
  <pre><code>docker run -p 8000:8080 -d myrepo/my-web-app:0.0.1-SNAPSHOT
  </code></pre>
  
  <p>This means that the <code>server.port</code> property that I defined in my <code>application.properties</code> is not getting honored when starting up the container. </p>
  
  <p>What is even more strange is that I can set the <code>server.port</code> to <code>8111</code> for example and still be able to access the URL if I use <code>-p 8000:8080</code>.</p>
  
  <p>However, tomcat starts up on the port specified by <code>server.port</code> if I run the same application in Eclipse rather than a Docker container.</p>
  
  <p><strong>Bottom line :</strong> The <code>server.port</code> property defined in a <em>Spring Boot</em> application.properties file is not getting honored by the Docker engine.</p>