This gem is an easy ruby interface to ubuntu linux containers (LXC). It provides a convenient wrapper for starting Ubuntu Cloud image-based ephemeral containers.
lxc-start-ephemeral uses AUFS overlay filesystem to clone an container using very little disk space, which then disappears when shut down.
$ gem install linux_container
> c = LinuxContainer.new(
name: 'mycontainer',
username: 'ubuntu', # optional for SSH, defaults to ubuntu
ssh_key_path: '~/.ssh/id_rsa' # optional
)
> c.create(
template: 'ubuntu-cloud', # optional, defaults to ubuntu-cloud
hostid: 'i12345', # optional, autogenerated
userdata: 'userdata.txt', # optional cloud-init user-data script
auth-key: '~/.ssh/id_rsa', # optional, defaults to ssh_key_path
arch: 'i686', # optional, defaults to host arch
release: 'quantal' # optional, defaults to host release
)
> c.dir('/tmp')
=> "/var/lib/lxc/mycontainer/rootfs/tmp"
> c.start
> c.state
> c.running?
> c.ip
> c.wait_for { ip && sshable? }
> c.ssh 'uptime'
> c.stop
> e = c.start_ephemeral
> e.wait_for { ip && sshable? }
> c2 = LinuxContainer.new(name: 'clonetest')
> c2.clone_from(c)
> c2.start('-d', '-s', 'lxc.cgroup.memory.limit_in_bytes=512M')
> LinuxContainer.all
=> [container, container, container, ... ]
> c.shutdown '-t', '120'
> c.destroy '-f'
execute, kill, wait, cgroup, ps, info, freeze, unfreeze, netstat