Skip to content

Instantly share code, notes, and snippets.

@strboul
Last active August 27, 2018 09:46
Show Gist options
  • Save strboul/b889f71572beb14a5f06bfd4290fdfe3 to your computer and use it in GitHub Desktop.
Save strboul/b889f71572beb14a5f06bfd4290fdfe3 to your computer and use it in GitHub Desktop.
How to use Docker volumes with an R example
#!/bin/bash
# M Y 2018-08-21. An example script on Docker volumes showing
# how to run a sandboxed 'R' code inside the container.
# Tip: Using `ls` (or else) with the volumes is helpful especially
# when need to understand why some particular files cannot be found.
set -x
V="rvol"
mkdir $V
printf "2 * 4 \n\ncat('success!!') \n\n " > $V/calc.R
## With VOL layer in the Dockerfile:
printf "FROM r-base:latest \n\nVOLUME /%s\n " "$V)" > Dockerfile
docker build -t test-docker-vol .
docker run --rm \
-v $PWD/$V:/$V \
test-docker-vol \
Rscript $V/calc.R
## With binding volume arg command:
docker run --rm \
-v $PWD/$V:/$V r-base:latest \
Rscript rvol/calc.R
## Clean up:
rm Dockerfile
rm -r $V/*
rmdir $V
docker rmi test-docker-vol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment