Port Forwarding to rabbitmq management plugin via docker

2,215 views
Skip to first unread message

Señor J Onion

unread,
Jun 7, 2015, 4:07:54 AM6/7/15
to vagra...@googlegroups.com
Hi - I am new to vagrant (and docker) and have set up a simple Vagrantfile to start up a rabbitmq instance inside a docker container (using the official docker image for that).

I want to connect to the rabbitmq management plugin in my browser on my host machine - I am on a Mac. I get a connection refused. I am clearly not yet understanding how perhaps port forwarding works. I am using Vagrant version 1.7.2 - a fresh install of that and Virtualbox. When I "vagrant up" - everything starts up fine and docker-logs shows me that rabbit started too.

This is my Vagrantfile

  Vagrant.require_version ">= 1.6.0"
    ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'

    Vagrant.configure("2") do |config|

      config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git/", disabled: false

      config.vm.provider "docker" do |docker|
        docker.image = "rabbitmq:3-management"
        docker.ports = ['5672:5672', '15672:8080']    # host:container
        docker.name = 'rabbitmq'
        docker.create_args = ['-e', 'RABBITMQ_NODENAME=johnny-is-a-rabbit']
      end

      config.ssh.insert_key = false
    end


Please can somebody let me know what URL to use in my browser so that I can see the rabbitmq management plugin ... Or what changes I would need to make to the Vagrantfile for this to work
(I have tried localhost:15672 and localhost:8080 ...)

Alvaro Miranda Aguilera

unread,
Jun 7, 2015, 10:18:45 PM6/7/15
to vagra...@googlegroups.com
Hello

You are missing one piece of the puzzle.

When you run Vagrant for docker, you are using a nested setup


host -> proxy vm -> docker

if you do vagrant up where the vagrant for docker is configured, it
will always use a proxy vm

If you are on linux it may not use it.. but you can tell vagrant to
always use the proxy vm


so your host need to connect to the proxy vm, and the proxy vm shoudl
fwd the ports to the docker vm


on this web:
https://docs.vagrantup.com/v2/docker/basics.html

read this part:

HOST VM

On systems that can't run Linux containers natively, such as Mac OS X
or Windows, Vagrant automatically spins up a "host VM" to run Docker.
This allows your Docker-based Vagrant environments to remain portable,
without inconsistencies depending on the platform they are running on.


if you want a visual vagrantfile, here is one example I did:

docker vm
https://github.com/kikitux/hashicorp-demo/blob/master/consul1/docker-dc1/Vagrantfile

and here the host where those docker will run:
https://github.com/kikitux/hashicorp-demo/blob/master/consul1/host/Vagrantfile


hope this helps
> --
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jörg Diekmann

unread,
Jun 8, 2015, 4:14:48 AM6/8/15
to vagra...@googlegroups.com
Hi Alvaro,

Thanks for this. I do get it that there’s that level of indirection you explained. So it says that if I don’t specify a vagrantfile for the host vm, then it uses a special host for docker using boot2docker. So I take it that my Vagrantfile should be fine - it will use a proxy VM then by default via boot2docker.

So the ‘ports’ configuration line then maps say port 15672 from my VM to my docker container. Therefore now, I need to find a way to map my mac ports to the vm port. So how would I set up this level of port forwarding?

The official rabbitmq docker image exposes port 8080 for the management console.

My current Vagrantfile maps the VM’s port 15672 to the docker container port 8080.

Now, say I want to map my Mac’s port 14672 to my VM’s port 15672 (which in turns maps it to docker’s port 8080). I assume this is what I need to accomplish? Is this possible?

Or is the solution to not create a port forwarding mapping from my Mac to the VM - but to find out the IP address of the VM instead, and use the VM’s IP address plus port 15672 to access the management plugin?

I tried the following - but connection is still refused (localhost:14672):

    
    config.vm.network "forwarded_port", guest: 15672, host: 14672


Having a look at the output when I vagrant up - it also feels like the ‘ports’ configuration for the docker provider automatically handles proxying my port all the way through to the docker container (from my mac host) - take a look at this output if I add the “forwarded_port” config:

==> default: Creating the container...
    default:   Name: rabbitmq
    default:  Image: rabbitmq:3-management
    default: Volume: /var/lib/docker/docker_1433750857_54067:/vagrant
    default:   Port: 14672:15672
    default:   Port: 5672:5672
    default:   Port: 15672:8080


It looks like the “forwarded_port” config is accomplishing the same as the docker provider’s ‘ports’ option.


I think this is where it is still confusing. I took a look at your Vagrantfiles and they seemed so complicated I couldn’t really make sense of them in relation to my scenario.

Anyway - your help is greatly appreciated.

Jörg


You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/GcbTei30yUM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.

Alvaro Miranda Aguilera

unread,
Jun 8, 2015, 5:31:17 AM6/8/15
to vagra...@googlegroups.com
Hello,

Have a look at the attached file, but basically is like this:

in your Vagrantfile, you need to tell what Vagrantfile use to spin a
docker host.

As you are using boot2docker, and seems it works for you, I leave it:

cat jd/Vagrantfile

Vagrant.require_version ">= 1.6.0"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", type: "rsync",
rsync__exclude: ".git/", disabled: false
config.vm.provider "docker" do |docker|
docker.vagrant_vagrantfile = "../boot2docker/Vagrantfile"
docker.image = "rabbitmq:3-management"
docker.ports = ['5672:5672', '15672:8080'] # guest:container
docker.name = 'rabbitmq'
docker.create_args = ['-e', 'RABBITMQ_NODENAME=johnny-is-a-rabbit']
end
config.ssh.insert_key = false
end


Check the first line inside the docker block


Then you define your docker host, and here is where you need to do all
the extra work:

cat boot2docker/Vagrantfile

Vagrant.configure(2) do |config|
config.vm.box = "mitchellh/boot2docker"
config.vm.network "forwarded_port", guest: 5672, host: 5672
end


So, on the first Vagrantfile, you do the mapping between guest and
docker container
on the second one you can use host to docker host

hope this helps

Thanks
Alvaro.
docker_sample.zip

Jörg Diekmann

unread,
Jun 8, 2015, 5:44:55 AM6/8/15
to vagra...@googlegroups.com
Hi Alvaro,

Thanks again for this: I think I understand the thinking behind this. I have created a separate Vagrantfile as you suggested and linked to it from my main Vagrantfile.

However, when I “vagrant up” now I get the following confusing error message about ports that I am not mapping …

Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 2375 is already in use
on the host machine.

I did a vagrant destroy before doing the up - so I don’t think it has anything to do with an existing VM that is running …

I am not sure where it is getting the 2375 port from ….


Jörg



--
You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/GcbTei30yUM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<docker_sample.zip>

Alvaro Miranda Aguilera

unread,
Jun 8, 2015, 5:53:53 AM6/8/15
to vagra...@googlegroups.com
Ok, seems is something listening on port 2375

What's your host OS?
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Jörg Diekmann

unread,
Jun 8, 2015, 6:58:03 AM6/8/15
to vagra...@googlegroups.com
My host OS is Mac OSX (the latest version)

Jörg Diekmann

unread,
Jun 8, 2015, 7:00:05 AM6/8/15
to vagra...@googlegroups.com
I did a cat on ~/.vagrant.d/boxes/mitchellh-VAGRANTSLASH-boot2docker/1.2.0/virtualbox/Vagrantfile

And found the following line in it:

  # Expose the Docker port
  config.vm.network "forwarded_port", guest: 2375, host: 2375, host_ip: "127.0.0.1", id: "docker"


Not sure how this all fits together … but may be an indication of what’s going on?

Jörg

Jörg Diekmann

unread,
Jun 8, 2015, 10:27:43 AM6/8/15
to vagra...@googlegroups.com
I looked at my Virtualbox UI and saw my VM was still running (before I made your suggested changes) even though I did a vagrant destroy. Anyway - I powered down that VM via the Virtualbox UI and now the new VM with the separate vagrantfile for the host starts up.



However - still - when I go to my browser on my host, I can't access the management plugin with localhost:14672 … Still a connection refused error. (I mapped it to port 14672 from the host to the VM so that it doesn’t collide with my local installation of rabbit)

Here is the output from the vagrant up:



>: vagrant up
Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
    default: Vagrant will now create or start a local VM to act as the Docker
    default: host. You'll see the output of the `vagrant up` for this VM below.
    default:  
    default: Checking if box 'mitchellh/boot2docker' is up to date...
    default: Clearing any previously set network interfaces...
    default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Forwarding ports...
    default: 2375 => 2375 (adapter 1)
    default: 15672 => 14672 (adapter 1)
    default: 22 => 2222 (adapter 1)
    default: Running 'pre-boot' VM customizations...
    default: Booting VM...
    default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: docker
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
    default: Machine booted and ready!
    default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default: 
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Syncing folders to the host VM...
    default: Installing rsync to the VM...
    default: Rsyncing folder: /Volumes/dev/ => /var/lib/docker/docker_1433772293_17627
    default:   - Exclude: [".vagrant/", ".git/"]
==> default: Warning: When using a remote Docker host, forwarded ports will NOT be
==> default: immediately available on your machine. They will still be forwarded on
==> default: the remote machine, however, so if you have a way to access the remote
==> default: machine, then you should be able to access those ports there. This is
==> default: not an error, it is only an informational message.
==> default: Creating the container...
    default:   Name: rabbitmq
    default:  Image: rabbitmq:3-management
    default: Volume: /var/lib/docker/docker_1433772293_17627:/vagrant
    default:   Port: 5672:5672
    default:   Port: 15672:8080
    default:  
    default: Container created: 7fc8575f656b1ee6
==> default: Starting container...
==> default: Provisioners will not be run since container doesn't support SSH.

Alvaro Miranda Aguilera

unread,
Jun 8, 2015, 6:18:34 PM6/8/15
to vagra...@googlegroups.com
On Tue, Jun 9, 2015 at 2:27 AM, Jörg Diekmann <senor....@gmail.com> wrote:
> default: Port: 15672:8080

sorry is taking this long.

I would suggest go to the Vagranfile folder for the host machine and
do vagrant ssh

once there

sudo su -

docker ps

and telnet to the ports

as Vagrant is in the middle, it may that some order of the ports is
being reversed

default: Port: 15672:8080

on the dokcer host vm, you can run all the docker dommands and netstat
to help you

Jörg Diekmann

unread,
Jun 9, 2015, 7:57:13 AM6/9/15
to vagra...@googlegroups.com
Hi Alvaro,

Thanks again for your help so far.

I followed the various commands - and this is what it look like:

Boot2Docker version 1.6.2, build master : 4534e65 - Wed May 13 21:24:28 UTC 2015
Docker version 1.6.2, build 7c8fca2
docker@boot2docker:~$ sudo su
root@boot2docker:/home/docker# docker ps
CONTAINER ID        IMAGE                   COMMAND                CREATED             STATUS              PORTS                                                        NAMES
8be5659e094d        rabbitmq:3-management   "/docker-entrypoint.   43 minutes ago      Up 43 minutes       0.0.0.0:5672->5672/tcp, 15672/tcp, 0.0.0.0:15672->8080/tcp   rabbitmq            
root@boot2docker:/home/docker# telnet 0.0.0.0 8080
telnet: can't connect to remote host (0.0.0.0): Connection refused
root@boot2docker:/home/docker# telnet 0.0.0.0 15672
Connection closed by foreign host
root@boot2docker:/home/docker# telnet 0.0.0.0 5672
Connection closed by foreign host
root@boot2docker:/home/docker# curl http://0.0.0.0:15672
curl: (52) Empty reply from server
root@boot2docker:/home/docker# 


Does this look wrong? Or the way it should do? Can’t figure out whether it is my Mac host to VM mapping that isn’t working or whether docker inside the VM isn’t mapping things correctly.
To me - it all seems/looks fine.


Jörg


Alvaro Miranda Aguilera

unread,
Jun 9, 2015, 6:30:45 PM6/9/15
to vagra...@googlegroups.com
Hello, not sure telnet 0.0.0.0 will work

you can provide this?

1. zip of where you are.. or github/gist.

2. iptables -L

just in case, validate there is no firewall causing issues

3. netstat -anp | egrep '5672|8080'

This will show if there is anything listening to what ip

if there is :8080 or 0.0.0.0:8080 that means any ip using ipv4

so telnet 127.0.0.1 8080 should work

Thanks
Alvaro
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Jörg Diekmann

unread,
Jun 10, 2015, 5:20:01 AM6/10/15
to vagra...@googlegroups.com
Hi Alvaro,

I’ve put both Vagrantfiles and the output from the various shell commands that I ran on the host VM onto a gist.


I hope this help in some ways.

Jörg

Jörg Diekmann

unread,
Jun 10, 2015, 6:29:33 AM6/10/15
to vagra...@googlegroups.com
Hey Alvaro - you’ve been helping me a lot - I wonder if it isn’t easier for you if we just Skype each other? It feels like I am taking up a lot of bandwidth here on this very silent group …

Jörg
Reply all
Reply to author
Forward
0 new messages