-
Notifications
You must be signed in to change notification settings - Fork 17
Lxc basic
tsabat edited this page Jun 8, 2012
·
9 revisions
In its current implementation, all lxc containers are created using toft lxc templates. The containers are confined in subnet 192.168.20.x/24 and 192.168.20.1 is used as gateway. This could be changed but I assume the default setting works for most of us in most cases.
Prepare a config file for your container. Here is a example:
# put the following content into a file, e.g. /tmp/n1.conf
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
# or 0.0.0.0 if you want to use dhcp
lxc.network.ipv4 = 192.168.20.2/24Then, create container use command lxc-create:
sudo lxc-create -n n1 -f /tmp/n1.conf -t centos-6Note:
- You have to run pretty much all lxc commands in root.
- The value of the
-tparameter indicates the template you use to create the container, toft brings three templates to you: lucid, natty and centos-6. Originally lxc give you several more templates such as lxc-fedora, lxc-maverick, but they are currently not guaranteed to work (especially with toft).
sudo lxc-start -n n1This will start the just created container and show you a login tty, use root:root to login.
If you want to start machine as a daemon, add -d to the above command. After container started, you can use lxc-console to login, or use ssh:
ssh root@192.168.20.1Stop container:
sudo lxc-stop -n n1Destroy container:
sudo lxc-destroy -n n1For more information about lxc commands, please refer to its manpage.