1 | ## Using Dockter
|
2 |
|
3 | This document will take you through using Dockter to make your work reproducible and easy to reuse.
|
4 |
|
5 | #### Prerequisites
|
6 |
|
7 | You should have some basic working knowledge of Docker. [This hands-on tutorial](https://ome.github.io/training-docker/) is a good way to start. You can also
|
8 | check out the [Katakoda set of Docker courses](https://www.katacoda.com/courses/docker).
|
9 |
|
10 | #### Motivation
|
11 |
|
12 | We encourage you to have a look at the above courses but the idea behind Dockter is that you don't need to master Docker. Dockter does most of the things for you
|
13 | in order to set up a reproducible research environment.
|
14 |
|
15 | Dockter is a tool to make it easier for researchers to create reproducible research environments. It generates a Docker image for a research project based on the source code in it. That means that you don’t need to learn a new file format (`Dockerfiles`) to create Docker images. Dockter makes it also easy to track dependencies and update the image when they change.
|
16 |
|
17 | In addition, Dockter manages the image building process to better fit your everyday workflow (determines package system dependencies, manages builds) and generates JSON-LD meta-data describing the image (from which citations etc can be generated).
|
18 |
|
19 | You can manually edit the files which Dockter generates so that the containers build of it exactly suit your project.
|
20 |
|
21 | #### 1. Install
|
22 |
|
23 | a) Download the latest stable binary package (ready to run) [for your operating system](https://github.com/stencila/dockter/releases):
|
24 |
|
25 | b) Copy the binary file into the folder where you would like Dockter to be (eg. `Applications` on your Mac OS, or `Program Files` on Windows).
|
26 |
|
27 | c) Once the file is downloaded, rename it to `dockter` Dockter is a command line tool (at least for now) so you need to interact with it through the terminal (on Windows it will be Power Shell).
|
28 |
|
29 | **Basic use**
|
30 |
|
31 | ```
|
32 | dockter compile [folder] [format] Compile a project to a software environment
|
33 | dockter build [folder] Build a Docker image for project
|
34 | dockter execute [folder] [format] Execute a project
|
35 | ```
|
36 |
|
37 |
|
38 | #### 2. Dockter for R
|
39 |
|
40 | Dockter can create a software environment file which reflects the requirements to run the project written in R.
|
41 | The software environment file is a file in `JSON` or `yaml` format with comprehensive meta data about the project.
|
42 | Dockter parses the folder with the R project for `R` and `Rmd` files and extracts the relevant information.
|
43 |
|
44 | * For each R package installed or loaded, the meta data is retrieved from [CRAN](http://crandb.r-pkg.org).
|
45 | * System dependencies for each package are obtained from [R-Hub](https://sysreqs.r-hub.io/pkg/xml2).
|
46 | * Meta data about the authors, title, abstract and so on.
|
47 |
|
48 | Try out Dockter on the `example.R` file included in this folder.
|
49 |
|
50 | ```
|
51 | dockter compile dockter/doc
|
52 | ```
|
53 |
|
54 | You will see the output on your screen in `JSON` and two files: `.Dockerfile` and `.DESCRIPTION` generated in the project folder:
|
55 |
|
56 | `.Dockerfile` will look more or less like the one below:
|
57 |
|
58 | ```
|
59 | # Generated by Dockter 2018-10-23T09:17:23.748Z
|
60 | # To stop Dockter generating this file and start editing it yourself, rename it to "Dockerfile".
|
61 |
|
62 | FROM ubuntu:16.04
|
63 |
|
64 | ENV TZ="Etc/UTC"
|
65 |
|
66 | RUN apt-get update \
|
67 | && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
68 | apt-transport-https \
|
69 | ca-certificates \
|
70 | software-properties-common
|
71 |
|
72 | RUN apt-add-repository "deb https://mran.microsoft.com/snapshot/2018-10-22/bin/linux/ubuntu xenial/" \
|
73 | && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 51716619E084DAB9
|
74 |
|
75 | RUN apt-get update \
|
76 | && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
77 | r-base \
|
78 | && apt-get autoremove -y \
|
79 | && apt-get clean \
|
80 | && rm -rf /var/lib/apt/lists/*
|
81 |
|
82 | # dockter
|
83 |
|
84 | COPY .DESCRIPTION DESCRIPTION
|
85 | RUN bash -c "Rscript <(curl -sL https://unpkg.com/@stencila/dockter/src/install.R)"
|
86 |
|
87 | COPY environment-example.R environment-example.R
|
88 | COPY example.R example.R
|
89 |
|
90 | CMD Rscript environment-example.R
|
91 | ```
|
92 | #### 3. Dockter for Python
|
93 |
|
94 | Dockter can create a software environment file which reflects the requirements to run the project written in Python.
|
95 | The software environment file is a file in `JSON` or `yaml` format with comprehensive meta data about the project.
|
96 | Dockter parses the folder with the Python project for `py` files and extracts the relevant information.
|
97 |
|
98 | #### 4. Real-life example
|
99 |
|
100 | To demonstrate convenience of using Dockter, try running it for one of the [Software Carpentry modules](https://github.com/swcarpentry/r-novice-inflammation)
|
101 | for learning R. The repository with the module contains a range of source code files, including 'python`, `JS`, `Rmd` and `R`.
|
102 | First, clone the repository on your machine:
|
103 |
|
104 | ```
|
105 | git clone https://github.com/swcarpentry/r-novice-inflammation.git
|
106 | ```
|
107 |
|
108 | Run `dockter compile` on the whole directory:
|
109 |
|
110 | ```
|
111 | dockter compile r-novice-inflammation
|
112 | ```
|
113 |
|
114 | Then, `dockter build` to create a `Docker` image so that the module can be run (note, `dockter` will likely have to download and install a number
|
115 | of packages, this may take a while):
|
116 |
|
117 | ```
|
118 | dockter build r-novice-inflammation
|
119 | ```
|
120 |
|
121 | Check if the image is there:
|
122 |
|
123 | ```
|
124 | docker images
|
125 | ```
|
126 |
|
127 | And you should see the image on the list:
|
128 |
|
129 | ``` TAG IMAGE ID CREATED SIZE
|
130 | rnoviceinflammation latest 149d3dc3fc73 20 minutes ago 1.12GB
|
131 | ```
|
132 |
|
133 | ### Resources
|
134 |
|
135 | [A beginner's guide to containters](https://medium.freecodecamp.org/a-beginner-friendly-introduction-to-containers-vms-and-docker-79a9e3e119b)
|
136 |
|
137 |
|