Docker Tasks
Build
Builds Docker image
php
<?php
$this->taskDockerBuild()->run();
$this->taskDockerBuild('path/to/dir')
->tag('database')
->run();
?>Class Build @package Robo\Task\Docker
tag($tag)*param string$tagenableBuildKit()*return$thissetOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.
Commit
Commits docker container to an image
$this->taskDockerCommit($containerId)
->name('my/database')
->run();
// alternatively you can take the result from DockerRun task:
$result = $this->taskDockerRun('db')
->exec('./prepare_database.sh')
->run();
$task->dockerCommit($result)
->name('my/database')
->run();name($name)*param string$namesetOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.
Exec
Executes command inside running Docker container
php
<?php
$test = $this->taskDockerRun('test_env')
->detached()
->run();
$this->taskDockerExec($test)
->interactive()
->exec('./runtests')
->run();
// alternatively use commands from other tasks
$this->taskDockerExec($test)
->interactive()
->exec($this->taskCodecept()->suite('acceptance'))
->run();
?>detached()*return$thisexec($command)*param string|\Robo\Contract\CommandInterface$commandsetOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.
Pull
Pulls an image from DockerHub
php
<?php
$this->taskDockerPull('wordpress')
->run();
?>setOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.
Remove
Remove docker container
php
<?php
$this->taskDockerRemove($container)
->run();
?>setOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.
Run
Performs docker run on a container.
php
<?php
$this->taskDockerRun('mysql')->run();
$result = $this->taskDockerRun('my_db_image')
->env('DB', 'database_name')
->volume('/path/to/data', '/data')
->detached()
->publish(3306)
->name('my_mysql')
->run();
// retrieve container's cid:
$this->say("Running container ".$result->getCid());
// execute script inside container
$result = $this->taskDockerRun('db')
->exec('prepare_test_data.sh')
->run();
$this->taskDockerCommit($result)
->name('test_db')
->run();
// link containers
$mysql = $this->taskDockerRun('mysql')
->name('wp_db') // important to set name for linked container
->env('MYSQL_ROOT_PASSWORD', '123456')
->run();
$this->taskDockerRun('wordpress')
->link($mysql)
->publish(80, 8080)
->detached()
->run();
?>detached()*return$thisexec($run)*param string|\Robo\Contract\CommandInterface$runvolume($from, $to = null)*param string$frompublish($port = null, $portTo = null)*param null|int$portcontainerWorkdir($dir)*param string$diruser($user)*param string$userprivileged()*return$thisname($name)*param string$namelink($name, $alias)*param string|\Robo\Task\Docker\Result$nametmpDir($dir)*param string$dirgetTmpDir()@return stringgetUniqId()@return stringsetOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.
Start
Starts Docker container
php
<?php
$this->taskDockerStart($cidOrResult)
->run();
?>setOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.
Stop
Stops Docker container
php
<?php
$this->taskDockerStop($cidOrResult)
->run();
?>setOutput($output)Sets the Console Output.setProcessInput($input)Pass an input to the process. Can be resource created with fopen() or stringdir($dir)Changes working directory of commandarg($arg)Pass argument to executable. Its value will be automatically escaped.args($args)Pass methods parameters as arguments to executable. Argument valuesrawArg($arg)Pass the provided string in its raw (as provided) form as an argument to executable.option($option, $value = null, $separator = null)Pass option to executable. Options are prefixed with--, value can be provided in second parameter.options(array $options, $separator = null)Pass multiple options to executable. The associative array containsoptionList($option, $value = null, $separator = null)Pass an option with multiple values to executable. Value can be a string or array.