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_commit
Create a new image from a container. Similar to the cli command
docker commit
ordocker 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
:Dockerfile
instructions 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: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.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: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.
cp_in
Copy files or directory into the container. This function tries to follow the same semantics as the command line
docker cp
command.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_out
Copy files or directories from the container. This function tries to follow the same semantics as the command line
docker cp
command.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_changes
Get changes on a container's filesystem. Returns which files in a container's filesystem have been added, deleted, or modified. The
Kind
of modification can be one of:0
: Modified1
: Added2
: Deleted. Similar to the cli commanddocker diff
ordocker container diff
.
Usage:
container_changes()
exec
Create 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 tostdin
of the exec command.stdout
: Attach tostdout
of the exec command.stderr
: Attach tostderr
of 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)FALSE
orNULL
to disable any output.
exec_create
Create 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 tostdin
of the exec command.stdout
: Attach tostdout
of the exec command.stderr
: Attach tostderr
of 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_export
Export a container. Export the contents of a container as a tarball. Similar to the cli command
docker export
ordocker container export
.Usage:
container_export()
container_archive
Get 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.
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 "?")
id
Return the container's id
Usage:
id()
image
Return the image for this container, as a
docker_image
object.Usage:
image()
inspect
Return 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 toFALSE
after a container has been removed.
container_kill
Kill a container. Send a POSIX signal to a container, defaulting to killing to the container. Similar to the cli command
docker kill
ordocker container kill
.Usage:
container_kill(signal = NULL)
Arguments:
signal
: Signal to send to the container as an integer or string (e.g.SIGINT
)
labels
Return 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 toFALSE
after a container has been removed.
container_logs
Get container logs. Get
stdout
andstderr
logs from a container.Note: This endpoint works only for containers with the
json-file
orjournald
logging driver. Similar to the cli commanddocker logs
ordocker 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
101
HTTP response with aConnection: upgrade
header, 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 fromstdout
stderr
: Return logs fromstderr
since
: 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 orall
to 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)FALSE
orNULL
to disable any output.
name
Return name for this container
Usage:
name()
container_path_stat
Get information about files in a container. A response header
X-Docker-Container-Path-Stat
is 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_pause
Pause a container. Use the cgroups freezer to suspend all processes in a container.
Traditionally, when suspending a process the
SIGSTOP
signal 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 pause
ordocker container pause
.Usage:
container_pause()
ports
Return a
data.frame
of 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 toFALSE
after a container has been removed.
container_import
Extract 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.
reload
Refresh infomation on the container from the server, returning
$inspect()
invisibly.Usage:
reload()
container_delete
Remove a container. Similar to the cli command
docker rm
ordocker 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_rename
Rename a container. Similar to the cli command
docker rename
ordocker container rename
.Usage:
container_rename(name)
Arguments:
name
: New name for the container
container_resize
Resize 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_restart
Restart a container. Similar to the cli command
docker restart
ordocker container restart
.Usage:
container_restart(t = NULL)
Arguments:
t
: Number of seconds to wait before killing the container
container_start
Start a container. Similar to the cli command
docker start
ordocker 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_stats
Get container stats based on resource usage. This endpoint returns a live stream of a container's resource usage statistics.
The
precpu_stats
is the CPU statistic of last read, which is used for calculating the CPU usage percentage. It is not the same as thecpu_stats
field.If either
precpu_stats.online_cpus
orcpu_stats.online_cpus
is nil then for compatibility with older daemons the length of the correspondingcpu_usage.percpu_usage
array should be used. Similar to the cli commanddocker stats
ordocker container stats
.Usage:
container_stats()
status
Short status of the container ("running", "exited", etc).
Usage:
status(reload = TRUE)
Arguments:
reload
: Refresh container data?
container_stop
Stop a container. Similar to the cli command
docker stop
ordocker container stop
.Usage:
container_stop(t = NULL)
Arguments:
t
: Number of seconds to wait before killing the container
container_top
List processes running inside a container. On Unix systems, this is done by running the
ps
command. This endpoint is not supported on Windows. Similar to the cli commanddocker top
ordocker container top
.Usage:
container_top(ps_args = NULL)
Arguments:
ps_args
: The arguments to pass tops
. For example,aux
container_unpause
Unpause a container. Resume a container which has been paused. Similar to the cli command
docker unpause
ordocker container unpause
.Usage:
container_unpause()
container_update
Update a container. Change various configuration options of a container without having to recreate it. Similar to the cli command
docker update
ordocker 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 tocgroups
under which the container'scgroup
is created. If the path is not absolute, the path is considered to be relative to thecgroups
path 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-1
to 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
CPUCount
first, thenCPUShares
, andCPUPercent
last.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
CPUCount
first, thenCPUShares
, andCPUPercent
last.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_wait
Wait for a container. Block until a container stops, then returns the exit code. Similar to the cli command
docker wait
ordocker container wait
.Usage:
container_wait()
See Also
docker_container_collection
for other
container management methods.