github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/drivers/external/lxc.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: 'Drivers: LXC'
     4  sidebar_title: LXC
     5  description: The LXC task driver is used to run application containers using LXC.
     6  ---
     7  
     8  # LXC Driver
     9  
    10  Name: `lxc`
    11  
    12  The `lxc` driver provides an interface for using LXC for running application
    13  containers. You can download the external LXC driver [here][lxc-driver]. For more detailed instructions on how to set up and use this driver, please refer to the [LXC guide][lxc-guide].
    14  
    15  ~> **Note:** The LXC client set up has changed in Nomad 0.9. You must use the new [plugin syntax][plugin] and install the external LXC driver in the [plugin_dir][plugin_dir] prior to upgrading. See [plugin options][plugin-options] below for an example. Note the job specification remains the same.
    16  
    17  ## Task Configuration
    18  
    19  ```hcl
    20  task "busybox" {
    21    driver = "lxc"
    22  
    23    config {
    24      log_level = "trace"
    25      verbosity = "verbose"
    26      template = "/usr/share/lxc/templates/lxc-busybox"
    27      template_args = []
    28  
    29      # these optional values can be set in the template
    30      distro =          ""
    31      release =         ""
    32      arch =            ""
    33      image_variant =   "default"
    34      image_server =    "images.linuxcontainers.org"
    35      gpg_key_id =      ""
    36      gpg_key_server =  ""
    37      disable_gpg =     false
    38      flush_cache =     false
    39      force_cache =     false
    40    }
    41  }
    42  ```
    43  
    44  The `lxc` driver supports the following configuration in the job spec:
    45  
    46  - `template` - The LXC template to run.
    47  
    48    ```hcl
    49    config {
    50      template = "/usr/share/lxc/templates/lxc-alpine"
    51    }
    52    ```
    53  
    54  - `template_args` - A list of argument strings to pass into the template.
    55  
    56  - `log_level` - (Optional) LXC library's logging level. Defaults to `error`.
    57    Must be one of `trace`, `debug`, `info`, `warn`, or `error`.
    58  
    59    ```hcl
    60    config {
    61      log_level = "debug"
    62    }
    63    ```
    64  
    65  - `verbosity` - (Optional) Enables extra verbosity in the LXC library's
    66    logging. Defaults to `quiet`. Must be one of `quiet` or `verbose`.
    67  
    68    ```hcl
    69    config {
    70      verbosity = "quiet"
    71    }
    72    ```
    73  
    74  - `volumes` - (Optional) A list of `host_path:container_path` strings to
    75    bind-mount host paths to container paths. Mounting host paths outside of the
    76    [allocation working directory] is allowed by default. You can prevent
    77    mounting host paths outside of the [allocation working directory] on
    78    individual clients by setting the [`volumes_enabled`](#volumes_enabled)
    79    option to `false` in the client's configuration
    80  
    81    ~> **Note:** Unlike the similar option for the docker driver, this
    82    option must not have an absolute path as the `container_path`
    83    component. This will cause an error when submitting a job.
    84  
    85    Setting this does not affect the standard bind-mounts of `alloc`,
    86    `local`, and `secrets`, which are always created.
    87  
    88    ```hcl
    89    config {
    90      volumes = [
    91        # Use absolute paths to mount arbitrary paths on the host
    92        "/path/on/host:path/in/container",
    93  
    94        # Use relative paths to rebind paths already in the allocation dir
    95        "relative/to/task:also/in/container"
    96      ]
    97    }
    98    ```
    99  
   100  - `release` - (Optional) The name/version of the distribution. By default this is set by the template.
   101  
   102  - `arch` - (Optional) The architecture of the container. By default this is set by the template.
   103  
   104  - `image_server` - (Optional) The hostname of the image server. Defaults to `images.linuxcontainers.org`.
   105  
   106  - `image_variant` - (Optional) The variant of the image. Defaults to `default` or as set by the template.
   107  
   108  - `disable_gpg` - (Optional) Disable GPG validation of images. Defaults to `false`, and enabling this flag is not recommended.
   109  
   110  - `flush_cache` - (Optional) Flush the local copy of the image (if present) and force it to be fetched from the image server. Defaults to `false`.
   111  
   112  - `force_cache` - (Optional) Force the use of the local copy even if expired. Defaults to `false`.
   113  
   114  - `gpg_key_server`: GPG key server used for checking image signatures. Default is set by the underlying LXC library.
   115  
   116  - `gpg_key_id`: GPG key ID used for checking image signatures. Default is set by the underlying LXC library.
   117  
   118  ## Networking
   119  
   120  Currently the `lxc` driver only supports host networking. See the `none`
   121  networking type in the `lxc.container.conf` [manual][lxc_man] for more
   122  information.
   123  
   124  ## Client Requirements
   125  
   126  The `lxc` driver requires the following:
   127  
   128  - 64-bit Linux host
   129  - The `linux_amd64` Nomad binary
   130  - The LXC driver binary placed in the [plugin_dir][plugin_dir] directory.
   131  - `liblxc` to be installed
   132  - `lxc-templates` to be installed
   133  
   134  ## Plugin Options
   135  
   136  - `enabled` - The `lxc` driver may be disabled on hosts by setting this option to `false` (defaults to `true`).
   137  
   138  - `volumes_enabled`<a id="volumes_enabled"></a> - Specifies whether host can bind-mount host paths to container paths (defaults to `true`).
   139  
   140  - `lxc_path` - The location in which all containers are stored (commonly defaults to `/var/lib/lxc`). See [`lxc-create`][lxc-create] for more details.
   141  
   142  - `gc` stanza:
   143    - `container` - Defaults to `true`. This option can be used to disable Nomad
   144      from removing a container when the task exits. Under a name conflict,
   145      Nomad may still remove the dead container.
   146  
   147  An example of using these plugin options with the new [plugin
   148  syntax][plugin] is shown below:
   149  
   150  ```hcl
   151  plugin "nomad-driver-lxc" {
   152    config {
   153      enabled = true
   154      volumes_enabled = true
   155      lxc_path = "/var/lib/lxc"
   156      gc {
   157        container = false
   158      }
   159    }
   160  }
   161  ```
   162  
   163  Please note the plugin name should match whatever name you have specified for the external driver in the [plugin_dir][plugin_dir] directory.
   164  
   165  ## Client Configuration
   166  
   167  -> Only use this section for pre-0.9 releases of Nomad. If you are using Nomad
   168  0.9 or above, please see [plugin options][plugin-options]
   169  
   170  The `lxc` driver has the following [client-level options][client_options]:
   171  
   172  - `lxc.enable` - The `lxc` driver may be disabled on hosts by setting this
   173    option to `false` (defaults to `true`).
   174  
   175  ## Client Attributes
   176  
   177  The `lxc` driver will set the following client attributes:
   178  
   179  - `driver.lxc` - Set to `1` if LXC is found and enabled on the host node.
   180  - `driver.lxc.version` - Version of `lxc` e.g.: `1.1.0`.
   181  
   182  ## Resource Isolation
   183  
   184  This driver supports CPU and memory isolation via the `lxc` library. Network
   185  isolation is not supported as of now.
   186  
   187  [lxc-create]: https://linuxcontainers.org/lxc/manpages/man1/lxc-create.1.html
   188  [lxc-driver]: https://releases.hashicorp.com/nomad-driver-lxc
   189  [lxc-guide]: https://learn.hashicorp.com/tutorials/nomad/plugin-lxc
   190  [lxc_man]: https://linuxcontainers.org/lxc/manpages/man5/lxc.container.conf.5.html#lbAM
   191  [plugin]: /docs/configuration/plugin
   192  [plugin_dir]: /docs/configuration#plugin_dir
   193  [plugin-options]: #plugin-options
   194  [client_options]: /docs/configuration/client#options
   195  [allocation working directory]: /docs/runtime/environment#task-directories 'Task Directories'