~ubuntu-branches/ubuntu/quantal/lxc/quantal-201208301614

« back to all changes in this revision

Viewing changes to doc/lxc.7

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter, Stéphane Graber, Guido Trotter
  • Date: 2010-01-10 10:40:21 UTC
  • mfrom: (1.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20100110104021-25cm8w09ccmw5w2z
[ Stéphane Graber ]
* Upgrade standards-version to 3.8.3
* Drop the copy of etc/* from rules as "etc" is no longer in the tarball

[ Guido Trotter ]
* New Upstream Version
* Update libcap2-dev dependency to libcap-dev
* Install upstream-built man pages via debian/lxc.manpages
* Drop unneeded docbook-utils build dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.\" This manpage has been automatically generated by docbook2man 
 
2
.\" from a DocBook document.  This tool can be found at:
 
3
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/> 
 
4
.\" Please send any bug reports, improvements, comments, patches, 
 
5
.\" etc. to Steve Cheng <steve@ggi-project.org>.
 
6
.TH "LXC" "7" "24 November 2009" "Version 0.6.4" ""
 
7
 
 
8
.SH NAME
 
9
lxc \- linux containers
 
10
.SH "QUICK START"
 
11
.PP
 
12
You are in a hurry, and you don't want to read this man page. Ok,
 
13
without warranty, here are the commands to launch a shell inside
 
14
a container with a predefined configuration template, it may
 
15
work.
 
16
\fB/usr/bin/lxc-execute -n foo -f
 
17
/usr/share/doc/lxc/examples/lxc-macvlan.conf /bin/bash\fR
 
18
.SH "OVERVIEW"
 
19
.PP
 
20
The container technology is actively being pushed into the
 
21
mainstream linux kernel. It provides the resource management
 
22
through the control groups aka process containers and resource
 
23
isolation through the namespaces.
 
24
.PP
 
25
The linux containers, \fBlxc\fR, aims to use these
 
26
new functionalities to provide an userspace container object
 
27
which provides full resource isolation and resource control for
 
28
an applications or a system.
 
29
.PP
 
30
The first objective of this project is to make the life easier
 
31
for the kernel developers involved in the containers project and
 
32
especially to continue working on the Checkpoint/Restart new
 
33
features. The \fBlxc\fR is small enough to easily
 
34
manage a container with simple command lines and complete enough
 
35
to be used for other purposes.
 
36
.SH "REQUIREMENTS"
 
37
.PP
 
38
The \fBlxc\fR relies on a set of functionalies
 
39
provided by the kernel which needs to be active. Depending of
 
40
the missing functionalities the \fBlxc\fR will
 
41
work with a restricted number of functionalities or will simply
 
42
fails.
 
43
.PP
 
44
The following list gives the kernel features to be enabled in
 
45
the kernel to have the full features container:
 
46
 
 
47
.nf
 
48
            * General setup
 
49
              * Control Group support
 
50
                -> Namespace cgroup subsystem
 
51
                -> Freezer cgroup subsystem
 
52
                -> Cpuset support
 
53
                -> Simple CPU accounting cgroup subsystem
 
54
                -> Resource counters
 
55
                  -> Memory resource controllers for Control Groups
 
56
              * Group CPU scheduler
 
57
                -> Basis for grouping tasks (Control Groups)
 
58
              * Namespaces support
 
59
                -> UTS namespace
 
60
                -> IPC namespace
 
61
                -> User namespace
 
62
                -> Pid namespace
 
63
                -> Network namespace
 
64
            * Device Drivers
 
65
              * Character devices
 
66
                -> Support multiple instances of devpts
 
67
              * Network device support
 
68
                -> MAC-VLAN support
 
69
                -> Virtual ethernet pair device
 
70
            * Networking
 
71
              * Networking options
 
72
                -> 802.1d Ethernet Bridging
 
73
            * Security options
 
74
              -> File POSIX Capabilities
 
75
      
 
76
.fi
 
77
.PP
 
78
The kernel version >= 2.6.27 shipped with the distros, will
 
79
work with \fBlxc\fR, this one will have less
 
80
functionalities but enough to be interesting.
 
81
With the kernel 2.6.29, \fBlxc\fR is fully
 
82
functional.
 
83
The helper script \fBlxc-checkconfig\fR will give
 
84
you information about your kernel configuration.
 
85
.PP
 
86
Before using the \fBlxc\fR, your system should be
 
87
configured with the file capabilities, otherwise you will need
 
88
to run the \fBlxc\fR commands as root.
 
89
.PP
 
90
The control group can be mounted anywhere, eg:
 
91
\fBmount -t cgroup cgroup /cgroup\fR\&.
 
92
If you want to dedicate a specific cgroup mount point
 
93
for \fBlxc\fR, that is to have different cgroups
 
94
mounted at different places with different options but
 
95
let \fBlxc\fR to use one location, you can bind
 
96
the mount point with the \fBlxc\fR name, eg:
 
97
\fBmount -t cgroup lxc /cgroup4lxc\fR or
 
98
\fBmount -t cgroup -ons,cpuset,freezer,devices
 
99
lxc /cgroup4lxc\fR
 
100
.SH "FUNCTIONAL SPECIFICATION"
 
101
.PP
 
102
A container is an object where the configuration is
 
103
persistent. The application will be launched inside this
 
104
container and it will use the configuration which was previously
 
105
created or specified in parameter of the command.
 
106
.PP
 
107
How to run an application in a container ?
 
108
.PP
 
109
Before running an application, you should know what are the
 
110
resources you want to isolate. The default configuration is to
 
111
isolate the pids, the sysv ipc and the mount points. If you want
 
112
to run a simple shell inside a container, a basic configuration
 
113
is needed, especially if you want to share the rootfs. If you
 
114
want to run an application like \fBsshd\fR, you
 
115
should provide a new network stack and a new hostname. If you
 
116
want to avoid conflicts with some files
 
117
eg. \fI/var/run/httpd.pid\fR, you should
 
118
remount \fI/var/run\fR with an empty
 
119
directory. If you want to avoid the conflicts in all the cases,
 
120
you can specify a rootfs for the container. The rootfs can be a
 
121
directory tree, previously bind mounted with the initial rootfs,
 
122
so you can still use your distro but with your
 
123
own \fI/etc\fR and \fI/home\fR
 
124
.PP
 
125
Here is an example of directory tree
 
126
for \fBsshd\fR:
 
127
 
 
128
.nf
 
129
        
 
130
[root@lxc sshd]$ tree -d rootfs
 
131
        
 
132
rootfs  
 
133
|-- bin 
 
134
|-- dev 
 
135
|   |-- pts
 
136
|   `-- shm
 
137
|       `-- network
 
138
|-- etc 
 
139
|   `-- ssh
 
140
|-- lib 
 
141
|-- proc
 
142
|-- root
 
143
|-- sbin
 
144
|-- sys 
 
145
|-- usr 
 
146
`-- var 
 
147
    |-- empty
 
148
    |   `-- sshd
 
149
    |-- lib
 
150
    |   `-- empty
 
151
    |       `-- sshd
 
152
    `-- run
 
153
        `-- sshd
 
154
      
 
155
.fi
 
156
and the mount points file associated with it:
 
157
 
 
158
.nf
 
159
        [root@lxc sshd]$ cat fstab
 
160
 
 
161
        /lib /home/root/sshd/rootfs/lib none ro,bind 0 0
 
162
        /bin /home/root/sshd/rootfs/bin none ro,bind 0 0
 
163
        /usr /home/root/sshd/rootfs/usr none ro,bind 0 0
 
164
        /sbin /home/root/sshd/rootfs/sbin none ro,bind 0 0
 
165
      
 
166
.fi
 
167
.PP
 
168
How to run a system in a container ?
 
169
.PP
 
170
Running a system inside a container is paradoxically easier
 
171
than running an application. Why ? Because you don't have to care
 
172
about the resources to be isolated, everything need to be
 
173
isolated, the other resources are specified as being isolated but
 
174
without configuration because the container will set them
 
175
up. eg. the ipv4 address will be setup by the system container
 
176
init scripts. Here is an example of the mount points file:
 
177
 
 
178
.nf
 
179
        [root@lxc debian]$ cat fstab
 
180
 
 
181
        /dev    /home/root/debian/rootfs/dev none bind 0 0
 
182
        /dev/pts /home/root/debian/rootfs/dev/pts  none bind 0 0
 
183
      
 
184
.fi
 
185
More information can be added to the container to facilitate the
 
186
configuration. For example, make accessible from the container
 
187
the resolv.conf file belonging to the host.
 
188
 
 
189
.nf
 
190
        /etc/resolv.conf /home/root/debian/rootfs/etc/resolv.conf none bind 0 0
 
191
      
 
192
.fi
 
193
.SS "CONTAINER LIFE CYCLE"
 
194
.PP
 
195
When the container is created, it contains the configuration
 
196
information. When a process is launched, the container will be
 
197
starting and running. When the last process running inside the
 
198
container exits, the container is stopped.
 
199
.PP
 
200
In case of failure when the container is initialized, it will
 
201
pass through the aborting state.
 
202
 
 
203
.nf
 
204
 
 
205
   ---------
 
206
  | STOPPED |<---------------
 
207
   ---------                 |
 
208
       |                     |
 
209
     start                   |
 
210
       |                     |
 
211
       V                     |
 
212
   ----------                |
 
213
  | STARTING |--error-       |
 
214
   ----------         |      |
 
215
       |              |      |
 
216
       V              V      |
 
217
   ---------    ----------   |
 
218
  | RUNNING |  | ABORTING |  |
 
219
   ---------    ----------   |
 
220
       |              |      |
 
221
  no process          |      |
 
222
       |              |      |
 
223
       V              |      |
 
224
   ----------         |      |
 
225
  | STOPPING |<-------       |
 
226
   ----------                |
 
227
       |                     |
 
228
        ---------------------
 
229
 
 
230
      
 
231
.fi
 
232
.SS "VOLATILE CONTAINERS"
 
233
.PP
 
234
The container can be directly started with a
 
235
configuration file in parameter without creating them before.
 
236
.SS "CONFIGURATION"
 
237
.PP
 
238
The container is configured through a configuration
 
239
file, the format of the configuration file is described in 
 
240
\fB\fIlxc.conf\fB\fR(5)
 
241
.SS "CREATING / DESTROYING THE CONTAINERS"
 
242
.PP
 
243
The container is created via the \fBlxc-create\fR
 
244
command. It takes a container name as parameter and an
 
245
optional configuration file. The name is used by the different
 
246
commands to refer to this
 
247
container. The \fBlxc-destroy\fR command will
 
248
destroy the container object.
 
249
 
 
250
.nf
 
251
          lxc-create -n foo
 
252
          lxc-destroy -n foo
 
253
        
 
254
.fi
 
255
.SS "STARTING / STOPPING A CONTAINER"
 
256
.PP
 
257
When the container has been created, it is ready to run an
 
258
application / system. When the application has to be destroyed,
 
259
the container can be stopped, that will kill all the processes
 
260
of the container. If the container was not created before
 
261
starting the application, the container will use the
 
262
configuration file passed as parameter to the command, otherwise
 
263
it will use the default isolation.
 
264
.PP
 
265
Running an application inside a container is not exactly the
 
266
same thing as running a system. For this reason, there is two
 
267
commands to run an application into a container:
 
268
 
 
269
.nf
 
270
          lxc-execute -n foo [-f config] /bin/bash
 
271
          lxc-start -n foo [/bin/bash]
 
272
        
 
273
.fi
 
274
.PP
 
275
\fBlxc-execute\fR command will run the
 
276
specified command into a container but it will mount /proc
 
277
and autocreate/autodestroy the container if it does not
 
278
exist. It will furthermore create an intermediate
 
279
process, \fBlxc-init\fR, which is in charge to
 
280
launch the specified command, that allows to support daemons
 
281
in the container. In other words, in the
 
282
container \fBlxc-init\fR has the pid 1 and the
 
283
first process of the application has the pid 2.
 
284
.PP
 
285
\fBlxc-start\fR command will run the specified
 
286
command into the container doing nothing else than using the
 
287
configuration specified by \fBlxc-create\fR\&.
 
288
The pid of the first process is 1. If no command is
 
289
specified \fBlxc-start\fR will
 
290
run \fI/sbin/init\fR\&.
 
291
.PP
 
292
To summarize, \fBlxc-execute\fR is for running
 
293
an application and \fBlxc-start\fR is for
 
294
running a system.
 
295
.PP
 
296
If the application is no longer responding, inaccessible or is
 
297
not able to finish by itself, a
 
298
wild \fBlxc-stop\fR command will kill all the
 
299
processes in the container without pity.
 
300
 
 
301
.nf
 
302
          lxc-stop -n foo
 
303
        
 
304
.fi
 
305
.SS "CONNECT TO AN AVAILABLE TTY"
 
306
.PP
 
307
If the container is configured with the ttys, it is possible
 
308
to access it through them. It is up to the container to
 
309
provide a set of available tty to be used by the following
 
310
command. When the tty is lost, it is possible to reconnect it
 
311
without login again.
 
312
 
 
313
.nf
 
314
          lxc-console -n foo -t 3
 
315
        
 
316
.fi
 
317
.SS "FREEZE / UNFREEZE A CONTAINER"
 
318
.PP
 
319
Sometime, it is useful to stop all the processes belonging to
 
320
a container, eg. for job scheduling. The commands:
 
321
 
 
322
.nf
 
323
          lxc-freeze -n foo
 
324
        
 
325
.fi
 
326
will put all the processes in an uninteruptible state and 
 
327
 
 
328
.nf
 
329
          lxc-unfreeze -n foo
 
330
        
 
331
.fi
 
332
will resume all the tasks.
 
333
.PP
 
334
This feature is enabled if the cgroup freezer is enabled in the
 
335
kernel.
 
336
.SS "GETTING INFORMATION ABOUT THE CONTAINER"
 
337
.PP
 
338
When there are a lot of containers, it is hard to follow
 
339
what has been created or destroyed, what is running or what are
 
340
the pids running into a specific container. For this reason, the
 
341
following commands give this information:
 
342
 
 
343
.nf
 
344
          lxc-ls
 
345
          lxc-ps --name foo
 
346
          lxc-info -n foo
 
347
        
 
348
.fi
 
349
.PP
 
350
\fBlxc-ls\fR lists the containers of the
 
351
system. The command is a script built on top
 
352
of \fBls\fR, so it accepts the options of the ls
 
353
commands, eg:
 
354
 
 
355
.nf
 
356
          lxc-ls -C1
 
357
        
 
358
.fi
 
359
will display the containers list in one column or:
 
360
 
 
361
.nf
 
362
          lxc-ls -l
 
363
        
 
364
.fi
 
365
will display the containers list and their permissions.
 
366
.PP
 
367
\fBlxc-ps\fR will display the pids for a specific
 
368
container. Like \fBlxc-ls\fR, \fBlxc-ps\fR
 
369
is built on top of \fBps\fR and accepts the same
 
370
options, eg:
 
371
 
 
372
.nf
 
373
lxc-ps --name foo --forest
 
374
.fi
 
375
will display the processes hierarchy for the processes
 
376
belonging the 'foo' container.
 
377
 
 
378
.nf
 
379
lxc-ps --lxc
 
380
.fi
 
381
will display all the containers and their processes.
 
382
.PP
 
383
\fBlxc-info\fR gives informations for a specific
 
384
container, at present time, only the state of the container is
 
385
displayed.
 
386
.PP
 
387
Here is an example on how the combination of these commands
 
388
allow to list all the containers and retrieve their state.
 
389
 
 
390
.nf
 
391
          for i in $(lxc-ls -1); do
 
392
            lxc-info -n $i
 
393
          done
 
394
        
 
395
.fi
 
396
And displaying all the pids of all the containers:
 
397
 
 
398
.nf
 
399
          for i in $(lxc-ls -1); do
 
400
            lxc-ps --name $i --forest
 
401
          done
 
402
        
 
403
.fi
 
404
.PP
 
405
\fBlxc-netstat\fR display network information for
 
406
a specific container. This command is built on top of
 
407
the \fBnetstat\fR command and will accept its
 
408
options
 
409
.PP
 
410
The following command will display the socket informations for
 
411
the container 'foo'.
 
412
 
 
413
.nf
 
414
          lxc-netstat -n foo -tano
 
415
        
 
416
.fi
 
417
.SS "MONITORING THE CONTAINERS"
 
418
.PP
 
419
It is sometime useful to track the states of a container,
 
420
for example to monitor it or just to wait for a specific
 
421
state in a script.
 
422
.PP
 
423
\fBlxc-monitor\fR command will monitor one or
 
424
several containers. The parameter of this command accept a
 
425
regular expression for example:
 
426
 
 
427
.nf
 
428
          lxc-monitor -n "foo|bar"
 
429
        
 
430
.fi
 
431
will monitor the states of containers named 'foo' and 'bar', and:
 
432
 
 
433
.nf
 
434
          lxc-monitor -n ".*"
 
435
        
 
436
.fi
 
437
will monitor all the containers.
 
438
.PP
 
439
For a container 'foo' starting, doing some work and exiting,
 
440
the output will be in the form:
 
441
 
 
442
.nf
 
443
          'foo' changed state to [STARTING]
 
444
          'foo' changed state to [RUNNING]
 
445
          'foo' changed state to [STOPPING]
 
446
          'foo' changed state to [STOPPED]
 
447
        
 
448
.fi
 
449
.PP
 
450
\fBlxc-wait\fR command will wait for a specific
 
451
state change and exit. This is useful for scripting to
 
452
synchronize the launch of a container or the end. The
 
453
parameter is an ORed combination of different states. The
 
454
following example shows how to wait for a container if he went
 
455
to the background.
 
456
 
 
457
.nf
 
458
 
 
459
          # launch lxc-wait in background
 
460
          lxc-wait -n foo -s STOPPED &
 
461
          LXC_WAIT_PID=$!
 
462
 
 
463
          # this command goes in background
 
464
          lxc-execute -n foo mydaemon &
 
465
 
 
466
          # block until the lxc-wait exits
 
467
          # and lxc-wait exits when the container
 
468
          # is STOPPED
 
469
          wait $LXC_WAIT_PID
 
470
          echo "'foo' is finished"
 
471
 
 
472
        
 
473
.fi
 
474
.SS "SETTING THE CONTROL GROUP FOR A CONTAINER"
 
475
.PP
 
476
The container is tied with the control groups, when a
 
477
container is started a control group is created and associated
 
478
with it. The control group properties can be read and modified
 
479
when the container is running by using the lxc-cgroup command.
 
480
.PP
 
481
\fBlxc-cgroup\fR command is used to set or get a
 
482
control group subsystem which is associated with a
 
483
container. The subsystem name is handled by the user, the
 
484
command won't do any syntax checking on the subsystem name, if
 
485
the subsystem name does not exists, the command will fail.
 
486
.PP
 
487
 
 
488
.nf
 
489
          lxc-cgroup -n foo cpuset.cpus
 
490
        
 
491
.fi
 
492
will display the content of this subsystem.
 
493
 
 
494
.nf
 
495
          lxc-cgroup -n foo cpu.shares 512
 
496
        
 
497
.fi
 
498
will set the subsystem to the specified value.
 
499
.SH "BUGS"
 
500
.PP
 
501
The \fBlxc\fR is still in development, so the
 
502
command syntax and the API can change. The version 1.0.0 will be
 
503
the frozen version.
 
504
.SH "SEE ALSO"
 
505
.PP
 
506
\fBlxc\fR(1),
 
507
\fBlxc-create\fR(1),
 
508
\fBlxc-destroy\fR(1),
 
509
\fBlxc-start\fR(1),
 
510
\fBlxc-stop\fR(1),
 
511
\fBlxc-execute\fR(1),
 
512
\fBlxc-console\fR(1),
 
513
\fBlxc-monitor\fR(1),
 
514
\fBlxc-wait\fR(1),
 
515
\fBlxc-cgroup\fR(1),
 
516
\fBlxc-ls\fR(1),
 
517
\fBlxc-ps\fR(1),
 
518
\fBlxc-info\fR(1),
 
519
\fBlxc-freeze\fR(1),
 
520
\fBlxc-unfreeze\fR(1),
 
521
\fBlxc.conf\fR(5)
 
522
.SH "AUTHOR"
 
523
.PP
 
524
Daniel Lezcano <daniel.lezcano@free.fr>