drvlxc.html.in 2.7 KB
Newer Older
1 2 3
<html>
  <body>
    <h1>LXC container driver</h1>
4 5 6 7 8 9 10 11 12 13 14 15
<p>
The libvirt LXC driver manages "Linux Containers".  Containers are sets of processes
with private namespaces which can (but don't always) look like separate machines, but
do not have their own OS.  Here are two example configurations.  The first is a very
light-weight "application container" which does not have it's own root image.  You would
start it using
</p>

<h3>Example config version 1</h3>
<p></p>
<pre>
&lt;domain type='lxc'&gt;
M
Matthew Booth 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
        &lt;name&gt;vm1&lt;/name&gt;
        &lt;memory&gt;500000&lt;/memory&gt;
        &lt;os&gt;
                &lt;type&gt;exe&lt;/type&gt;
                &lt;init&gt;/bin/sh&lt;/init&gt;
        &lt;/os&gt;
        &lt;vcpu&gt;1&lt;/vcpu&gt;
        &lt;clock offset='utc'/&gt;
        &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
        &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
        &lt;on_crash&gt;destroy&lt;/on_crash&gt;
        &lt;devices&gt;
                &lt;emulator&gt;/usr/libexec/libvirt_lxc&lt;/emulator&gt;
                &lt;interface type='network'&gt;
                        &lt;source network='default'/&gt;
                &lt;/interface&gt;
                &lt;console type='pty' /&gt;
        &lt;/devices&gt;
34 35 36 37 38 39 40 41 42 43 44
&lt;/domain&gt;
</pre>

<p>
The next example assumes there is a private root filesystem
(perhaps hand-crafted using busybox, or installed from media,
debootstrap, whatever) under /opt/vm-1-root:
</p>
<p></p>
<pre>
&lt;domain type='lxc'&gt;
M
Matthew Booth 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        &lt;name&gt;vm1&lt;/name&gt;
        &lt;memory&gt;32768&lt;/memory&gt;
        &lt;os&gt;
                &lt;type&gt;exe&lt;/type&gt;
                &lt;init&gt;/init&lt;/init&gt;
        &lt;/os&gt;
        &lt;vcpu&gt;1&lt;/vcpu&gt;
        &lt;clock offset='utc'/&gt;
        &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
        &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
        &lt;on_crash&gt;destroy&lt;/on_crash&gt;
        &lt;devices&gt;
                &lt;emulator&gt;/usr/libexec/libvirt_lxc&lt;/emulator&gt;
                &lt;filesystem type='mount'&gt;
                        &lt;source dir='/opt/vm-1-root'/&gt;
                        &lt;target dir='/'/&gt;
                &lt;/filesystem&gt;
                &lt;interface type='network'&gt;
                        &lt;source network='default'/&gt;
                &lt;/interface&gt;
                &lt;console type='pty' /&gt;
        &lt;/devices&gt;
67 68 69 70 71 72
&lt;/domain&gt;
</pre>

<p>
In both cases, you can define and start a container using:</p>
<pre>
D
Daniel Veillard 已提交
73 74
virsh --connect lxc:/// define v1.xml
virsh --connect lxc:/// start v1.xml
75 76 77
</pre>
and then get a console  using:
<pre>
D
Daniel Veillard 已提交
78
virsh --connect lxc:/// console v1
79 80 81 82
</pre>
<p>Now doing 'ps -ef' will only show processes in the container, for
instance.
</p>
83 84
  </body>
</html>