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


Action ""

Execute a docker command.

Schema definitions

definitions =
    type: 'object'
    allOf: [
      $ref: '#/definitions/docker'
          type: ['boolean', 'string']
          description: '''
          Serialize the command into a file and execute it with bash.
          oneOf: [
            type: 'string'
            typeof: 'function'
          description: '''
          String, Object or array; Command to execute. A value provided as a
          function is interpreted as an action and will be called by forwarding
          the config object. The result is the expected to be the command
          to execute.
          type: 'string'
          description: '''
          Current working directory from where to execute the command.
          $ref: 'module://@nikitajs/core/src/actions/execute#/definitions/config/properties/code'
          default: {}
          $ref: '#/definitions/docker'
          $ref: 'module://@nikitajs/core/src/actions/execute#/definitions/config/properties/format'
    required: ['command']
  # Note, we can't use additionalProperties properties with anyOf for now,
  # from the doc: "There are some proposals to address this in the next
  # version of the JSON schema specification."
  # additionalProperties: false
    type: 'object'
    description: '''
    Isolate all the parent configuration properties into a docker
    property, used when providing and cascading a docker configuration at
    a global scale.
        type: 'boolean'
        description: '''
        Use the `docker compose` (or `docker-compose`) command instead of
        type: 'string'
        description: '''
        The value associated with the `DOCKER_HOST` environment variable,
        for example `tcp://dind:2375`.
        type: 'string'
        format: 'hostname'
        description: '''
        Name of the docker-machine, required if using docker-machine.
        type: 'object'
        default: {}
        description: '''
        Options passed to the `docker` or `docker compose` command.


handler = ({config, tools: {find}}) ->
  # Merge global config
  config.docker = await find ({config: {docker}}) -> docker
  config = merge config, config.docker
  # Build Docker 
  config.opts = for option, value of config.opts
    continue if value is null
    value = 'true' if value is true
    value = 'false' if value is false
    if option in ['tlsverify'] then  "--#{option}" else "--#{option}=#{value}"
  config.opts = config.opts.join ' '
    await @execute
      code: config.code
      format: config.format
      trap: true
      command: [
        if config.docker_host
          export DOCKER_HOST=#{config.docker_host}
        if config.machine
          if command -v docker-machine ; then echo 1; fi
          machine='#{config.machine or ''}'
          if [ -z "#{config.machine or ''}" ]; then exit 5; fi
          if docker-machine status "${machine}" | egrep 'Stopped|Saved'; then
            docker-machine start "${machine}";
          eval "$(docker-machine env ${machine})"
        if config.compose
          bin=`command -v docker-compose >/dev/null 2>&1  && echo "docker-compose $opts" || echo "docker $opts compose"` 
          $bin #{config.command}
          "docker #{config.opts} #{config.command}"
      ].join '\n'
  catch err
    throw Error err.stderr.trim() if utils.string.lines(err.stderr.trim()).length is 1
    throw Error err.stderr.trim().replace 'Error response from daemon: ', '' if /^Error response from daemon/.test err.stderr


module.exports =
  handler: handler
    argument_to_config: 'command'
    definitions: definitions


utils = require '../utils'
{merge} = require 'mixme'
Edit on GitHub

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