| docker_container {stevedore} | R Documentation |
Management commands for working with a particular docker container
Description
Methods for working with a particular docker container. Container
objects are returned by creating or running a docker container, or
by using $container$get to fetch an existing container by
name or id.
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
image_commitCreate a new image from a container. Similar to the cli command
docker commitordocker container commit.Usage:
image_commit(repo = NULL, tag = NULL, author = NULL, changes = NULL, comment = NULL, pause = NULL, hostname = NULL, domainname = NULL, user = NULL, attach_stdin = NULL, attach_stdout = NULL, attach_stderr = NULL, exposed_ports = NULL, tty = NULL, open_stdin = NULL, stdin_once = NULL, env = NULL, cmd = NULL, healthcheck = NULL, args_escaped = NULL, image = 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)Arguments:
repo: Repository name for the created imagetag: Tag name for the create imageauthor: Author of the image (e.g.,John Hannibal Smith <hannibal@a-team.com>)changes:Dockerfileinstructions to apply while committingcomment: Commit messagepause: Whether to pause the container before committinghostname: 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.exposed_ports: A character vector of port mappings between the container and host, in (1) the form<host>:<container>(e.g.,10080:80to 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 uselocalhostor127.0.0.1for 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 valueTRUEindicating to map all container ports to random available ports on the host. You can use the$ports()method in thedocker_containerobject 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, includingstdinif it is not closed.open_stdin: Openstdinstdin_once: Closestdinafter 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.cmd: Command to run specified as a string or an array of strings.healthcheck: A test to perform to check that the container is healthy.args_escaped: Command is already escaped (Windows only)image: The name of the image to use when creating the containervolumes: 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:rofor read-only mappings (i.e., the same syntax as the docker command line client).docker_volumeobjects have a$mapmethod 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 noENTRYPOINTinstruction in theDockerfile).network_disabled: Disable networking for the container.mac_address: MAC address of the container.on_build:ONBUILDmetadata 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, andENTRYPOINTuses a shell.
cp_inCopy files or directory into the container. This function tries to follow the same semantics as the command line
docker cpcommand.Usage:
cp_in(src, dest)
Arguments:
src: File or directory to copy into the container.dest: Destination within the container. This must be a single path.
cp_outCopy files or directories from the container. This function tries to follow the same semantics as the command line
docker cpcommand.Usage:
cp_out(src, dest)
Arguments:
src: File or directory within the container to copy to the host.dest: Destination on the host. This must be a single path.
container_changesGet changes on a container's filesystem. Returns which files in a container's filesystem have been added, deleted, or modified. The
Kindof modification can be one of:0: Modified1: Added2: Deleted. Similar to the cli commanddocker diffordocker container diff.
Usage:
container_changes()
execCreate and run an exec instance. Run a command inside a running container. Similar to the cli command
docker exec.Usage:
exec(cmd, stdin = NULL, stdout = TRUE, stderr = TRUE, detach_keys = NULL, tty = NULL, env = NULL, privileged = NULL, user = NULL, detach = FALSE, stream = stdout())Arguments:
cmd: Command to run, as a string or array of strings.stdin: Attach tostdinof the exec command.stdout: Attach tostdoutof the exec command.stderr: Attach tostderrof the exec command.detach_keys: Override the key sequence for detaching a container. Format is a single character[a-Z]orctrl-<value>where<value>is one of:a-z,@,^,[,,or_.tty: Allocate a pseudo-TTY.env: A list of environment variables in the form["VAR=value", ...].privileged: Runs the exec process with extended privileges.user: The user, and optionally, group to run the exec process inside the container. Format is one of:user,user:group,uid, oruid:gid.detach: Detach from the command.stream: The stream to send output to. Options here are (1) a connection object (e.g.stdout(),stderr()or a writable open file connection object, (2) a scalar character indicating a filename to write to, or (3)FALSEorNULLto disable any output.
exec_createCreate an exec instance. Run a command inside a running container. Similar to the cli command
docker exec.Usage:
exec_create(cmd, stdin = NULL, stdout = TRUE, stderr = TRUE, detach_keys = NULL, tty = NULL, env = NULL, privileged = NULL, user = NULL)Arguments:
cmd: Command to run, as a string or array of strings.stdin: Attach tostdinof the exec command.stdout: Attach tostdoutof the exec command.stderr: Attach tostderrof the exec command.detach_keys: Override the key sequence for detaching a container. Format is a single character[a-Z]orctrl-<value>where<value>is one of:a-z,@,^,[,,or_.tty: Allocate a pseudo-TTY.env: A list of environment variables in the form["VAR=value", ...].privileged: Runs the exec process with extended privileges.user: The user, and optionally, group to run the exec process inside the container. Format is one of:user,user:group,uid, oruid:gid.
container_exportExport a container. Export the contents of a container as a tarball. Similar to the cli command
docker exportordocker container export.Usage:
container_export()
container_archiveGet an archive of a filesystem resource in a container. Get a tar archive of a resource in the filesystem of container id.
Usage:
container_archive(path, dest)
Arguments:
path: Resource in the container's filesystem to archive.dest: Destination for the archive. Must be either a scalar character (representing a filename) orNULL, in which case a raw vector is returned.
helpDisplay 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 "?")
idReturn the container's id
Usage:
id()
imageReturn the image for this container, as a
docker_imageobject.Usage:
image()
inspectReturn detailed information about this container. Similar to the cli command
docker container inspect.Usage:
inspect(reload = TRUE)
Arguments:
reload: Logical scalar, indicating if the information should be refreshed from the daemon. This is useful to set toFALSEafter a container has been removed.
container_killKill a container. Send a POSIX signal to a container, defaulting to killing to the container. Similar to the cli command
docker killordocker container kill.Usage:
container_kill(signal = NULL)
Arguments:
signal: Signal to send to the container as an integer or string (e.g.SIGINT)
labelsReturn labels for this container
Usage:
labels(reload = TRUE)
Arguments:
reload: Logical scalar, indicating if the information should be refreshed from the daemon. This is useful to set toFALSEafter a container has been removed.
container_logsGet container logs. Get
stdoutandstderrlogs from a container.Note: This endpoint works only for containers with the
json-fileorjournaldlogging driver. Similar to the cli commanddocker logsordocker container logs.Usage:
container_logs(follow = NULL, stdout = TRUE, stderr = TRUE, since = NULL, timestamps = NULL, tail = NULL, stream = stdout())Arguments:
follow: Return the logs as a stream.This will return a
101HTTP response with aConnection: upgradeheader, then hijack the HTTP connection to send raw output. For more information about hijacking and the stream format, hrefhttps://docs.docker.com/engine/api/1.29/#operation/ContainerAttachsee the documentation for the attach endpoint.stdout: Return logs fromstdoutstderr: Return logs fromstderrsince: Only return logs since this time, as a UNIX timestamptimestamps: Add timestamps to every log linetail: Only return this number of log lines from the end of the logs. Specify as an integer orallto output all log lines.stream: The stream to send output to. Options here are (1) a connection object (e.g.stdout(),stderr()or a writable open file connection object, (2) a scalar character indicating a filename to write to, or (3)FALSEorNULLto disable any output.
nameReturn name for this container
Usage:
name()
container_path_statGet information about files in a container. A response header
X-Docker-Container-Path-Statis return containing a base64 - encoded JSON object with some filesystem header information about the path.Usage:
container_path_stat(path)
Arguments:
path: Resource in the container's filesystem to archive.
container_pausePause a container. Use the cgroups freezer to suspend all processes in a container.
Traditionally, when suspending a process the
SIGSTOPsignal is used, which is observable by the process being suspended. With the cgroups freezer the process is unaware, and unable to capture, that it is being suspended, and subsequently resumed. Similar to the cli commanddocker pauseordocker container pause.Usage:
container_pause()
portsReturn a
data.frameof information about ports opened by this container. This is particularly useful in a container started withports = TRUE, where container ports are mapped to random ports on the host. Similar to the cli commanddocker container port.Usage:
ports(reload = TRUE)
Arguments:
reload: Logical scalar, indicating if the information should be refreshed from the daemon. This is useful to set toFALSEafter a container has been removed.
container_importExtract an archive of files or folders to a directory in a container. Upload a tar archive to be extracted to a path in the filesystem of container id.
Usage:
container_import(src, path, no_overwrite_dir_non_dir = NULL)
Arguments:
src: The input stream must be a tar archive compressed with one of the following algorithms: identity (no compression), gzip, bzip2, xz.path: Path to a directory in the container to extract the archive's contents into.no_overwrite_dir_non_dir: If '1', 'true', or 'True' then it will be an error if unpacking the given content would cause an existing directory to be replaced with a non-directory and vice versa.
reloadRefresh infomation on the container from the server, returning
$inspect()invisibly.Usage:
reload()
container_deleteRemove a container. Similar to the cli command
docker rmordocker container rm.Usage:
container_delete(delete_volumes = NULL, force = NULL, link = NULL)Arguments:
delete_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.
container_renameRename a container. Similar to the cli command
docker renameordocker container rename.Usage:
container_rename(name)
Arguments:
name: New name for the container
container_resizeResize a container TTY. Resize the TTY for a container. You must restart the container for the resize to take effect.
Usage:
container_resize(h = NULL, w = NULL)
Arguments:
h: Height of the tty session in charactersw: Width of the tty session in characters
container_restartRestart a container. Similar to the cli command
docker restartordocker container restart.Usage:
container_restart(t = NULL)
Arguments:
t: Number of seconds to wait before killing the container
container_startStart a container. Similar to the cli command
docker startordocker container start.Usage:
container_start(detach_keys = NULL)
Arguments:
detach_keys: Override the key sequence for detaching a container. Format is a single character[a-Z]orctrl-<value>where<value>is one of:a-z,@,^,[,,or_.
container_statsGet container stats based on resource usage. This endpoint returns a live stream of a container's resource usage statistics.
The
precpu_statsis the CPU statistic of last read, which is used for calculating the CPU usage percentage. It is not the same as thecpu_statsfield.If either
precpu_stats.online_cpusorcpu_stats.online_cpusis nil then for compatibility with older daemons the length of the correspondingcpu_usage.percpu_usagearray should be used. Similar to the cli commanddocker statsordocker container stats.Usage:
container_stats()
statusShort status of the container ("running", "exited", etc).
Usage:
status(reload = TRUE)
Arguments:
reload: Refresh container data?
container_stopStop a container. Similar to the cli command
docker stopordocker container stop.Usage:
container_stop(t = NULL)
Arguments:
t: Number of seconds to wait before killing the container
container_topList processes running inside a container. On Unix systems, this is done by running the
pscommand. This endpoint is not supported on Windows. Similar to the cli commanddocker topordocker container top.Usage:
container_top(ps_args = NULL)
Arguments:
ps_args: The arguments to pass tops. For example,aux
container_unpauseUnpause a container. Resume a container which has been paused. Similar to the cli command
docker unpauseordocker container unpause.Usage:
container_unpause()
container_updateUpdate a container. Change various configuration options of a container without having to recreate it. Similar to the cli command
docker updateordocker container update.Usage:
container_update(cpu_shares = NULL, memory = NULL, cgroup_parent = NULL, blkio_weight = NULL, blkio_weight_device = NULL, blkio_device_read_bps = NULL, blkio_device_write_bps = NULL, blkio_device_read_iops = NULL, blkio_device_write_iops = NULL, cpu_period = NULL, cpu_quota = NULL, cpu_realtime_period = NULL, cpu_realtime_runtime = NULL, cpuset_cpus = NULL, cpuset_mems = NULL, devices = NULL, device_cgroup_rules = NULL, disk_quota = NULL, kernel_memory = NULL, memory_reservation = NULL, memory_swap = NULL, memory_swappiness = NULL, nano_cpus = NULL, oom_kill_disable = NULL, pids_limit = NULL, ulimits = NULL, cpu_count = NULL, cpu_percent = NULL, io_maximum_iops = NULL, io_maximum_bandwidth = NULL, restart_policy = NULL)Arguments:
cpu_shares: An integer value representing this container's relative CPU weight versus other containers.memory: Memory limit in bytes.cgroup_parent: Path tocgroupsunder which the container'scgroupis created. If the path is not absolute, the path is considered to be relative to thecgroupspath of the init process. Cgroups are created if they do not already exist.blkio_weight: Block IO weight (relative weight).blkio_weight_device: Block IO weight (relative device weight) in the form[{"Path": "device_path", "Weight": weight}].blkio_device_read_bps: Limit read rate (bytes per second) from a device, in the form[{"Path": "device_path", "Rate": rate}].blkio_device_write_bps: Limit write rate (bytes per second) to a device, in the form[{"Path": "device_path", "Rate": rate}].blkio_device_read_iops: Limit read rate (IO per second) from a device, in the form[{"Path": "device_path", "Rate": rate}].blkio_device_write_iops: Limit write rate (IO per second) to a device, in the form[{"Path": "device_path", "Rate": rate}].cpu_period: The length of a CPU period in microseconds.cpu_quota: Microseconds of CPU time that the container can get in a CPU period.cpu_realtime_period: The length of a CPU real-time period in microseconds. Set to 0 to allocate no time allocated to real-time tasks.cpu_realtime_runtime: The length of a CPU real-time runtime in microseconds. Set to 0 to allocate no time allocated to real-time tasks.cpuset_cpus: CPUs in which to allow execution (e.g.,0-3,0,1)cpuset_mems: Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.devices: A list of devices to add to the container.device_cgroup_rules: a list of cgroup rules to apply to the containerdisk_quota: Disk limit (in bytes).kernel_memory: Kernel memory limit in bytes.memory_reservation: Memory soft limit in bytes.memory_swap: Total memory limit (memory + swap). Set as-1to enable unlimited swap.memory_swappiness: Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100.nano_cpus: CPU quota in units of 10<sup>-9</sup> CPUs.oom_kill_disable: Disable OOM Killer for the container.pids_limit: Tune a container's pids limit. Set -1 for unlimited.ulimits: A list of resource limits to set in the container. For example:{"Name": "nofile", "Soft": 1024, "Hard": 2048}"cpu_count: The number of usable CPUs (Windows only).On Windows Server containers, the processor resource controls are mutually exclusive. The order of precedence is
CPUCountfirst, thenCPUShares, andCPUPercentlast.cpu_percent: The usable percentage of the available CPUs (Windows only).On Windows Server containers, the processor resource controls are mutually exclusive. The order of precedence is
CPUCountfirst, thenCPUShares, andCPUPercentlast.io_maximum_iops: Maximum IOps for the container system drive (Windows only)io_maximum_bandwidth: Maximum IO in bytes per second for the container system drive (Windows only)restart_policy: The behavior to apply when the container exits. The default is not to restart.An ever increasing delay (double the previous delay, starting at 100ms) is added before each restart to prevent flooding the server.
container_waitWait for a container. Block until a container stops, then returns the exit code. Similar to the cli command
docker waitordocker container wait.Usage:
container_wait()
See Also
docker_container_collection for other
container management methods.