The goal of dockermachine is to provide a convenient interface to
docker-machine from the R command line. This will allow R users to easily create, control, and destroy cloud instances across a wide variety of providers.
You can install dockermachine from github with:
# install.packages("devtools") devtools::install_github("cboettig/dockermachine")
Once you have installed the R package, use the helper function
install_machine() to install the latest version of
docker-machine on your platform, if you have not already installed it some other way:
library("dockermachine") install_machine() It seems docker-machine has been installed. Use force = TRUE to reinstall or upgrade.
The sister function
update_machine() can be used to get a more recent version of
To experiment with
docker-machine, locally, we recommend installing VirtualBox for your platform and testing out the commands using the
machine_create("virtualbox")  "Running pre-create checks..."  "Creating machine..."  "(machine) Copying /Users/cboettig/.docker/machine/cache/boot2docker.iso to /Users/cboettig/.docker/machine/machines/machine/boot2docker.iso..."  "(machine) Creating VirtualBox VM..."  "(machine) Creating SSH key..."  "(machine) Starting the VM..."  "(machine) Check network to re-create if needed..."  "(machine) Waiting for an IP..."  "Waiting for machine to be running, this may take a few minutes..."  "Detecting operating system of created instance..."  "Waiting for SSH to be available..."  "Detecting the provisioner..."  "Provisioning with boot2docker..."  "Copying certs to the local machine directory..."  "Copying certs to the remote machine..."  "Setting Docker configuration on the remote daemon..."  "Checking connection to Docker..."  "Docker is up and running!"  "To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: /Users/cboettig/Library/Application Support/docker-machine/docker-machine env machine"
This may take up to a few minutes to get your first machine created. By default, this creates a machine named
machine. You can change this name (e.g. when working with many remote machines through the same client) by passing a different name to the
name string of most any
Once our machine is up and running, we can list all machines:
machine_ls()  "NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS"  "machine - virtualbox Running tcp://192.168.99.100:2376 v17.07.0-ce "
We are also ready now to use the
harbor R package (or any system commands to the
docker engine) to deploy custom R images and run R commands on the remote machines.
Use the command
machine_scp to copy data to your local computer before destroying the remote machine, or push your results to the cloud using your preferred platform such as GitHub, Amazon S3, Google Cloud Storage, or DropBox (all accessible through the R command line with the appropriate additional packages.)
file.create("file.txt") machine_scp("file.txt", "machine:~/filecopy.txt") machine_scp("machine:~/filecopy.txt", ".")
When we're all done, we can stop and remove the machine.
machine_stop()  "Stopping \"machine\"..." "Machine \"machine\" was stopped." machine_rm()  "About to remove machine"  "WARNING: This action will delete both local reference and remote instance."  "Successfully removed machine"
This step is crucial to avoid continuing to accumulate charges from a cloud provider. By combining these commands with commands to
harbor to run code on a remote machine, this allows a user to create R scripts which can deploy long-running instances remotely and shut them down when they are finished.
Once you comfortable creating machines, controlling those machines with docker (see the
harbor package by Winston Chang), and terminating those machines, then consider trying out one of the remote providers using your Amazon EC2, Google Cloud, Digital Ocean, Azure, openstack, or other credentials.