Skip to content

Instantly share code, notes, and snippets.

@botchagalupe
Created June 17, 2011 22:59
Show Gist options
  • Save botchagalupe/1032548 to your computer and use it in GitHub Desktop.
Save botchagalupe/1032548 to your computer and use it in GitHub Desktop.

http://www.phenona.com/blog/using-lxc-linux-containers-in-amazon-ec2/

Use ami-1aad5273

sudo -i

apt-get update && apt-get install lxc debootstrap bridge-utils dnsmasq

mkdir /cgroup mount -t cgroup none /cgroup

(If you want to keep cgroup mounted between reboots, do: echo "none /cgroup cgroup defaults 0 0" >> /etc/fstab instead.)

Now, let's create a network bridge for the containers to be able to connect to the network/Internet. Simply run:

brctl addbr br0 brctl setfd br0 0 ifconfig br0 192.168.3.1 up

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sysctl -w net.ipv4.ip_forward=1

Let's set up DHCP/DNS on our new bridge. Open up /etc/dnsmasq.conf for editing (vim/nano/ed/cat, your choice). Uncomment the necessary lines so that the conf file looks like the following:

domain-needed bogus-priv interface = br0 listen-address = 127.0.0.1 listen-address = 192.168.3.1 expand-hosts domain = containers dhcp-range = 192.168.3.50,192.168.3.200,1h

Now, you'll need to edit /etc/dhcp3/dhclient.conf for DNS to properly resolve locally. Add the following lines to the beginning:

(use dhcp/dhclient.conf )

prepend domain-name-servers 127.0.0.1; prepend domain-search "containers.";

dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0

service dnsmasq restart

Create a container

wget -O lxc-ubuntu http://xrl.us/ec2ubuntulxc chmod +x lxc-ubuntu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment