title: Spring Boot in Docker container behind Nginx reverse proxy not working
body: <p>I have a problem with a Spring Boot application running inside docker container, which is running behind nginx reverse proxy.</p>
  <p>To check that docker and nginx are working correctly I've tried folloging, which worked as expected:</p>
  <pre><code>docker run -d -p 9001:80 nginx:alpine
  </code></pre>
  <p>My nginx config looks like</p>
  <pre><code>server {
   server_name xyz.com;
   listen 80;
   location / {
    proxy_pass http://localhost:9001;
   }
  }
  </code></pre>
  <p>Now I'm able to reach the nginx welcome page from the internet via xyz.com and let's assume the server's IP address is 123.123.1.1, via <a href="http://123.123.1.1:9001" rel="nofollow noreferrer">http://123.123.1.1:9001</a> as expected.
  Also on the server itself, I get the welcome page via</p>
  <pre><code>curl http://localhost:9001
  </code></pre>
  <p>I think that shows, that docker and nginx are working as expected.</p>
  <p>Let's go further down towards my problem.</p>
  <p>Now I have build a simple Spring Boot application, which is bind to address 0.0.0.0 and port 9001. (Of course I have stopped the nginx container before going on...)
  After the maven build, I have started the application with</p>
  <pre><code>java -jar app.jar
  </code></pre>
  <p>After it started up, I can reach it on the server with</p>
  <pre><code>curl http://localhost:9001
  </code></pre>
  <p>and from the internet via xyz.com and <a href="http://123.123.1.1:9001" rel="nofollow noreferrer">http://123.123.1.1:9001</a> - everything fine as expected.</p>
  <p>Now, I've stopped the application und build a Dockerfile:</p>
  <pre><code>FROM amazoncorretto:11-alpine-jdk
  COPY target/app.jar app.jar
  ENTRYPOINT [&quot;java&quot;, &quot;-jar&quot;,&quot;/app.jar&quot;]
  </code></pre>
  <p>First building the image with <code>docker build -t app:latest .</code> and afterwards run the container with <code>docker run -p 9001:9001 -d app:latest</code>. So far so good, the container starts up - fine.</p>
  <p>And here is the problem:
  I'm not able to reach the application neither via xyz.com nor on the server witch <code>curl http://localhost:9001</code>! But via <a href="http://123.123.1.1:9001" rel="nofollow noreferrer">http://123.123.1.1:9001</a> it worked!</p>
  <p>I've tried to check it inside the container <code>docker exec -it [container] sh</code> and afterwards <code># wget localhost:9001</code> worked fine. <code># netstat -tulpn</code> on the container itself brings following</p>
  <pre><code>Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  tcp        0      0 0.0.0.0:9001            0.0.0.0:*               LISTEN      1/java
  </code></pre>
  <p>Also on the server <code>$ netstat -tulpn</code> shows the following:</p>
  <pre><code>Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  tcp        0      0 0.0.0.0:9001            0.0.0.0:*               LISTEN      607173/docker-proxy
  tcp6       0      0 :::9001                 :::*                    LISTEN      607180/docker-proxy
  </code></pre>
  <p>Maybe something with iptables, but not sure what.
  Hopefully somebody out there has an idea to help me.
  Thanks in advance!</p>
  <p><strong>Update</strong>
  When I used port 80 inside the container (The Spring Boot application listen now on port 80 instead of 9001) - magically it works! Tried port 8080 inside the container also - this didn't work!
  Looks like a port problem, maybe someone can explain where the problem is?!</p>