OpenStack Routing for VMs running Docker Containers. Is there a smarter way of doing this?

asked 2014-03-07 11:01:48 -0600

qeedy gravatar image

updated 2014-03-15 17:41:45 -0600

When I run Docker within a VM, I'm required to explicitly set routing so that I can access the docker container by using the floating IP address and the exposed Docker port. My machine is a lab machine with only one physical NIC. Therefore this NIC is used to access OpenStack itself and its VMs.

Question: Editing the iptables manually is very cumbersome and error prone and therefore I'm wondering if you can think of a smarter, a more generic, way of doing this? Note: This machine is for testing only and not exposed to the Internet and therefore lax security wouldn't be an issue.

  • Installed Ubuntu 12.04
  • Made below network setting

    $ apt-get install bridge-utils

    $ nano /etc/network/interfaces

Content of /etc/network/interfaces

 # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    auto eth0
    iface eth0 inet manual
            up ip address add 0/0 dev $IFACE
            up ip link set $IFACE up
            down ip link set $IFACE down

    # Bridge for OpenStack to work with single NIC
    auto br-openstack
    iface br-openstack inet static
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
            up ifconfig $IFACE promisc

*Configure forwarding

# sysctl net.ipv4.ip_forward=1

# iptables -t nat -A POSTROUTING -o br-openstack -j MASQUERADE

*Created VM and installed Apache *Edited iptables as VM listens on IP Command was executed on DevStack host machine!

# iptables -t nat -A PREROUTING -i br-openstack -p tcp --dport 8080 -j DNAT --to-destination

Note: With above settings, I can run the VM and access its Apache HTTP Server on port 8080 with either or with, which is the VM's floating IP address.

*Installed Docker on the VM *Run a Docker container, which runs Apache HTTP Server on port 80. Used command below to expose the port.

# docker run -p 80:8080 -d mbentley/ubuntu-tomcat7

*Edited ipatables to be able to access the Docker container on port 80.

This command is executed on the DevStack machine!

# iptables -t nat -A PREROUTING -i br-openstack -p tcp --dport 80 -j DNAT --to-destination

This command is executed on the VM!

# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination

Note: The docker container is now accessible via the floating IP address on port 80.

Side note: I tried my best to format this post consistently but somehow this WYSIWYG editor didn't allow me to.

edit retag flag offensive close merge delete