How do I connect a Docker container running on boot2docker to a network service running on a different host?

I am using the latest boot2docker version 1.3.2, 495c19a on a Windows 7 64-bit machine (SP1).

There is a celery process running in my docker container that is trying to connect to the rabbitMQ service running on the same machine running boot2docker.

Celery process running in a docker container cannot connect to RabbitMQ and reports the following:

[2014-12-02 10: 28: 41,141: ERROR / MainProcess] consumer: cannot connect to amqp: // guest: ** @ 127.0.0.1: 5672 //: [Errno 111] Connection refused. Try again in 2.00 seconds ...

I have reason to believe this is a network related issue with routing from container to VirtualBox host and from host to RabbitMQ service running on local machine; I have no idea how to set this up and I was wondering if anyone could advise me on how to proceed?

I tried setting up port 5672 in port forwarding, but it didn't work (but I believe it is for incoming traffic to the VM, like boot2docker ssh).

I am starting the container as a runner docker -i -t tagname

I do not specify the host with -h when I start the container.

I'm sorry if this question seems rather clueless or if the answer seems obvious ... I appreciate any help!


Additional Information:

The host virtual machine's routing table is what boot2docker is configured during installation like this:

enter image description here

  • docker0 IP address - 172.17.42.1

  • eth0 IP address 10.0.2.15

  • eth1 IP address: 192.168.59.103

  • eth0 connects to NAT (adapter 1) in the VirtualBox virtual machine network configuration.

  • Adapter 1 has a port forwarding setting for ssh; default setting for host IP 127.0.0.1, host port 2022, guest port 22.

  • eth1 connects to the host-only adapter (adapter 2).

  • Both adapters are configured for promiscuous mode (allow all).

  • Docker container IP is 172.17.0.33.

+3


source to share


3 answers


[2014-12-02 10: 28: 41,141: ERROR / MainProcess] consumer: cannot connect to amqp: // guest: ** @ 127.0.0.1: 5672 //: [Errno 111] Connection refused. Try again in 2.00 seconds ...

127.0.0.1 is a special IP that means "I" and inside the container means "I am the container", so it doesn't connect to an outside host. So, the first thing to do is change the IP address where you are trying to connect to the Rabbit to the one from the external host that it is running on.



Then you probably have to do something about the routing, but let's do it step by step.

+2


source


since your RabbitMQ server is running on your windows host, you have to tell your container that it should talk to this IP, which will probably be 192.168.59.3

most importantly, your container 127.0.0.1

is just a loopback device for those containers - even the ports of the boot2docker vm.



You can set up an ambassador container that has --expose=80

and uses something like socat to forward all traffic from that container to your host (see svendowideit / Ambassador). Then you would be --link

that container ambassador for your current image

but personally I would not do this natively and just configure your container app to talk to the real IP of the host

+2


source


You must explicitly specify ports for port forwarding separately for boot2docker and docker.

Please try the following:

c:\>boot2docker init
c:\>boot2docker up
c:\>boot2docker ssh -L 0.0.0.0:5672:localhost:5672
docker@boot2docker:~$ docker run -it -p 5672:5672 tagname

      

0


source







All Articles