# Building LXC containers ## Overview `lxcbuild` utility creates a LXC container based on its build recipe and build context path given in command line parameter. If a filename is given, the build recipe is loaded from the file and the directory in which the file resides is taken as build context, ie. all relative paths are resolved from it. In case a directory path is passed as parameter, the directory is then used as build context and a file called `lxcfile` from the given directory is used as build recipe. ### Usage ```bash lxcbuild where the buildpath can be either specific lxcfile or a directory containing one ``` ## Directives used in lxcfile The *lxcfile* syntax is designed to resemble *Dockerfile* syntax in order to ease the potential transition. Since LXC operates on much lower level of abstraction than Docker, some principles are applied more explicitly and verbosely. Major difference between Docker and *lxcbuild* is that every directive in *Dockerfile* creates a new filesystem layer whereas layers in *lxcbuild* are managed manually. ### IMAGE - **Usage:** `IMAGE ` - **Description:** Sets container name. Every *lxcfile* needs to have one, otherwise no LXC config can be written and no `RUN` scripts can be run. LXC configuration file is written to path `/var/lib/lxc//config` - **Docker equivalent:** `-t` in `docker build` command line parameters - **Populates LXC field:** `lxc.uts.name` ### LAYER - **Usage:** `LAYER ` - **Description:** Includes OverlayFS layer. Unlike *Dockerfile*'s `FROM`, in *lxcfile* all layers need to be defined. The `LAYER` directives are given from the lowermost to the uppermost layer, where the lowermost is usually the basic operating system and the uppermost is the working layer in which all subsequent `RUN` commands and other action will take place. - **Docker equivalent:** `FROM` - **Populates LXC field:** `lxc.rootfs.path` ### MERGE - **Usage:** `MERGE ` - **Description:** Runs `` on LXC host and passes all layer paths as parameter to this script. This helps you to resolve the conflicts in cases where you mix multiple OverlayFS layers with overlapping files, ie. package manager cache. The idea is that all layers are read separately by the `` script and the fixed result is written back to the uppermost layer. - **Docker equivalent:** None - **Populates LXC field:** None ### RUN - **Usage:** ```bash RUN