Search code examples
lxcubuntu-15.04lxd

how to access mongodb deployed insde lxc container


I have been playing with lxc-lxd. I was able to install mongodb within an lxc container (ubuntu 15.04). I was able to access everything from within the container but not the otherway around. The container & lxc-bridge were being given 10.x.x.x ip address where as my network router IP address starts with 192.x.x.x. How do I access mongodb from outside the container (out side the host as well). I am planing to create a couple of more containers for nginx & node.js, so host pass through may not be an option.

My Ubuntu host is running within a virtualbox VM, hope this is not causing the issue.


Solution

  • First create a bridge as per instructions here https://wiki.debian.org/LXC/SimpleBridge

    My interface was showing em1 instead of eth0 so be sure to replace eth0 with whatever you got.

    # Comment out the following:
    # The primary network interface
    #allow-hotplug eth0
    #iface eth0 inet dhcp
    
    auto br0
    iface br0 inet dhcp
            bridge_ports eth0
            bridge_fd 0
            bridge_maxwait 0
    

    Then create your container with a profile:

    lxc profile create bridged
    lxc profile device add bridged eth0 nic nictype=bridged parent=br0
    lxc launch ubuntu/vivid test --profile=bridged
    

    again replace eth0 with whatever you got, I think this is redundant given we already has a bridge called br0, in fact I did this in reverse order. Created the profile and the container but I got the following error:

    Error calling 'lxd forkstart db01 /var/lib/lxd/containers /var/log/lxd/db01/lxc.conf': err='exit status 1'
    

    Fixed this by creating the bridge as described above.