run: Run a containerised command, and wait until finished

View source: R/run.R

runR Documentation

Run a containerised command, and wait until finished

Description

Run a containerised command, and wait until finished

Usage

run(
  container_id,
  command,
  args = NULL,
  volumes = NULL,
  workspace = NULL,
  environment_variables = NULL,
  debug = FALSE,
  verbose = FALSE,
  stdout = "|",
  stderr = "|"
)

Arguments

container_id

The name of the container, usually the repository name on dockerhub.

command

Character scalar, the command to run. If you are running .bat or .cmd files on Windows, make sure you read the 'Batch files' section in the process manual page.

args

Character vector, arguments to the command.

volumes

Which volumes to be mounted. Format: a character vector, with each element containing the source path and container path concatenated with a ":". For example: c("/source_folder:/container_folder").

workspace

Which working directory to run the command in.

environment_variables

A character vector of environment variables. Format: c("ENVVAR=VALUE").

debug

If TRUE, a command will be printed that the user can execute to enter the container.

verbose

Whether or not to print output

stdout

What to do with standard output of the command. Default ("|") means to include it as an item in the results list. If it is the empty string (""), then the child process inherits the standard output stream of the R process. If it is a string other than "|" and "", then it is taken as a file name and the output is redirected to this file.

stderr

What to do with standard error of the command. Default ("|") means to include it as an item in the results list. If it is the empty string (""), then the child process inherits the standard error stream of the R process. If it is a string other than "|" and "", then it is taken as a file name and the standard error is redirected to this file.

Examples

if (test_docker_installation()) {
  set_default_config(create_docker_config(), permanent = FALSE)

  # running a command
  run("alpine", "echo", c("hello"))

  # mounting a folder
  folder <- tempdir()
  write("i'm a mounted file", paste0(folder, "/file.txt"))
  run("alpine", "cat", c("/mounted_folder/file.txt"), volumes = paste0(folder, "/:/mounted_folder"))
}


dynverse/babelwhale documentation built on July 31, 2023, 2:11 a.m.