diff --git a/dockerPython/Dockerfile b/children-society/python3-notebook/Dockerfile similarity index 68% rename from dockerPython/Dockerfile rename to children-society/python3-notebook/Dockerfile index b1524ca..a578395 100644 --- a/dockerPython/Dockerfile +++ b/children-society/python3-notebook/Dockerfile @@ -1,4 +1,4 @@ -FROM jupyter/minimal-notebook +FROM jupyter/minimal-notebook:9e056d61b7a5 COPY requirements.txt /tmp/ RUN pip install --requirement /tmp/requirements.txt diff --git a/children-society/python3-notebook/readme.md b/children-society/python3-notebook/readme.md new file mode 100644 index 0000000..952991e --- /dev/null +++ b/children-society/python3-notebook/readme.md @@ -0,0 +1,5 @@ +This folder has the Python notebook docker files for DKSG's work with the Singapore Children's Society. + +Events: + +* April 2017, DataDive diff --git a/children-society/python3-notebook/requirements.txt b/children-society/python3-notebook/requirements.txt new file mode 100644 index 0000000..d7a0eee --- /dev/null +++ b/children-society/python3-notebook/requirements.txt @@ -0,0 +1,7 @@ +matplotlib==2.0.0 +numpy==1.12.0 +pandas==0.19.2 +plotly==2.0.5 +scikit-learn==0.18.1 +scipy==0.19.0 +spacy==1.7.2 diff --git a/children-society/r-notebook/.dockerignore b/children-society/r-notebook/.dockerignore new file mode 100644 index 0000000..9dea340 --- /dev/null +++ b/children-society/r-notebook/.dockerignore @@ -0,0 +1,2 @@ +# Documentation +README.md diff --git a/children-society/r-notebook/Dockerfile b/children-society/r-notebook/Dockerfile new file mode 100644 index 0000000..aeaa04f --- /dev/null +++ b/children-society/r-notebook/Dockerfile @@ -0,0 +1,40 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +FROM jupyter/minimal-notebook:9e056d61b7a5 + +MAINTAINER Jupyter Project + +USER root + +# R pre-requisites +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + fonts-dejavu \ + gfortran \ + gcc && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +USER $NB_USER + +# R packages +RUN conda config --add channels r && \ + conda install --quiet --yes \ + 'r-base=3.3.2' \ + 'r-irkernel=0.7*' \ + 'r-plyr=1.8*' \ + 'r-devtools=1.12*' \ + 'r-tidyverse=1.0*' \ + 'r-shiny=0.14*' \ + 'r-rmarkdown=1.2*' \ + 'r-forecast=7.3*' \ + 'r-rsqlite=1.1*' \ + 'r-reshape2=1.4*' \ + 'r-nycflights13=0.2*' \ + 'r-caret=6.0*' \ + 'r-rcurl=1.95*' \ + 'r-crayon=1.3*' \ + 'r-randomforest=4.6*' && conda clean -tipsy + +RUN conda config --add channels BIMSBbioinfo && \ + conda install --quiet --yes \ + 'r-plotly=4.5.2' && conda clean -tipsy diff --git a/children-society/r-notebook/README.md b/children-society/r-notebook/README.md new file mode 100644 index 0000000..b167f7b --- /dev/null +++ b/children-society/r-notebook/README.md @@ -0,0 +1,5 @@ +This folder has the R notebook docker files for DKSG's work with the Singapore Children's Society. + +Events: + +* April 2017, DataDive diff --git a/dockerPython/requirements.txt b/dockerPython/requirements.txt deleted file mode 100644 index 4452444..0000000 --- a/dockerPython/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy -pandas -matplotlib -scipy -scikit-learn diff --git a/ojoy/r-notebook/Dockerfile b/ojoy/r-notebook/Dockerfile new file mode 100644 index 0000000..aeaa04f --- /dev/null +++ b/ojoy/r-notebook/Dockerfile @@ -0,0 +1,40 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +FROM jupyter/minimal-notebook:9e056d61b7a5 + +MAINTAINER Jupyter Project + +USER root + +# R pre-requisites +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + fonts-dejavu \ + gfortran \ + gcc && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +USER $NB_USER + +# R packages +RUN conda config --add channels r && \ + conda install --quiet --yes \ + 'r-base=3.3.2' \ + 'r-irkernel=0.7*' \ + 'r-plyr=1.8*' \ + 'r-devtools=1.12*' \ + 'r-tidyverse=1.0*' \ + 'r-shiny=0.14*' \ + 'r-rmarkdown=1.2*' \ + 'r-forecast=7.3*' \ + 'r-rsqlite=1.1*' \ + 'r-reshape2=1.4*' \ + 'r-nycflights13=0.2*' \ + 'r-caret=6.0*' \ + 'r-rcurl=1.95*' \ + 'r-crayon=1.3*' \ + 'r-randomforest=4.6*' && conda clean -tipsy + +RUN conda config --add channels BIMSBbioinfo && \ + conda install --quiet --yes \ + 'r-plotly=4.5.2' && conda clean -tipsy diff --git a/ojoy/r-notebook/README.md b/ojoy/r-notebook/README.md new file mode 100644 index 0000000..5e5e2f9 --- /dev/null +++ b/ojoy/r-notebook/README.md @@ -0,0 +1,5 @@ +This folder has the R notebook docker files for DKSG's work with the O'Joy. + +Events: + +* April 2017, DataDive diff --git a/ojoy/rstudio/Dockerfile b/ojoy/rstudio/Dockerfile new file mode 100644 index 0000000..37fc6ab --- /dev/null +++ b/ojoy/rstudio/Dockerfile @@ -0,0 +1,27 @@ +FROM rocker/rstudio:3.3.3 + +RUN R -e 'install.packages("devtools")' + + +RUN R -e 'library(devtools); \ + install_version("ggplot2", "2.2.1");' + + +RUN R -e 'library(devtools); \ + install_version("dplyr", "0.5.0");' + +RUN R -e 'library(devtools); \ + install_version("tidyr", "0.6.1");' + +RUN R -e 'library(devtools); \ + install_version("data.table", "1.10.4");' + +RUN R -e 'library(devtools); \ + install_version("leaflet", "1.1.0");' + +RUN R -e 'library(devtools); \ + install_version("shiny", "1.0.1", repos = "https://cloud.r-project.org/");' + +RUN R -e 'library(devtools); \ + install_version("vcd", "1.4-3");' + diff --git a/python3-notebook/Dockerfile b/python3-notebook/Dockerfile new file mode 100644 index 0000000..a578395 --- /dev/null +++ b/python3-notebook/Dockerfile @@ -0,0 +1,6 @@ +FROM jupyter/minimal-notebook:9e056d61b7a5 + +COPY requirements.txt /tmp/ +RUN pip install --requirement /tmp/requirements.txt +COPY . /tmp/ + diff --git a/dockerPython/readme.md b/python3-notebook/readme.md similarity index 100% rename from dockerPython/readme.md rename to python3-notebook/readme.md diff --git a/python3-notebook/requirements.txt b/python3-notebook/requirements.txt new file mode 100644 index 0000000..a0127e8 --- /dev/null +++ b/python3-notebook/requirements.txt @@ -0,0 +1,6 @@ +matplotlib==2.0.0 +numpy==1.12.0 +pandas==0.19.2 +plotly==2.0.5 +scikit-learn==0.18.1 +scipy==0.19.0 diff --git a/r-notebook/.dockerignore b/r-notebook/.dockerignore new file mode 100644 index 0000000..9dea340 --- /dev/null +++ b/r-notebook/.dockerignore @@ -0,0 +1,2 @@ +# Documentation +README.md diff --git a/r-notebook/Dockerfile b/r-notebook/Dockerfile new file mode 100644 index 0000000..c3ea7aa --- /dev/null +++ b/r-notebook/Dockerfile @@ -0,0 +1,40 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +FROM jupyter/minimal-notebook + +MAINTAINER Jupyter Project + +USER root + +# R pre-requisites +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + fonts-dejavu \ + gfortran \ + gcc && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +USER $NB_USER + +# R packages +RUN conda config --add channels r && \ + conda install --quiet --yes \ + 'r-base=3.3.2' \ + 'r-irkernel=0.7*' \ + 'r-plyr=1.8*' \ + 'r-devtools=1.12*' \ + 'r-tidyverse=1.0*' \ + 'r-shiny=0.14*' \ + 'r-rmarkdown=1.2*' \ + 'r-forecast=7.3*' \ + 'r-rsqlite=1.1*' \ + 'r-reshape2=1.4*' \ + 'r-nycflights13=0.2*' \ + 'r-caret=6.0*' \ + 'r-rcurl=1.95*' \ + 'r-crayon=1.3*' \ + 'r-randomforest=4.6*' && conda clean -tipsy + +RUN conda config --add channels BIMSBbioinfo && \ + conda install --quiet --yes \ + 'r-plotly=4.5.2' && conda clean -tipsy diff --git a/r-notebook/README.md b/r-notebook/README.md new file mode 100644 index 0000000..41808db --- /dev/null +++ b/r-notebook/README.md @@ -0,0 +1,118 @@ +![docker pulls](https://img.shields.io/docker/pulls/jupyter/r-notebook.svg) ![docker stars](https://img.shields.io/docker/stars/jupyter/r-notebook.svg) [![](https://images.microbadger.com/badges/image/jupyter/r-notebook.svg)](https://microbadger.com/images/jupyter/r-notebook "jupyter/r-notebook image metadata") + +# Jupyter Notebook R Stack + +## What it Gives You + +* Jupyter Notebook 4.3.x +* Conda R v3.3.x and channel +* plyr, devtools, shiny, rmarkdown, forecast, rsqlite, reshape2, nycflights13, caret, rcurl, and randomforest pre-installed +* The [tidyverse](https://github.com/tidyverse/tidyverse) R packages are also installed, including ggplot2, dplyr, tidyr, readr, purrr, tibble, stringr, lubridate, and broom +* Unprivileged user `jovyan` (uid=1000, configurable, see options) in group `users` (gid=100) with ownership over `/home/jovyan` and `/opt/conda` +* [tini](https://github.com/krallin/tini) as the container entrypoint and [start-notebook.sh](../base-notebook/start-notebook.sh) as the default command +* A [start-singleuser.sh](../base-notebook/start-singleuser.sh) script useful for running a single-user instance of the Notebook server, as required by JupyterHub +* A [start.sh](../base-notebook/start.sh) script useful for running alternative commands in the container (e.g. `ipython`, `jupyter kernelgateway`, `jupyter lab`) +* Options for a self-signed HTTPS certificate and passwordless `sudo` + +## Basic Use + +The following command starts a container with the Notebook server listening for HTTP connections on port 8888 with a randomly generated authentication token configured. + +``` +docker run -it --rm -p 8888:8888 jupyter/r-notebook +``` + +Take note of the authentication token included in the notebook startup log messages. Include it in the URL you visit to access the Notebook server or enter it in the Notebook login form. + +## Notebook Options + +The Docker container executes a [`start-notebook.sh` script](../base-notebook/start-notebook.sh) script by default. The `start-notebook.sh` script handles the `NB_UID` and `GRANT_SUDO` features documented in the next section, and then executes the `jupyter notebook`. + +You can pass [Jupyter command line options](https://jupyter.readthedocs.io/en/latest/projects/jupyter-command.html) through the `start-notebook.sh` script when launching the container. For example, to secure the Notebook server with a custom password hashed using `IPython.lib.passwd()` instead of the default token, run the following: + +``` +docker run -d -p 8888:8888 jupyter/r-notebook start-notebook.sh --NotebookApp.password='sha1:74ba40f8a388:c913541b7ee99d15d5ed31d4226bf7838f83a50e' +``` + +For example, to set the base URL of the notebook server, run the following: + +``` +docker run -d -p 8888:8888 jupyter/r-notebook start-notebook.sh --NotebookApp.base_url=/some/path +``` + +For example, to disable all authentication mechanisms (not a recommended practice): + +``` +docker run -d -p 8888:8888 jupyter/r-notebook start-notebook.sh --NotebookApp.token='' +``` + +You can sidestep the `start-notebook.sh` script and run your own commands in the container. See the *Alternative Commands* section later in this document for more information. + +## Docker Options + +You may customize the execution of the Docker container and the command it is running with the following optional arguments. + +* `-e GEN_CERT=yes` - Generates a self-signed SSL certificate and configures Jupyter Notebook to use it to accept encrypted HTTPS connections. +* `-e NB_UID=1000` - Specify the uid of the `jovyan` user. Useful to mount host volumes with specific file ownership. For this option to take effect, you must run the container with `--user root`. (The `start-notebook.sh` script will `su jovyan` after adjusting the user id.) +* `-e GRANT_SUDO=yes` - Gives the `jovyan` user passwordless `sudo` capability. Useful for installing OS packages. For this option to take effect, you must run the container with `--user root`. (The `start-notebook.sh` script will `su jovyan` after adding `jovyan` to sudoers.) **You should only enable `sudo` if you trust the user or if the container is running on an isolated host.** +* `-v /some/host/folder/for/work:/home/jovyan/work` - Host mounts the default working directory on the host to preserve work even when the container is destroyed and recreated (e.g., during an upgrade). + +## SSL Certificates + +You may mount SSL key and certificate files into a container and configure Jupyter Notebook to use them to accept HTTPS connections. For example, to mount a host folder containing a `notebook.key` and `notebook.crt`: + +``` +docker run -d -p 8888:8888 \ + -v /some/host/folder:/etc/ssl/notebook \ + jupyter/r-notebook start-notebook.sh \ + --NotebookApp.keyfile=/etc/ssl/notebook/notebook.key + --NotebookApp.certfile=/etc/ssl/notebook/notebook.crt +``` + +Alternatively, you may mount a single PEM file containing both the key and certificate. For example: + +``` +docker run -d -p 8888:8888 \ + -v /some/host/folder/notebook.pem:/etc/ssl/notebook.pem \ + jupyter/r-notebook start-notebook.sh \ + --NotebookApp.certfile=/etc/ssl/notebook.pem +``` + +In either case, Jupyter Notebook expects the key and certificate to be a base64 encoded text file. The certificate file or PEM may contain one or more certificates (e.g., server, intermediate, and root). + +For additional information about using SSL, see the following: + +* The [docker-stacks/examples](https://github.com/jupyter/docker-stacks/tree/master/examples) for information about how to use [Let's Encrypt](https://letsencrypt.org/) certificates when you run these stacks on a publicly visible domain. +* The [jupyter_notebook_config.py](jupyter_notebook_config.py) file for how this Docker image generates a self-signed certificate. +* The [Jupyter Notebook documentation](https://jupyter-notebook.readthedocs.io/en/latest/public_server.html#using-ssl-for-encrypted-communication) for best practices about running a public notebook server in general, most of which are encoded in this image. + + +## Alternative Commands + +### start-singleuser.sh + +[JupyterHub](https://jupyterhub.readthedocs.io) requires a single-user instance of the Jupyter Notebook server per user. To use this stack with JupyterHub and [DockerSpawner](https://github.com/jupyter/dockerspawner), you must specify the container image name and override the default container run command in your `jupyterhub_config.py`: + +```python +# Spawn user containers from this image +c.DockerSpawner.container_image = 'jupyter/r-notebook' + +# Have the Spawner override the Docker run command +c.DockerSpawner.extra_create_kwargs.update({ + 'command': '/usr/local/bin/start-singleuser.sh' +}) +``` + +### start.sh + +The `start.sh` script supports the same features as the default `start-notebook.sh` script (e.g., `GRANT_SUDO`), but allows you to specify an arbitrary command to execute. For example, to run the text-based `ipython` console in a container, do the following: + +``` +docker run -it --rm jupyter/r-notebook start.sh ipython +``` + +This script is particularly useful when you derive a new Dockerfile from this image and install additional Jupyter applications with subcommands like `jupyter console`, `jupyter kernelgateway`, and `jupyter lab`. + +### Others + +You can bypass the provided scripts and specify your an arbitrary start command. If you do, keep in mind that certain features documented above will not function (e.g., `GRANT_SUDO`). diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..d3bbc70 --- /dev/null +++ b/readme.md @@ -0,0 +1,248 @@ +# Contents + +- [Introduction](#introduction) +- [Installation](#installation) +- [Ensure that Docker is Running](#ensure-that-docker-is-running) +- [Using Python Notebooks](#using-docker-for-python-notebooks) +- [Using R Notebooks](#using-docker-for-r-notebooks) +- [Using RStudio](#using-docker-for-rstudio) +- [Adding new libraries](#adding-new-libraries) + +## Introduction + +*Contain Yourself* provides volunteers of DataKind Singapore a consistent enviroment when working on a project. By containerizing our tools we can: + +- be inclusive of volunteers who are running Windows/MacOS/Linux +- be more productive by reducing frictions in working on different platforms +- maintain reproducibility when sending containers with code to our partners as it's ready to run no matter what environment they're using. + +### What are containers (in the software sense)? + +Containers are a virtual operating system that can run applications or processes the same way regardless of the actual host operating system. For example, somebody who has Windows installed on their laptop can: + +1. develop an application within a container +2. pass that container to her project members +3. run the application on their machines regardless of their operating system +4. get the same results from running the application + +We'll be using [Docker](https://www.docker.com/) containers. Docker images for different projects will be hosted in a Quay.io repository. [Quay.io](https://quay.io/) is a service that specializes in building and hosting Docker repositories. + +## Installation + +### ... for Windows + +Follow the setup instructions here: https://docs.docker.com/docker-for-windows/install/ + +Note: If your machine doesn't met the requirement for "Docker For Windows", try setting up "Docker Toolbox": +https://docs.docker.com/toolbox/toolbox_install_windows/ + +### ... for Linux + +Follow the setup instructions for your flavor of Linux here: https://docs.docker.com/engine/installation/linux/ + +### ... for MacOS + +Follow the setup instructions here: https://store.docker.com/editions/community/docker-ce-desktop-mac + +Or if you use Homebrew Cask, + +``` +$ brew cask install docker +``` + +## Ensure that Docker is Running + +Start running the Docker app. Check that it is running on the command line: + +``` +$ docker info +Containers: 3 + Running: 0 + Paused: 0 + Stopped: 3 +Images: 1 +Server Version: 1.13.1 +... +``` + +## Using Docker for Python Notebooks +### Getting a Python Jupyter Notebook Container Image + +There are at least two ways of getting an image: + +- Pulling from a repository (such as quay.io) +- Loading from a file + +#### Pulling from a repository +You can pull down the image with: + +``` +$ docker pull quay.io/dksg/python3-notebook:1.0.0 +``` + +Once that finishes downloading, you should see something like: + +``` +$ docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +quay.io/dksg/python3-notebook 1.0.0 f01e49a5a922 3 days ago 2.61 GB +``` + +#### Loading from a file +This is an alternative method. Skip this if you already have pulled from a repository successfully. Otherwise, follow the steps below: + +1. Copy the tar file (get this from a DK corelead) to your local directory (e.g. quay.io_SLASH_dksg_SLASH_python3-notebook_1.0.0.tar) +2. In your local directory, run the following docker command: +``` +docker load --input quay.io_SLASH_dksg_SLASH_python3-notebook_1.0.0.tar +``` +3. This will return a loaded image id. +4. Tag the newly added image with the version from the filename by running the following: +``` +docker tag quay.io/dksg/python3-notebook:1.0.0 + +``` + +### Running a Jupyter Notebook from the pulled/loaded image + +Take the `IMAGE ID` from previous step and start it up with this command: + +``` +docker run -p 8888:8888 -v /path/to/local/directory:/home/jovyan/work f01e49a5a922 +``` +**Note:** /path/to/local/directory should be replaced by **an existing local directory in your laptop.** +This is where your notebooks (.ipynb) will be stored. +e.g. docker run -p 8888:8888 -v /Users/johndoe/datadive:/home/jovyan/work quay.io/dksg/python3-notebook:1.0.0 + +You will get instructions for link to paste into your browser address box. If you're using Docker Toolbox, you should use the custom IP address (default http://192.168.99.100/) + +### Once the notebook is running, you may create a new notebook and try the samples in this tutorial: +https://plot.ly/python/ipython-notebook-tutorial/ + +Note: The following python script may be needed to run first in order to run the above tutorial samples: +``` +import plotly +plotly.offline.init_notebook_mode() # run at the start of every ipython notebook +``` + + +## Using Docker for R Notebooks +### Getting an R Jupyter Notebook Container Image + +There are at least two ways of getting an image: + +- Pulling from a repository (such as quay.io) +- Loading from a file + +#### Pulling from a repository +You can pull down the image with: + +``` +$ docker pull quay.io/dksg/r-notebook:1.0.1 +``` + +Once that finishes downloading, you should see something like: + +``` +$ docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +quay.io/dksg/r-notebook 1.0.1 f01e49a5a922 3 days ago 2.61 GB +``` + +#### Loading from a file +This is an alternative method. Skip this if you already have pulled from a repository successfully. Otherwise, follow the steps below: + +1. Copy the tar file (get this from a DK corelead) to your local directory (e.g. quay.io_SLASH_dksg_SLASH_r-notebook_1.0.1.tar) +2. In your local directory, run the following docker command: +``` +docker load --input quay.io_SLASH_dksg_SLASH_r-notebook_1.0.1.tar +``` +3. This will return a loaded image id. +4. Tag the newly added image with the version from the filename by running the following: +``` +docker tag quay.io/dksg/r-notebook:1.0.1 + +``` + +### Running a Jupyter Notebook from the pulled/loaded image + +Take the `IMAGE ID` from previous step and start it up with this command: + +``` +docker run -p 8888:8888 -v /path/to/local/directory:/home/jovyan/work f01e49a5a922 +``` +**Note:** /path/to/local/directory should be replaced by **an existing local directory in your laptop.** +This is where your notebooks (.ipynb) will be stored. +e.g. docker run -p 8888:8888 -v /Users/johndoe/datadive:/home/jovyan/work quay.io/dksg/r-notebook:1.0.1 + +You will get instructions for link to paste into your browser address box. If you're using Docker Toolbox, you should use the custom IP address (default http://192.168.99.100/) + +### Once the notebook is running, you may create a new notebook and try the following samples: +https://plot.ly/r/using-r-in-jupyter-notebooks/#examples + + +## Using Docker for RStudio +### Getting an RStudio Container Image + +There are at least two ways of getting an image: + +- Pulling from a repository (such as quay.io) +- Loading from a file + +#### Pulling from a repository +You can pull down the image with: + +``` +$ docker pull quay.io/dksg/ojoy-rstudio:1.0.2 +``` + +Once that finishes downloading, you should see something like: + +``` +$ docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +quay.io/dksg/ojoy-rstudio 1.0.2 1c1e06209032 13 hours ago 1.166 GB +``` + +#### Loading from a file +This is an alternative method. Skip this if you already have pulled from a repository successfully. Otherwise, follow the steps below: + +1. Copy the tar file (get this from a DK corelead) to your local directory (e.g. quay.io_SLASH_dksg_SLASH_ojoy-rstudio_1.0.2.tar) +2. In your local directory, run the following docker command: +``` +docker load --input quay.io_SLASH_dksg_SLASH_ojoy-rstudio_1.0.2.tar +``` +3. Once loaded, you should be able to see the new image when you run "docker images": +``` +$ docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +quay.io/dksg/ojoy-rstudio 1.0.2 1c1e06209032 13 hours ago 1.166 GB +``` + + +### Running RStudio from the pulled/loaded image + +Start it up with this command: + +``` +docker run -p 8787:8787 -v /path/to/local/directory:/home/rstudio/foobar quay.io/dksg/ojoy-rstudio:1.0.2 +``` +**Note:** /path/to/local/directory should be replaced by **an existing local directory in your laptop.** +This is where your data/scripts will be stored. +e.g. docker run -d -p 8787:8787 -v /Users/johndoe/datadive:/home/rstudio/foobar quay.io/dksg/ojoy-rstudio:1.0.2 + +You should be able to access RStudio in the browser via http://localhost:8787. If you're using Docker Toolbox, you should use the custom IP address (default http://192.168.99.100:8787) + +Username: rstudio + +Password: rstudio + + +## Adding new libraries + +If there's a python or R library that you need, you can install it in your container, but unless the library is persisted to the image, your scripts that use the library will not run on somebody else's machine. Each project will have a person assigned as a *library curator* and they will be able to include the library in the project's docker image. Workflow should be: + +1. You're puttering along when you realise that you want to add your favourite nlp library. +2. You install it in your container, and try it out. It works great! +3. Show it to your project's curator and convince them that it's a useful library. Their default mode is lazy and they will try to point you to an existing library. You show them the hot shiny feature the one you want has. +4. The curator changes the requirements file in our docker file Github repo, Quay auto-magically builds a new image, and when people need to run your code, they need to use this new image. diff --git a/redcross-blood-program/python3-notebook/Dockerfile b/redcross-blood-program/python3-notebook/Dockerfile new file mode 100644 index 0000000..a578395 --- /dev/null +++ b/redcross-blood-program/python3-notebook/Dockerfile @@ -0,0 +1,6 @@ +FROM jupyter/minimal-notebook:9e056d61b7a5 + +COPY requirements.txt /tmp/ +RUN pip install --requirement /tmp/requirements.txt +COPY . /tmp/ + diff --git a/redcross-blood-program/python3-notebook/readme.md b/redcross-blood-program/python3-notebook/readme.md new file mode 100644 index 0000000..c672989 --- /dev/null +++ b/redcross-blood-program/python3-notebook/readme.md @@ -0,0 +1,5 @@ +This folder has the Python notebook docker files for DKSG's work with the Red Cross Blood Programme. + +Events: + +* April 2017, DataDive diff --git a/redcross-blood-program/python3-notebook/requirements.txt b/redcross-blood-program/python3-notebook/requirements.txt new file mode 100644 index 0000000..f025e1b --- /dev/null +++ b/redcross-blood-program/python3-notebook/requirements.txt @@ -0,0 +1,8 @@ +matplotlib==2.0.0 +numpy==1.12.0 +pandas==0.19.2 +plotly==2.0.5 +scikit-learn==0.18.1 +scipy==0.19.0 +folium==0.3.0 +geopy==1.11.0 diff --git a/redcross-blood-program/r-notebook/.dockerignore b/redcross-blood-program/r-notebook/.dockerignore new file mode 100644 index 0000000..9dea340 --- /dev/null +++ b/redcross-blood-program/r-notebook/.dockerignore @@ -0,0 +1,2 @@ +# Documentation +README.md diff --git a/redcross-blood-program/r-notebook/Dockerfile b/redcross-blood-program/r-notebook/Dockerfile new file mode 100644 index 0000000..aeaa04f --- /dev/null +++ b/redcross-blood-program/r-notebook/Dockerfile @@ -0,0 +1,40 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +FROM jupyter/minimal-notebook:9e056d61b7a5 + +MAINTAINER Jupyter Project + +USER root + +# R pre-requisites +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + fonts-dejavu \ + gfortran \ + gcc && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +USER $NB_USER + +# R packages +RUN conda config --add channels r && \ + conda install --quiet --yes \ + 'r-base=3.3.2' \ + 'r-irkernel=0.7*' \ + 'r-plyr=1.8*' \ + 'r-devtools=1.12*' \ + 'r-tidyverse=1.0*' \ + 'r-shiny=0.14*' \ + 'r-rmarkdown=1.2*' \ + 'r-forecast=7.3*' \ + 'r-rsqlite=1.1*' \ + 'r-reshape2=1.4*' \ + 'r-nycflights13=0.2*' \ + 'r-caret=6.0*' \ + 'r-rcurl=1.95*' \ + 'r-crayon=1.3*' \ + 'r-randomforest=4.6*' && conda clean -tipsy + +RUN conda config --add channels BIMSBbioinfo && \ + conda install --quiet --yes \ + 'r-plotly=4.5.2' && conda clean -tipsy diff --git a/redcross-blood-program/r-notebook/README.md b/redcross-blood-program/r-notebook/README.md new file mode 100644 index 0000000..41808db --- /dev/null +++ b/redcross-blood-program/r-notebook/README.md @@ -0,0 +1,118 @@ +![docker pulls](https://img.shields.io/docker/pulls/jupyter/r-notebook.svg) ![docker stars](https://img.shields.io/docker/stars/jupyter/r-notebook.svg) [![](https://images.microbadger.com/badges/image/jupyter/r-notebook.svg)](https://microbadger.com/images/jupyter/r-notebook "jupyter/r-notebook image metadata") + +# Jupyter Notebook R Stack + +## What it Gives You + +* Jupyter Notebook 4.3.x +* Conda R v3.3.x and channel +* plyr, devtools, shiny, rmarkdown, forecast, rsqlite, reshape2, nycflights13, caret, rcurl, and randomforest pre-installed +* The [tidyverse](https://github.com/tidyverse/tidyverse) R packages are also installed, including ggplot2, dplyr, tidyr, readr, purrr, tibble, stringr, lubridate, and broom +* Unprivileged user `jovyan` (uid=1000, configurable, see options) in group `users` (gid=100) with ownership over `/home/jovyan` and `/opt/conda` +* [tini](https://github.com/krallin/tini) as the container entrypoint and [start-notebook.sh](../base-notebook/start-notebook.sh) as the default command +* A [start-singleuser.sh](../base-notebook/start-singleuser.sh) script useful for running a single-user instance of the Notebook server, as required by JupyterHub +* A [start.sh](../base-notebook/start.sh) script useful for running alternative commands in the container (e.g. `ipython`, `jupyter kernelgateway`, `jupyter lab`) +* Options for a self-signed HTTPS certificate and passwordless `sudo` + +## Basic Use + +The following command starts a container with the Notebook server listening for HTTP connections on port 8888 with a randomly generated authentication token configured. + +``` +docker run -it --rm -p 8888:8888 jupyter/r-notebook +``` + +Take note of the authentication token included in the notebook startup log messages. Include it in the URL you visit to access the Notebook server or enter it in the Notebook login form. + +## Notebook Options + +The Docker container executes a [`start-notebook.sh` script](../base-notebook/start-notebook.sh) script by default. The `start-notebook.sh` script handles the `NB_UID` and `GRANT_SUDO` features documented in the next section, and then executes the `jupyter notebook`. + +You can pass [Jupyter command line options](https://jupyter.readthedocs.io/en/latest/projects/jupyter-command.html) through the `start-notebook.sh` script when launching the container. For example, to secure the Notebook server with a custom password hashed using `IPython.lib.passwd()` instead of the default token, run the following: + +``` +docker run -d -p 8888:8888 jupyter/r-notebook start-notebook.sh --NotebookApp.password='sha1:74ba40f8a388:c913541b7ee99d15d5ed31d4226bf7838f83a50e' +``` + +For example, to set the base URL of the notebook server, run the following: + +``` +docker run -d -p 8888:8888 jupyter/r-notebook start-notebook.sh --NotebookApp.base_url=/some/path +``` + +For example, to disable all authentication mechanisms (not a recommended practice): + +``` +docker run -d -p 8888:8888 jupyter/r-notebook start-notebook.sh --NotebookApp.token='' +``` + +You can sidestep the `start-notebook.sh` script and run your own commands in the container. See the *Alternative Commands* section later in this document for more information. + +## Docker Options + +You may customize the execution of the Docker container and the command it is running with the following optional arguments. + +* `-e GEN_CERT=yes` - Generates a self-signed SSL certificate and configures Jupyter Notebook to use it to accept encrypted HTTPS connections. +* `-e NB_UID=1000` - Specify the uid of the `jovyan` user. Useful to mount host volumes with specific file ownership. For this option to take effect, you must run the container with `--user root`. (The `start-notebook.sh` script will `su jovyan` after adjusting the user id.) +* `-e GRANT_SUDO=yes` - Gives the `jovyan` user passwordless `sudo` capability. Useful for installing OS packages. For this option to take effect, you must run the container with `--user root`. (The `start-notebook.sh` script will `su jovyan` after adding `jovyan` to sudoers.) **You should only enable `sudo` if you trust the user or if the container is running on an isolated host.** +* `-v /some/host/folder/for/work:/home/jovyan/work` - Host mounts the default working directory on the host to preserve work even when the container is destroyed and recreated (e.g., during an upgrade). + +## SSL Certificates + +You may mount SSL key and certificate files into a container and configure Jupyter Notebook to use them to accept HTTPS connections. For example, to mount a host folder containing a `notebook.key` and `notebook.crt`: + +``` +docker run -d -p 8888:8888 \ + -v /some/host/folder:/etc/ssl/notebook \ + jupyter/r-notebook start-notebook.sh \ + --NotebookApp.keyfile=/etc/ssl/notebook/notebook.key + --NotebookApp.certfile=/etc/ssl/notebook/notebook.crt +``` + +Alternatively, you may mount a single PEM file containing both the key and certificate. For example: + +``` +docker run -d -p 8888:8888 \ + -v /some/host/folder/notebook.pem:/etc/ssl/notebook.pem \ + jupyter/r-notebook start-notebook.sh \ + --NotebookApp.certfile=/etc/ssl/notebook.pem +``` + +In either case, Jupyter Notebook expects the key and certificate to be a base64 encoded text file. The certificate file or PEM may contain one or more certificates (e.g., server, intermediate, and root). + +For additional information about using SSL, see the following: + +* The [docker-stacks/examples](https://github.com/jupyter/docker-stacks/tree/master/examples) for information about how to use [Let's Encrypt](https://letsencrypt.org/) certificates when you run these stacks on a publicly visible domain. +* The [jupyter_notebook_config.py](jupyter_notebook_config.py) file for how this Docker image generates a self-signed certificate. +* The [Jupyter Notebook documentation](https://jupyter-notebook.readthedocs.io/en/latest/public_server.html#using-ssl-for-encrypted-communication) for best practices about running a public notebook server in general, most of which are encoded in this image. + + +## Alternative Commands + +### start-singleuser.sh + +[JupyterHub](https://jupyterhub.readthedocs.io) requires a single-user instance of the Jupyter Notebook server per user. To use this stack with JupyterHub and [DockerSpawner](https://github.com/jupyter/dockerspawner), you must specify the container image name and override the default container run command in your `jupyterhub_config.py`: + +```python +# Spawn user containers from this image +c.DockerSpawner.container_image = 'jupyter/r-notebook' + +# Have the Spawner override the Docker run command +c.DockerSpawner.extra_create_kwargs.update({ + 'command': '/usr/local/bin/start-singleuser.sh' +}) +``` + +### start.sh + +The `start.sh` script supports the same features as the default `start-notebook.sh` script (e.g., `GRANT_SUDO`), but allows you to specify an arbitrary command to execute. For example, to run the text-based `ipython` console in a container, do the following: + +``` +docker run -it --rm jupyter/r-notebook start.sh ipython +``` + +This script is particularly useful when you derive a new Dockerfile from this image and install additional Jupyter applications with subcommands like `jupyter console`, `jupyter kernelgateway`, and `jupyter lab`. + +### Others + +You can bypass the provided scripts and specify your an arbitrary start command. If you do, keep in mind that certain features documented above will not function (e.g., `GRANT_SUDO`).