docklet_create {analogsea} | R Documentation |
Docklets: docker on droplets.
Description
Docklets: docker on droplets.
Usage
docklet_create(
name = random_name(),
size = getOption("do_size", "s-1vcpu-2gb"),
region = getOption("do_region", "sfo3"),
ssh_keys = getOption("do_ssh_keys", NULL),
backups = getOption("do_backups", NULL),
ipv6 = getOption("do_ipv6", NULL),
private_networking = getOption("do_private_networking", NULL),
tags = list(),
wait = TRUE,
image = "docker-20-04",
keyfile = NULL,
...
)
docklet_ps(droplet, all = TRUE, ssh_user = "root")
docklet_images(droplet, all = TRUE, ssh_user = "root")
docklet_pull(
droplet,
repo,
ssh_user = "root",
keyfile = NULL,
ssh_passwd = NULL,
verbose = FALSE
)
docklet_run(
droplet,
...,
rm = FALSE,
name = NULL,
ssh_user = "root",
keyfile = NULL,
ssh_passwd = NULL,
verbose = FALSE
)
docklet_stop(droplet, container, ssh_user = "root")
docklet_rm(droplet, container, ssh_user = "root")
docklet_docker(
droplet,
cmd,
args = NULL,
docker_args = NULL,
ssh_user = "root",
keyfile = NULL,
ssh_passwd = NULL,
verbose = FALSE
)
docklet_rstudio(
droplet,
user,
password,
email = "rstudio@example.com",
img = "rocker/rstudio",
port = "8787",
volume = "",
dir = "",
browse = TRUE,
add_users = FALSE,
ssh_user = "root",
keyfile = NULL,
ssh_passwd = NULL,
verbose = FALSE
)
docklet_rstudio_addusers(
droplet,
user,
password,
img = "rocker/rstudio",
port = "8787",
ssh_user = "root",
keyfile = NULL,
ssh_passwd = NULL,
verbose = FALSE
)
docklet_shinyserver(
droplet,
img = "rocker/shiny",
port = "3838",
volume = "",
dir = "",
browse = TRUE,
ssh_user = "root",
keyfile = NULL
)
docklet_shinyapp(
droplet,
path,
img = "rocker/shiny",
port = "80",
dir = "",
browse = TRUE,
ssh_user = "root",
keyfile = NULL
)
Arguments
name |
(character) Name of the droplet. The human-readable string you
wish to use when displaying the Droplet name. The name, if set to a domain
name managed in the DigitalOcean DNS management system, will configure a
PTR record for the Droplet. The name set during creation will also
determine the hostname for the Droplet in its internal configuration.
Default: picks a random name from |
size |
(character) Size slug identifier. See |
region |
(character) The unique slug identifier for the region that you
wish to deploy in. See |
ssh_keys |
(character) A character vector of key names, an integer
vector of key ids, or NULL, to use all keys in your account. Accounts
with the corresponding private key will be able to log in to the droplet.
See |
backups |
(logical) Enable backups. A boolean indicating whether automated backups should be enabled for the droplet. Automated backups can only be enabled when the droplet is created, and cost extra. Default: FALSE |
ipv6 |
(logical) A boolean indicating whether IPv6 is enabled on the droplet. |
private_networking |
(logical) Use private networking. Private
networking is currently only available in certain regions.
Default: |
tags |
(character) A vector of tag names to apply to the Droplet after it is created. Tag names can either be existing or new tags. Default: list() |
wait |
If |
image |
(character/numeric) The image ID of a public or private image,
or the unique slug identifier for a public image. This image will be the
base image for your droplet. See |
keyfile |
Optional private key file. |
... |
For |
droplet |
A droplet, or something that can be coerced to a droplet by
|
all |
(logical) List all containers or images. Default: |
ssh_user |
(character) User account for ssh commands against droplet. Default: root |
repo |
(character) Docker name, can be local to the Droplet or remote,
e.g., |
ssh_passwd |
Optional passphrase or callback function for authentication.
Refer to the |
verbose |
If TRUE, will print command before executing it. |
rm |
(logical) Automatically remove the container when it exits.
Default: |
container |
(character) Container name, can be partial (though has to be unique) |
cmd |
(character) A docker command (e.g., |
args |
(character) Docker args |
docker_args |
(character) Docker args |
user |
(character) User name. required. |
password |
(character) Password. required. can not be 'rstudio' |
email |
(character) E-mail address. Default: |
img |
(character) Docker image (not a DigitalOcean image). Default:
|
port |
(character) Port. Default: |
volume |
(character) Volume. Can use to bind a volume. |
dir |
(character) Working directory inside the container. |
browse |
(logical) If |
add_users |
(logical) Add users or not when installing RStudio server. Default: FALSE |
path |
(character) Path to a directory with Shiny app files |
Value
all functions return a droplet
URLs
If you need to figure out the URL for your RStudio or Shiny server
instance, you can construct like http://<ip address>:<port>
where
IP address can most likely be found like d$networks$v4[[1]]$ip_address
and the port is the port you set in the function call.
Managing Docker containers from R
There's a few things to be note about managing Docker containers from analogsea:
To see running containers run
docklet_ps(d)
To get get logs run
droplet_ssh(d, "docker logs <container ID>")
To get a continuous feed of the logs run
droplet_ssh(d, "docker logs -f <container ID>")
Do not use
docker exec -ti
as you do not want an interactive session - it will not work from within R. If you log into your DigitalOcean droplet you can dodocker exec -ti
To install R package dependencies for a Shiny app, or similar, run
droplet_ssh(d, "docker exec <ID> R -e 'install.packages(\"pkg-name\")'")
whered
is your droplet object and<ID>
is the docker container ID
Missing droplet ID
If you get a droplet object back without an IP address, the IP
address was not assigned when the payload was returned by DigitalOcean.
Simply run d <- droplet(d$id)
to update your droplet object and the IP
address will populate.
See Also
Examples
## Not run:
d <- docklet_create()
d <- droplet(d$id)
d %>% docklet_pull("dockerpinata/sqlite")
d %>% docklet_images()
# sqlite
d %>% docklet_run("dockerpinata/sqlite", "sqlite3 --version", rm = TRUE)
d %>% docklet_ps()
# cowsay
d %>% docklet_pull("chuanwen/cowsay")
d %>% docklet_run("chuanwen/cowsay", rm = TRUE)
# docker images
d %>% docklet_images()
# install various R versions via Rocker
d %>% docklet_pull("rocker/r-base")
d %>% docklet_pull("rocker/r-devel")
d %>% docklet_pull("rocker/r-ver:3.2")
d %>% docklet_run("rocker/r-ver:3.2", "R --version", rm = TRUE)
d %>% docklet_run("rocker/r-ver:3.2", "Rscript -e '2 + 3'", rm = TRUE)
# Run a docklet containing rstudio
d %>% docklet_rstudio(user = "foo", password = "bar")
# Delete a droplet
d %>% droplet_delete()
# Add users to an Rstudio instance
## This adds 100 users to the instance, with username/passwords
## following pattern user1/user1 ... through 100
d <- docklet_create()
d <- droplet(d$id)
d %>% docklet_rstudio(user = "foo", password = "bar") %>%
docklet_rstudio_addusers(user = "foo", password = "bar")
# Spin up a Shiny server (opens in default browser)
(d <- docklet_create())
d %>% docklet_shinyserver()
docklet_create() %>% docklet_shinyserver()
# Spin up a Shiny server with an app (opens in default browser)
d <- docklet_create(); d <- droplet(d$id)
path <- system.file("examples", "widgets", package = "analogsea")
d %>% docklet_shinyapp(path)
## uploading more apps - use droplet_upload, then navigate in browser
### if you try to use docklet_shinyapp again on the same droplet, it will error
path2 <- system.file("examples", "mpg", package = "analogsea")
d %>% droplet_upload(path2, "/srv/shinyapps") # then go to browser
## End(Not run)