- Data Science and Software Engineering at Seelio
- Have worked with R for nearly a decade
- Use Docker extensively at Seelio
March 10, 2016
docker-compose
1.6.0 to support the version 2 format of docker-compose.yml
)From https://www.docker.com/what-docker:
Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.
docker-machine
): used on Windows and Mac OS X to manage the Linux VM on which the Docker daemon runs, or to create a Docker swarmdocker
): the combination of the client with which you communicate with other parts of the Docker architecture as well as the daemon that receives commands from the client and manages containersdocker-compose
): tool for defining and running multi-container Docker applications (Compose not yet supported on Windows)In a development environment, the docker client and docker daemon will usually run on the same physical system. However, this need not be true.
docker-compose.yml
file or via the docker network create
commanddocker-compose.yml
file or via the docker volume create
commandAssumes Docker Engine and Docker Machine have already been installed
docker-machine create --driver virtualbox default
--engine-storage-driver overlay
to the above docker-machine create
command worked bettereval $(docker-machine env)
docker run hello-world
Steps that I carried out in advance (for the sake of time):
docker pull debian
docker pull postgres
docker pull r-base
docker pull rocker/hadleyverse
Images pulled the morning of March 10, 2016
docker run -it --rm debian bash
bash
)docker run -it --rm r-base
Details about r-base
package can be found on Docker Hub
docker run -it --rm -v "$(pwd)":/home/docker -w /home/docker -u docker r-base bash
R
from the command line (use R interactively or batch)bash
as the command to docker run
, you could run R directly: R CMD ...
Other R images available:
Links to the rocker Github and Docker Hub accounts can be found in the Resources section at the end of the presentation
# Builds image upon the existing rocker/hadleyverse image FROM rocker/hadleyverse # Example of installing a library RUN apt-get update \ && apt-get install -y --no-install-recommends \ libpqxx-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/ \ && rm -rf /tmp/downloaded_packages/ /tmp/*.rds # Example of installing additional R packages RUN install2.r --error \ -r "https://cran.rstudio.com" \ RCurl
Building your image: docker build -t <name>:<tag> .
Assumes Dockerfile
resides in the current directory
Push image to Docker Hub via docker push
(beyond the scope of this talk, see docker push --help
for more info)
Example docker-compose.yml available on Github
docker-compose up -d
from the diretory in which docker-compose.yml
residespopulate_postgres.sh
script uploaded to Github as part of this presentationdocker-machine ip
to find out the IP address of your Docker host (only needed on Mac and Windows, can just use localhost on Linux)To shut down services, execute docker-compose down