Lxc is great for starting up several containers on your laptop or on an ec2 host. But what if you want to fire up containers on multiple ec2 instances, and have them talk to each other?
An easy way to support that is using openvswitch. This script is a user-data-script which you can use to fire up instances ready to connect containers. For instance, I personally would
ami=`ubuntu-cloudimg-query precise` ec2-run-instances -n 2 -f user-data-lxc-ovs.sh -k mykeypair $ami
This will fire off two Ubuntu precise instances which will run the script. Once the scripts are done (sudo status cloud-final will show stopped), you can look at the openvswitch bridge with
sudo ovs-vsctl show
You want to connect the bridges on each instance by adding a GRE tunnel. On each host, do
sudo ovs-vsctl add-port br0 gre0 -- set interface gre0 type=gre options:remote_ip=x.x.x.x
where x.x.x.x is the public ip address of the other instance. Now the tunnel is set up. You can simply fire up container p1 in each instance
sudo lxc-start -n p1
Check out the /etc/lxc/lxc-ovs.conf file on each instance, which was the lxc configuration used to create the containers. It has two network sections (each started by lxc.network.type=veth). The first will be veth0, and will be connected to the lxcbr0 to connect the container to the internet. The second will be veth1, which is bridged with the openvswitch GRE tunnel. So the containers can ssh to each other’s veth1 addresses.