docker_container_collection {stevedore} | R Documentation |
Management commands for working with docker containers
Description
Methods for working with docker containers. This object is
$container
within a docker_client
object.
Details
Below is reference documentation for all methods for version '1.29' of the docker API - other versions are available. This documentation is automatically generated from docker's API schema, and so inaccuracies may exist between it and stevedore's interface (especially references to JSON objects). Please report any documentation that might be improved at https://github.com/richfitz/stevedore/issues
Methods
container_create
Create a container. Similar to the cli command
docker create
ordocker container create
.Usage:
container_create(image, cmd = NULL, hostname = NULL, domainname = NULL, user = NULL, attach_stdin = NULL, attach_stdout = NULL, attach_stderr = NULL, ports = NULL, tty = NULL, open_stdin = NULL, stdin_once = NULL, env = NULL, health_check = NULL, args_escaped = NULL, volumes = NULL, working_dir = NULL, entrypoint = NULL, network_disabled = NULL, mac_address = NULL, on_build = NULL, labels = NULL, stop_signal = NULL, stop_timeout = NULL, shell = NULL, host_config = NULL, network = NULL, name = NULL)
Arguments:
image
: The name of the image to use when creating the containercmd
: Command to run specified as a string or an array of strings.hostname
: The hostname to use for the container, as a valid RFC 1123 hostname.domainname
: The domain name to use for the container.user
: The user that commands are run as inside the container.attach_stdin
: Whether to attach tostdin
.attach_stdout
: Whether to attach tostdout
.attach_stderr
: Whether to attach tostderr
.ports
: A character vector of port mappings between the container and host, in (1) the form<host>:<container>
(e.g.,10080:80
to map the container's port 80 to the host's port 10080),<ip>:<host>:<container>
to bind a specific host interface as well as a port (e.g., you can uselocalhost
or127.0.0.1
for the first element), (3) form<port>
to map the containers port to a random available port on the host s shorthand for<port>:<port>
, or (3) a single logical valueTRUE
indicating to map all container ports to random available ports on the host. You can use the$ports()
method in thedocker_container
object to query the port mapping of a running container. Multiple values can be provided to map multiple ports to the host (e.g.,c("80", "443:443")
.tty
: Attach standard streams to a TTY, includingstdin
if it is not closed.open_stdin
: Openstdin
stdin_once
: Closestdin
after one attached client disconnectsenv
: A list of environment variables to set inside the container in the form["VAR=value", ...]
. A variable without=
is removed from the environment, rather than to have an empty value.health_check
: A test to perform to check that the container is healthy. Construct with$types$health_config()
args_escaped
: Command is already escaped (Windows only)volumes
: A character vector of mappings of mount points on the host (or in volumes) to paths on the container. Each element must be of the form<path_host>:<path_container>
, possibly followed by:ro
for read-only mappings (i.e., the same syntax as the docker command line client).docker_volume
objects have a$map
method to help with generating these paths for volume mappings.working_dir
: The working directory for commands to run in.entrypoint
: The entry point for the container as a string or an array of strings.If the array consists of exactly one empty string (
[""]
) then the entry point is reset to system default (i.e., the entry point used by docker when there is noENTRYPOINT
instruction in theDockerfile
).network_disabled
: Disable networking for the container.mac_address
: MAC address of the container.on_build
:ONBUILD
metadata that were defined in the image'sDockerfile
.labels
: User-defined key/value metadata.stop_signal
: Signal to stop a container as a string or unsigned integer.stop_timeout
: Timeout to stop a container in seconds.shell
: Shell for whenRUN
,CMD
, andENTRYPOINT
uses a shell.host_config
: Container configuration that depends on the host we are running onnetwork
: This container's networking configuration.name
: Assign the specified name to the container. Must match/?[a-zA-Z0-9_-]+
.
get
Get a container by name or id
Usage:
get(id)
Arguments:
id
: A scalar character with the container's name or id (abbreviations of the id are allowed and will be resolved by the docker daemon).
help
Display help for this object
Usage:
help(help_type = getOption("help_type"))
Arguments:
help_type
: Passed toutils::help
, can be one of "text", "html" or "pdf" (or an abbreviation). By default it uses the valuegetOption("help_type")
and should follow the same behaviour as other R help (e.g., using "?")
container_list
List containers. Similar to the cli command
docker ps
ordocker container ls
.Usage:
container_list(all = NULL, limit = NULL, size = NULL, filters = NULL)
Arguments:
all
: Return all containers. By default, only running containers are shownlimit
: Return this number of most recently created containers, including non-running ones.size
: Return the size of container as fieldsSizeRw
andSizeRootFs
.filters
: Filters to process on the container list, as a named character vector. For examplec(status = "paused")
will only return paused containers. Available filters:ancestor
=(<image-name>[:<tag>]
,<image id>
, or<image@digest>
)before
=(<container id>
or<container name>
)expose
=(<port>[/<proto>]
|<startport-endport>/[<proto>]
)exited=<int>
containers with exit code of<int>
health
=(starting
|healthy
|unhealthy
|none
)id=<ID>
a container's IDisolation=
(default
|process
|hyperv
) (Windows daemon only)is-task=
(true
|false
)label=key
orlabel="key=value"
of a container labelname=<name>
a container's namenetwork
=(<network id>
or<network name>
)publish
=(<port>[/<proto>]
|<startport-endport>/[<proto>]
)since
=(<container id>
or<container name>
)status=
(created
|restarting
|running
|removing
|paused
|exited
|dead
)volume
=(<volume name>
or<mount point destination>
)
container_prune
Delete stopped containers. Similar to the cli command
docker container prune
.Usage:
container_prune(filters = NULL)
Arguments:
filters
: Filters to process on the prune list, as a named character vector.Available filters:
until=<timestamp>
Prune containers created before this timestamp. The<timestamp>
can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g.10m
,1h30m
) computed relative to the daemon machine's time.
container_delete
Remove a container. Similar to the cli command
docker rm
ordocker container rm
.Usage:
container_delete(id, delete_volumes = NULL, force = NULL, link = NULL)
Arguments:
id
: ID or name of the containerdelete_volumes
: Remove the volumes associated with the container.force
: If the container is running, kill it before removing it.link
: Remove the specified link associated with the container.
run
Run a command in a new container. This method does rather a lot, and wraps several other methods. It aims to mimic the behaviour of
docker run
in the command line tool. It will:Try to pull a container if it does not yet exist (see
$pull
indocker_image_collection
)Create the container (see
$create
indocker_container_collection
)Start the container (see
$start
indocker_container
)Optionally stream the logs, if not detached (see
$logs
indocker_container
Wait for the container to finish (see
$wait
indocker_container
)
It returns a list with a container object as
"container"
and a"docker_stream"
object containing logs as"logs"
). Ifrm = TRUE
anddetach = TRUE
the container object will be of limited utility and you will need to usereload = FALSE
on many methods (and some will not work) as the container will have been removed on exit.Unlike the command line version, interrupting the streaming logs will not necessarily kill the container but may leave it running in the background.
Unlike the command line version, the
attach = TRUE
simply attaches the output of the container and blocks the R session until it is complete. There is currently no way of sending input into the docker container. Similar to the cli command
docker run
.Usage:
run(image, cmd = NULL, ..., detach = FALSE, rm = FALSE, stream = stdout(), host_config = NULL)
Arguments:
image
: Image to run. Can be a name, id, or adocker_image
object.cmd
: Command to run in the container. Must be a character vector. If not specified then the defaultENTRYPOINT
andCMD
will be used (see the docker documentation for details)...
: Additional arguments passed through to$create
(seedocker_container_collection
. There are many possible arguments here.detach
: Detach the container as soon as it has started and return control to R. The container will run in the background. The returned object can be used to interrogate the container afterwards (seedocker_container
).rm
: Remove the container on exit.stream
: The stream to use to send output to, ifdetach = FALSE
. The default uses the standard output stream (i.e., wherecat
would send output). Other valid values are an R connection object, a string (interpreted as a filename) orFALSE
to prevent any output.host_config
: Passed through to$create
, as with...
.
See Also
docker_container
for information on
container objects.