Difference between revisions of "LXC"

From Alpine Linux
Jump to: navigation, search
m (newlines removed)
Line 13: Line 13:
iface br0 inet dhcp
iface br0 inet dhcp
     bridge-ports eth0
     bridge-ports eth0
Line 21: Line 20:
lxc.network.link = br0
lxc.network.link = br0
lxc.network.flags = up
lxc.network.flags = up

Revision as of 09:44, 21 March 2013

Linux Containers (LXC) provides containers similar BSD Jails, Linux VServer and Solaris Zones. It gives the impression of virtualization, but shares the kernel and resources with the "host".

Note: As of 1 March 2013, use LXC from the edge repository: apk add lxc@edge


Install the required packages:

apk add lxc bridge

Prepare network on host

Set up a bridge on the host. Example /etc/network/interfaces:

auto br0
iface br0 inet dhcp
    bridge-ports eth0

Create a network configuration template for the guests, /etc/lxc/lxc.conf:

lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up

Create a guest

lxc-create -n guest1 -f /etc/lxc/lxc.conf -t alpine

This will create a /var/lib/lxc/guest1 directory with a config file and a rootfs directory.

Starting/Stopping the guest

Create a symlink to the /etc/init.d/lxc script for your guest.

ln -s lxc /etc/init.d/lxc.guest1

You can start your guest with:

/etc/init.d/lxc.guest1 start

Stop it with:

/etc/init.d/lxc.guest1 stop

Make it autostart on boot up with:

rc-update add lxc.guest1

Connecting to the guest

By default sshd is not installed, so you will have to connect to a virtual console. This is done with:

lxc-console -n guest1

To disconnect from it, press Ctrl+a q

Deleting a guest

Make sure the guest is stopped and run:

lxc-destroy -n guest1

This will erase eerything, without asking any questions. It is equivalent to:

rm -r /var/lib/lxc/guest1