# Docker Tasks ## Build Builds Docker image ```php taskDockerBuild()->run(); $this->taskDockerBuild('path/to/dir') ->tag('database') ->run(); ?> ``` Class Build @package Robo\Task\Docker * `tag($tag)` * `param string` $tag * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options 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` $name * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options to executable. Value can be a string or array. ## Exec Executes command inside running Docker container ```php 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` $this * `interactive()` * `return` $this * `exec($command)` * `param string|\Robo\Contract\CommandInterface` $command * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options to executable. Value can be a string or array. ## Pull Pulls an image from DockerHub ```php taskDockerPull('wordpress') ->run(); ?> ``` * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options to executable. Value can be a string or array. ## Remove Remove docker container ```php taskDockerRemove($container) ->run(); ?> ``` * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options to executable. Value can be a string or array. ## Run Performs `docker run` on a container. ```php 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` $this * `interactive()` * `return` $this * `exec($run)` * `param string|\Robo\Contract\CommandInterface` $run * `volume($from, $to = null)` * `param string` $from * `env($variable, $value = null)` * `param string` $variable * `publish($port = null, $portTo = null)` * `param null|int` $port * `containerWorkdir($dir)` * `param string` $dir * `user($user)` * `param string` $user * `privileged()` * `return` $this * `name($name)` * `param string` $name * `link($name, $alias)` * `param string|\Robo\Task\Docker\Result` $name * `tmpDir($dir)` * `param string` $dir * `getTmpDir()` @return string * `getUniqId()` @return string * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options to executable. Value can be a string or array. ## Start Starts Docker container ```php taskDockerStart($cidOrResult) ->run(); ?> ``` * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options to executable. Value can be a string or array. ## Stop Stops Docker container ```php taskDockerStop($cidOrResult) ->run(); ?> ``` * `dir($dir)` Changes working directory of command * `printed($arg)` Should command output be printed * `arg($arg)` Pass argument to executable. Its value will be automatically escaped. * `args($args)` Pass methods parameters as arguments to executable. Argument values * `rawArg($arg)` Pass the provided string in its raw (as provided) form as an argument to executable. * `option($option, $value = null)` Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. * `optionList($option, $value = null)` Pass multiple options to executable. Value can be a string or array.