   buildScriptPaths = (instance) ->
     [scriptDir = "#{config.compose.scriptBaseDir}/#{config.domain}/#{instance}", "#{scriptDir}/docker-compose.yml"]
 
+  composeProject = (instance) -> "#{config.domain}-#{instance}"
+
   start: (instance, composition, data) ->
     eventEmitter = new events.EventEmitter()
     compose = yaml.safeDump composition
     [scriptDir, scriptPath] = buildScriptPaths instance
+    composeProjectName = composeProject instance
 
     pullCb = (data) ->
       data = data.toString()


    ensureMkdir scriptDir, ->
      writeFile scriptPath, compose, ->
        runCmd 'docker-compose', ['-f', scriptPath, '-p', instance, 'pull'], env, {stdout: pullCb, stderr: emitLogCb}, ->
          runCmd 'docker-compose', ['-f', scriptPath, '-p', instance, 'up', '-d', '--remove-orphans'], env, {stderr: emitLogCb}, ->
            console.log 'Done, started', instance
    eventEmitter

  stop: (instance, data) ->
    eventEmitter = new events.EventEmitter()
    [scriptDir, scriptPath] = buildScriptPaths instance

    env = buildEnv config, data
    emitLogCb = (data) -> eventEmitter.emit 'teardown-log', data.toString()

    runCmd 'docker-compose', ['-f', scriptPath, '-p', instance, 'down', '--remove-orphans'], env, {stderr: emitLogCb}, ->
      console.log 'Done, stopped', instance
    eventEmitter

#

    console.log 'success', cmd, args
    spawned.stdout.on 'data', callbacks.stdout if callbacks.stdout
    spawned.stderr.on 'data', callbacks.stderr if callbacks.stderr
    spawned.on 'close', exitCb

ensureMkdir = (scriptDir, success) ->
  mkdirp scriptDir, (err) ->
