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


Action "docker.compose.up"

Create and start containers according to a docker-compose.yml file nikita.docker.compose is an alias to nikita.docker.compose.up


  • err
    Error object if any.
  • executed
    if command was executed
  • stdout
    Stdout value(s) unless stdout option is provided.
  • stderr
    Stderr value(s) unless stderr option is provided.

Schema definitions

definitions =
    type: 'object'
        type: 'object'
        description: '''
        The content of the docker-compose.yml to write if not exist.
        type: 'boolean'
        default: true
        description: '''
        Inherited from nikita.file use when writing docker-compose.yml file.
        type: ['string', 'boolean']
        default: false
        description: '''
        Create a backup, append a provided string to the filename extension or
        a timestamp if value is not a string, only apply if the target file
        exists and is modified.
        type: 'boolean'
        default: true
        description: '''
        Run containers in detached mode.
        type: 'boolean'
        default: false
        description: '''
        Force to re-create the containers if the config and image have not
        type: 'array'
        items: type: 'string'
        description: '''
        Specify specific services to create.
        type: 'string'
        description: '''
        The docker-compose.yml absolute's file's path, required if no content
        is specified.


handler = ({config, tools: {find, log}}) ->
  # Global config
  config.docker = await find ({config: {docker}}) -> docker
  config[k] ?= v for k, v of config.docker
  # Validate parameters
  throw Error 'Missing docker-compose content or target' if not and not config.content?
  if config.content and not ?= "/tmp/nikita_docker_compose_#{}/docker-compose.yml"
    clean_target = true
  config.compose_env ?= []
  if config.compose_env.length and not config.target_env?
    config.target_env ?= "/tmp/nikita_docker_compose_#{}/.env"
    clean_target = true
  config.recreate ?= false # TODO: move to schema ?= [] = [] if not Array.isArray
  await @file.yaml
    $if: config.content?
    backup: config.backup
    content: config.content
    eof: config.eof
  await @file
    $if: config.compose_env.length
    backup: config.backup
    # If compose_env is an object
    # content: Object.keys(config.compose_env)
    #   .map( (key) => "#{key}=#{config.compose_env[key]}")
    #   .join('\n')
    # If compose_env is an array
    content: config.compose_env.join('\n')
    eof: config.eof
    target: config.target_env
  {$status, stdout} = await
    $shy: true
    command: "--file #{} ps -q | xargs docker #{utils.opts config} inspect"
    compose: true
    cwd: config.cwd
    uid: config.uid
    code: [0, 123]
    stdout_log: false
  unless $status
    $status = true
    containers = JSON.parse stdout
    $status = containers.some (container) -> not container.State.Running
    log "Docker created, need start" if $status
      $if: config.force or $status
      command: [
        "--file #{} up"
        '-d' if config.detached
        '--force-recreate' if config.force
      ].join ' '
      compose: true
      cwd: path.dirname
      uid: config.uid
  catch err
    throw err
    await @fs.remove
      $if: clean_target
    await @fs.remove
      $if: clean_target and config.target_env
      target: config.target_env


module.exports =
  handler: handler
    definitions: definitions


utils = require '../utils'
path = require 'path'
Edit on GitHub

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