Introduction

The goal of dockerAPI is to provide an R client for the docker Remote API. Docker is an open platform for developing, shipping, and running applications. Docker is designed to deliver your applications faster. With Docker you can separate your applications from your infrastructure AND treat your infrastructure like a managed application.

Docker does this by combining a lightweight container virtualization platform with workflows and tooling that help you manage and deploy your applications. We will mainly be looking at three components of docker namely registries, images and containers. Registries contain images, images contain containers and containers encompass everything needed for an applications that docker runs.

The docker Remote API allows us to interact with registries, images and containers both locally and remotely by way of a mostly RESTFUL API. For more details on docker read Understanding Docker.

Installation

To install dockerAPI from CRAN use

install.packages("dockerAPI")

To get the latest development version of dockerAPI use

devtools::install_github("johndharrison/dockerAPI")

Installing docker

Docker is available for a wide range of platforms. dockerAPI has been tested on Windows, Linux and Mac OS X. Windows and Mac OS X currently both require a helper application boot2docker to run docker. dockerAPI has been mostly tested on Ubuntu Linux. For detailed instructions on installing docker for your platform please see the installation guides. docker version 1.4, docker Remote API version 1.16 or greater is assumed.

Docker basics

Connecting to the docker daemon

On Linux the daemon listens on unix:///var/run/docker.sock but you can Bind Docker to another host/port or a Unix socket. On boot2docker (Windows and Mac OS X) the daemon listens on tcp with TLS enabled. Running

$ boot2docker shellinit
Writing c:\Users\john\.docker\boot2docker-vm\ca.pem:
Writing c:\Users\john\.docker\boot2docker-vm\cert.pem:
Writing c:\Users\john\.docker\boot2docker-vm\key.pem:
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=c:\Users\john\.docker\boot2docker-vm

gives information on the location of the certs and the relevant docker ip. It is straightforward to change these defaults. For example to secure the Linux docker Remote API see here. For most of this guide we will assume we are connecting to a windows boot2docker variant over TLS. This is usually the most problematic platform and it will require us to authenticate which is useful for illustration. Windows, Mac OS X, Linux is how I would perceive the order of the OS's in terms of problems running docker. If you have authentication turned off you can remove the config = myConfig references you will see that follows from the relevant methods.

The docker class

The dockerAPI package contains a number of reference classes that will enable us to interact with the docker Remote API. The first such class we encounter is the docker class. The docker class is initialised by passing it a string of the docker host url or a httr object of class url. Class url is a named list giving information on the url (scheme, hostname, path etc.). For our windows based boot2docker example we would initialise our docker class as

dckr <- docker("https://192.168.59.103:2376)
myConfig <- httr::config(sslcert = "../../certs/cert.pem"
                         , sslkey = "../../certs/key.pem"
                         , sslversion=1L, ssl.verifypeer = FALSE)

The additional setup in myConfig is typically what we would need for SSL/TLS authentication. sslcert and sslkey point to the location of the cert and key. In this case sslversion=1L states that we are using TLS and ssl.verifypeer = FALSE means our cert is signed and for libcurl to ignore this fact. The path to my certs dont match the output from boot2docker shellinit as I am actually accessing the windows machine running docker from another virtual machine and have just copied the cert and key across.

Interacting with the daemon.

The docker class has a number of informative methods that we will look at. Firstly lets check that we can connect to the docker server. There is a ping method:

> dckr$ping(config = myConfig)
[1] "OK"

which helpfully indicates everything is as expected. We can get system-wide information using the info method:

> dckr$info(config = myConfig)[c("Name", "OperatingSystem")]
$Name
[1] "boot2docker"

$OperatingSystem
[1] "Boot2Docker 1.4.0 (TCL 5.4); master : 69cf398 - Fri Dec 12 01:15:02 UTC 2014"

which returns a wide range of information two components of which we highlight here. So we see that the docker machine we are connecting to herre is running boot2docker and the docker version is 1.4.0. Finally we can call the version method for more detail on the setup:

> dckr$version(config = myConfig)
$ApiVersion
[1] "1.16"

$Arch
[1] "amd64"

$GitCommit
[1] "4595d4f"

$GoVersion
[1] "go1.3.3"

$KernelVersion
[1] "3.16.7-tinycore64"

$Os
[1] "linux"

$Version
[1] "1.4.0"


johndharrison/dockerAPI documentation built on May 19, 2019, 5:13 p.m.