简体   繁体   中英

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

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

My docker container is running a celery process which attempts to connect to a rabbitMQ service running on the same machine that boot2docker is running on.

The Celery process running within the 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. Trying again in 2.00 seconds...

I have reason to believe this is a network related issue, associated with routing from the container, to the VirtualBox host, and from the host to the RabbitMQ service running on the local machine; I do not know how to configure this and I was wondering if anyone can advise me how to proceed?

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

I am running the container as docker run -i -t tagname

I am not specifying a host with -h when I run the container.

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


Some additional information :

The routing table of the host VM is what boot2docker configured during installation as follows :

在此输入图像描述

  • docker0 IP Address is 172.17.42.1

  • eth0 IP Address is 10.0.2.15

  • eth1 IP Address is 192.168.59.103

  • eth0 is attached to NAT (Adapter 1) in the VirtualBox VM network configuration.

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

  • eth1 is attached to Host-only adapter (Adapter 2).

  • Both adapters are set to promiscuous mode (allow all).

  • The IP Address of the docker container is 172.17.0.33.

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

127.0.0.1 is a special IP address that means "me", and inside the container it means "me the container", so this is why it is not connecting to the outer host. So the first thing to do is change the IP address where you are trying to connect to Rabbit to that of the outer host where it is running.

Then you probably have to do something about routing, but let's take one step at a time.

as your RabbitMQ server is running on your Windows host, you need to tell your container that it should talk to that IP - which would probably be 192.168.59.3

most importantly, your container's 127.0.0.1 is only a loopback device to that container's services - not even the boot2docker vm's ports.

You could 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'd --link that ambassador container to your current image

but personally, I'd avoid that initially, and just configure your containerised app to talk to the real host's IP

You have to specifc explicitely ports for port redirection separately for boot2docker and docker.

Please try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM