title: Connection refused to localhost with Docker container (Windows)
body: <p>I'm working on Windows with Docker Desktop.</p>
  <p>I built a Docker container which has this Dockerfile:</p>
  <pre><code>FROM ubuntu:20.04
  RUN apt-get update &amp;&amp; apt-get install -y \
      default-jre \
      default-jdk \
      &amp;&amp; rm -rf /var/lib/apt/lists/*
  COPY ./src/ /srcMicroservizio
  RUN cd /srcMicroservizio &amp;&amp; javac -cp .:BouncyCastle1.jar:BouncyCastle2.jar:byteLib.jar:clientMqtt.jar:gson-2.8.6.jar:sqlite-jdbc-3.27.2.1.jar ./analisiDati/* ./db/* ./oggetti/*
  EXPOSE 3001
  CMD cd /srcMicroservizio &amp;&amp; java -cp .:BouncyCastle1.jar:BouncyCastle2.jar:byteLib.jar:clientMqtt.jar:gson-2.8.6.jar:sqlite-jdbc-3.27.2.1.jar analisiDati/AnalisiDati
  </code></pre>
  <p>And then I started it with the following command:</p>
  <pre><code>docker build -t analisidati-pissir . &amp;&amp; docker run -p 3001:3001/tcp --net=host --name analisidati-pissir-container -it analisidati-pissir
  </code></pre>
  <p>Inside the Java code of the microservice I created a server on port 3001 with:</p>
  <pre><code>HttpServer server = HttpServer.create(new InetSocketAddress(3001), 0);
  </code></pre>
  <p>But when I try to contact the server using:</p>
  <pre><code>curl -i &quot;localhost:3001&quot;
  </code></pre>
  <p>I obtain the following error:</p>
  <pre><code>curl: (7) Failed to connect to localhost port 3001: Connection refused
  </code></pre>
  <p>Why isn't Windows able to contact the container?</p>
  <p>I tried to use the container on Ubuntu 20.04 virtual machine and it worked correctly.</p>
  <p>Also, if I run the code of the microservice using Eclipse instead of the container it works.</p>
  <p>Is this a Docker's bridging problem?</p>
  <p>Is there a way to fix it?</p>