github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/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 bind-mount host paths to container paths. Mounting host paths outside of the allocation directory can be disabled on clients by setting the [`volumes_enabled`](#volumes_enabled) option set to false. This will limit volumes to directories that exist inside the allocation directory. 75 76 ~> **Note:** Unlike the similar option for the docker driver, this 77 option must not have an absolute path as the `container_path` 78 component. This will cause an error when submitting a job. 79 80 Setting this does not affect the standard bind-mounts of `alloc`, 81 `local`, and `secrets`, which are always created. 82 83 ```hcl 84 config { 85 volumes = [ 86 # Use absolute paths to mount arbitrary paths on the host 87 "/path/on/host:path/in/container", 88 89 # Use relative paths to rebind paths already in the allocation dir 90 "relative/to/task:also/in/container" 91 ] 92 } 93 ``` 94 95 - `release` - (Optional) The name/version of the distribution. By default this is set by the template. 96 97 - `arch` - (Optional) The architecture of the container. By default this is set by the template. 98 99 - `image_server` - (Optional) The hostname of the image server. Defaults to `images.linuxcontainers.org`. 100 101 - `image_variant` - (Optional) The variant of the image. Defaults to `default` or as set by the template. 102 103 - `disable_gpg` - (Optional) Disable GPG validation of images. Defaults to `false`, and enabling this flag is not recommended. 104 105 - `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`. 106 107 - `force_cache` - (Optional) Force the use of the local copy even if expired. Defaults to `false`. 108 109 - `gpg_key_server`: GPG key server used for checking image signatures. Default is set by the underlying LXC library. 110 111 - `gpg_key_id`: GPG key ID used for checking image signatures. Default is set by the underlying LXC library. 112 113 ## Networking 114 115 Currently the `lxc` driver only supports host networking. See the `none` 116 networking type in the `lxc.container.conf` [manual][lxc_man] for more 117 information. 118 119 ## Client Requirements 120 121 The `lxc` driver requires the following: 122 123 - 64-bit Linux host 124 - The `linux_amd64` Nomad binary 125 - The LXC driver binary placed in the [plugin_dir][plugin_dir] directory. 126 - `liblxc` to be installed 127 - `lxc-templates` to be installed 128 129 ## Plugin Options 130 131 - `enabled` - The `lxc` driver may be disabled on hosts by setting this option to `false` (defaults to `true`). 132 133 - `volumes_enabled`<a id="volumes_enabled"></a> - Specifies whether host can bind-mount host paths to container paths (defaults to `true`). 134 135 - `lxc_path` - The location in which all containers are stored (commonly defaults to `/var/lib/lxc`). See [`lxc-create`][lxc-create] for more details. 136 137 - `gc` stanza: 138 - `container` - Defaults to `true`. This option can be used to disable Nomad 139 from removing a container when the task exits. Under a name conflict, 140 Nomad may still remove the dead container. 141 142 An example of using these plugin options with the new [plugin 143 syntax][plugin] is shown below: 144 145 ```hcl 146 plugin "nomad-driver-lxc" { 147 config { 148 enabled = true 149 volumes_enabled = true 150 lxc_path = "/var/lib/lxc" 151 gc { 152 container = false 153 } 154 } 155 } 156 ``` 157 158 Please note the plugin name should match whatever name you have specified for the external driver in the [plugin_dir][plugin_dir] directory. 159 160 ## Client Configuration 161 162 -> Only use this section for pre-0.9 releases of Nomad. If you are using Nomad 163 0.9 or above, please see [plugin options][plugin-options] 164 165 The `lxc` driver has the following [client-level options][client_options]: 166 167 - `lxc.enable` - The `lxc` driver may be disabled on hosts by setting this 168 option to `false` (defaults to `true`). 169 170 ## Client Attributes 171 172 The `lxc` driver will set the following client attributes: 173 174 - `driver.lxc` - Set to `1` if LXC is found and enabled on the host node. 175 - `driver.lxc.version` - Version of `lxc` e.g.: `1.1.0`. 176 177 ## Resource Isolation 178 179 This driver supports CPU and memory isolation via the `lxc` library. Network 180 isolation is not supported as of now. 181 182 [lxc-create]: https://linuxcontainers.org/lxc/manpages/man1/lxc-create.1.html 183 [lxc-driver]: https://releases.hashicorp.com/nomad-driver-lxc 184 [lxc-guide]: https://learn.hashicorp.com/nomad/using-plugins/lxc 185 [lxc_man]: https://linuxcontainers.org/lxc/manpages/man5/lxc.container.conf.5.html#lbAM 186 [plugin]: /docs/configuration/plugin 187 [plugin_dir]: /docs/configuration#plugin_dir 188 [plugin-options]: #plugin-options 189 [client_options]: /docs/configuration/client#options