A simple reproducible analysis with Docker and git
04 Oct 2017Initialise the repository and connect it to remote:
$ git init
$ git remote add origin git@gitlab.ethz.ch:mrawlik/1st-order-SFC-design.git
Create a README.md
file.
$ git add README.md
$ git commit -m "Initial commit."
$ git push -u origin master
Write a program. It will accept a single argument: the path where to write its output.
OUTPATH = ARGS[1]
println("hello world")
write(joinpath(OUTPATH, "output.txt"), "hello world")
Add it to git:
$ git add hello.jl
$ git commit -m "Add a hello program."
You can test it locally:
$ mkdir output
$ julia hello.jl output
hello world
$ cat output/output.txt
hello world
Now pack the program in a Docker container. Create a Dockerfile
:
# specify the version
FROM julia:0.6
# add the contents of the current directory to docker, in particular the hello
# program
ADD . /
# prepare an output directory
# we could also have an input one
# VOLUME /input
VOLUME /output
# what to run
CMD julia hello.jl /output
Build the docker image with a friendly name. The first time it may take some
time, as docker needs to fetch the base julia:0.6
image.
$ docker build -t hello .
Run the analysis inside docker. The first argument to --volume
needs to be an
absolute path. In fish
do:
$ docker run --volume (pwd)/output:/output hello
In bash:
$ docker run --volume `pwd`/output:/output hello