docker - Curling server from Host raises a (56) Recv failure: Connection reset by peer - Stack Overflow

I have created a Docker image that runs a web server (based on OcamlDream) on port 8080.I run the con

I have created a Docker image that runs a web server (based on Ocaml/Dream) on port 8080.

I run the container mapping host port 8084 to container port 8080 as follows :

docker run -p 8084:8080 <MyDockerImageID>

Now I curl for localhost:8084 from the host and I have the following error :

curl -v localhost:8084
* Host localhost:8084 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8084...
* Immediate connect fail for ::1: Cannot assign requested address
*   Trying 127.0.0.1:8084...
* Connected to localhost (127.0.0.1) port 8084
> GET / HTTP/1.1
> Host: localhost:8084
> User-Agent: curl/8.5.0
> Accept: */*
> 
* Recv failure: Connection reset by peer
* Closing connection
curl: (56) Recv failure: Connection reset by peer

Note that if I curl from inside the container, it works :

docker exec -ti <MycontainerID> curl localhost:8080

I also tried to run the server on port 80 inside the container and tried with different port mappings but the problem persists.

I finally tried the same port mapping with an Nginx container and it worked fine.

Any idea why is there this problem?

Update :

I just tried the solution described here by running the container on the host network

docker run --network host -d <MycontainerID>

and now it works.

However, from what I understand, this could rise security issues.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744752345a4591672.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信