Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection refused when try to connect http server in docker daemon container

I am using boot2docker. I run one image at the daemon mode which starts grunt server at port 3000. This is the command I used to start it up.

That image has already exposed port 3000

docker run -d -P --name dummy image_name grunt server
docker ps
3af4ba19c539        image_name:latest   "grunt server"      54 minutes ago      Up 54 minutes       0.0.0.0:45000->3000/tcp   dummy

and then run into the same container to "curl" the web server.

docker exec -it 3af4ba19c539 /bin/bash 
curl localhost:3000 

It gets the html.

However, when I try to connect it in my mac pc. It said "Connection refused."

curl $(boot2docker ip):45000
//curl: (7) Failed connect to 192.168.59.103:45000; Connection refused

I try to solve this problem by using VBoxManage, but it is not working either

VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port45000,tcp,,45000,,45000"

May I know how to solve this problem. Many thanks in advance

like image 805
Xiaohe Dong Avatar asked Feb 11 '23 01:02

Xiaohe Dong


1 Answers

I need to see the source of your application to be sure, but I'm willing to bet you've bound to the local loopback interface (127.0.0.1 or localhost) in your application. If you instead bind to 0.0.0.0 to listen to all interfaces, you should find it is accessible from the outside.

like image 152
Adrian Mouat Avatar answered Feb 13 '23 02:02

Adrian Mouat