Documentationcurrent version
Help us improve the docs by fixing typos and proposing enhancements.


Action "lxc.init"

Initialize a Linux Container with given image name, container name and config.


  • $status Was the container successfully created


const {$status} = await nikita.lxc.init({
  image: "ubuntu:18.04",
  container: "my_container"
})`Container was created: ${$status}`)

Implementation details

The current version 3.18 of lxd has an issue with lxc init waiting for configuration from stdin when there is no tty. This used to work before. Use [ -t 0 ] && echo 'tty' || echo 'notty' to detect the tty. The current fix is to prepend the init command with echo '' | .


We do not honors the configuration (-c) argument. Use the lxc.config.set for now.

Schema definitions

definitions =
    type: 'object'
        type: 'string'
        description: '''
        The image the container will use, name:[version] (e.g: ubuntu:16.04.).
        type: 'string'
        pattern: '(^[a-zA-Z][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9](?!\-)$)|(^[a-zA-Z]$)'
        description: '''
        The name of the container. Must:
        - be between 1 and 63 characters long
        - be made up exclusively of letters, numbers and dashes from the ASCII table
        - not start with a digit or a dash
        - not end with a dash
        type: 'string'
        description: '''
        Network name to add to the container (see
        type: 'string'
        description: '''
        Storage name where to store the container, [default_storage] by
        type: 'string'
        description: '''
        Profile to set this container up.
        type: 'boolean'
        default: false
        description: '''
        If true, the container will be deleted when stopped.
        type: 'boolean'
        default: false
        description: '''
        If true, instantiate a VM instead of a container.
        type: 'boolean'
        default: false
        description: '''
        Start the container once initialized.
        type: 'string'
        description: '''
        If the LXC is clustered, instantiate the container on a specific node.
    required: ['image', 'container']


handler = ({config}) ->
  command_init = [
    'lxc', 'init', config.image, config.container
    "--network #{}" if
    "--storage #{}" if
    "--ephemeral" if config.ephemeral
    "--vm" if config.vm
    "--profile #{config.profile}" if config.profile
    "--target #{}" if
  ].join ' '
  # Execution
  {$status} = await @execute
    command: """
    lxc info #{config.container} >/dev/null && exit 42
    echo '' | #{command_init}
    code: [0, 42]
  await @lxc.start
    $if: config.start
    container: config.container


module.exports =
  handler: handler
    definitions: definitions
Edit on GitHub

Nikita is an open source project hosted on GitHub and developed by Adaltas.