lib/plugins/aws/invokeLocal/index.js/AwsInvokeLocal/invokeLocalDocker
class AwsInvokeLocal:  invokeLocalDocker() {
    const handler = this.options.functionObj.handler;

    return this.serverless.pluginManager.spawn('package').then(() =>
      BbPromise.all([
        this.checkDockerDaemonStatus(),
        this.checkDockerImage().then(exists => {
          return exists ? {} : this.pullDockerImage();
        }),
        this.getLayerPaths().then(layerPaths => this.buildDockerImage(layerPaths)),
        this.extractArtifact(),
      ]).then(
        results =>
          new BbPromise((resolve, reject) => {
            const imageName = results[2];
            const artifactPath = results[3];
            const configuredEnvVars = this.getConfiguredEnvVars();
            const envVarsFromOptions = this.getEnvVarsFromOptions();
            const envVars = _.merge(configuredEnvVars, envVarsFromOptions);
            const envVarsDockerArgs = _.flatMap(envVars, (value, key) => [
              '--env',
              `${key}=${value}`,
            ]);
            const dockerArgsFromOptions = this.getDockerArgsFromOptions();
            const dockerArgs = _.concat(
              ['run', '--rm', '-v', `${artifactPath}:/var/task`],
              envVarsDockerArgs,
              dockerArgsFromOptions,
              [imageName, handler, JSON.stringify(this.options.data)]
            );
            const docker = spawn('docker', dockerArgs);
            docker.stdout.on('data', buf => this.serverless.cli.consoleLog(buf.toString()));
            docker.stderr.on('data', buf => this.serverless.cli.consoleLog(buf.toString()));
            docker.on('exit', error => {
              return error ? reject(error) : resolve(imageName);
            });
          })
      )
    );
  }