Reputation: 83
I'm working on Windows with Docker Desktop.
I built a Docker container which has this Dockerfile:
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y \
default-jre \
default-jdk \
&& rm -rf /var/lib/apt/lists/*
COPY ./src/ /srcMicroservizio
RUN cd /srcMicroservizio && 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 && java -cp .:BouncyCastle1.jar:BouncyCastle2.jar:byteLib.jar:clientMqtt.jar:gson-2.8.6.jar:sqlite-jdbc-3.27.2.1.jar analisiDati/AnalisiDati
And then I started it with the following command:
docker build -t analisidati-pissir . && docker run -p 3001:3001/tcp --net=host --name analisidati-pissir-container -it analisidati-pissir
Inside the Java code of the microservice I created a server on port 3001 with:
HttpServer server = HttpServer.create(new InetSocketAddress(3001), 0);
But when I try to contact the server using:
curl -i "localhost:3001"
I obtain the following error:
curl: (7) Failed to connect to localhost port 3001: Connection refused
Why isn't Windows able to contact the container?
I tried to use the container on Ubuntu 20.04 virtual machine and it worked correctly.
Also, if I run the code of the microservice using Eclipse instead of the container it works.
Is this a Docker's bridging problem?
Is there a way to fix it?
Upvotes: 2
Views: 9701
Reputation: 341
The parameter --network=host
(or --net=host
) is only supported on Linux. Unfortunately Docker does not complain when you use the parameter under Windows, but you will get a "connection refused" error message.
As a test i used the following command:
docker run --rm -p 80:80 nginx
and with that I could connect to localhost:80docker run --rm -p 80:80 --network=host nginx
gave me a "connection refused" error message when trying to access localhost:8080Upvotes: 4