Skip to content

Commit 6880d2f

Browse files
committedDec 8, 2015
Updating docker image to be based on the Jupyter defined datascience-notebook to remove downstream management
1 parent e8d7b61 commit 6880d2f

File tree

5 files changed

+59
-98
lines changed

5 files changed

+59
-98
lines changed
 

‎Dockerfile

+12-86
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,23 @@
1-
# Econometrics Book Base Docker Image (for tmpnb orchestrate.py server)
2-
# User: econ
1+
# Econometrics Book Docker Image
2+
# User: jovyan
3+
# This uses the Jupyter DataScience Docker Container with Python, R and Julia
34

4-
FROM debian:jessie
5+
FROM jupyter/datascience-notebook
56

67
MAINTAINER Matthew McKay <mamckay@gmail.com>
78

8-
# Install all OS dependencies for fully functional notebook server
9-
ENV DEBIAN_FRONTEND noninteractive
10-
RUN apt-get update && apt-get install -yq --no-install-recommends \
11-
git \
12-
vim \
13-
wget \
14-
build-essential \
15-
python-dev \
16-
ca-certificates \
17-
bzip2 \
18-
unzip \
19-
libsm6 \
20-
pandoc \
21-
texlive-latex-base \
22-
texlive-latex-extra \
23-
texlive-fonts-extra \
24-
texlive-fonts-recommended \
25-
supervisor \
26-
sudo \
27-
&& apt-get clean
28-
29-
# Julia dependencies
30-
RUN apt-get install -y julia libnettle4 && apt-get clean
31-
32-
# R dependencies that conda can't provide (X, fonts, compilers)
33-
RUN apt-get install -y libzmq3-dev libcurl4-openssl-dev libxrender1 fonts-dejavu gfortran gcc && apt-get clean
34-
35-
ENV CONDA_DIR /opt/conda
36-
37-
# Install conda
38-
RUN echo 'export PATH=$CONDA_DIR/bin:$PATH' > /etc/profile.d/conda.sh && \
39-
wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
40-
/bin/bash Miniconda3-latest-Linux-x86_64.sh -b -p $CONDA_DIR && \
41-
rm Miniconda3-latest-Linux-x86_64.sh && \
42-
$CONDA_DIR/bin/conda install --yes python=3.5 anaconda && $CONDA_DIR/bin/conda clean -yt
43-
44-
# We run our docker images with a non-root user as a security precaution.
45-
# econ is our user
46-
RUN useradd -m -s /bin/bash econ
47-
RUN chown -R econ:econ $CONDA_DIR
48-
49-
EXPOSE 8888
50-
51-
USER econ
52-
ENV HOME /home/econ
53-
ENV SHELL /bin/bash
54-
ENV USER econ
55-
ENV PATH $CONDA_DIR/bin:$PATH
56-
WORKDIR $HOME
57-
58-
RUN conda install --yes ipython-notebook terminado && conda clean -yt
59-
60-
RUN ipython profile create
61-
62-
# Workaround for issue with ADD permissions
639
USER root
64-
ADD notebooks/ /home/econ/
65-
RUN chown econ:econ /home/econ -R
66-
USER econ
67-
68-
# Python packages
69-
RUN conda install --yes python=3.5 anaconda && conda clean -yt
70-
RUN pip install quantecon
7110

72-
# Now for a python2 environment
73-
# RUN conda create -p $CONDA_DIR/envs/python2 python=2.7 ipython numpy pandas scikit-learn scikit-image matplotlib scipy seaborn sympy cython patsy statsmodels cloudpickle dill numba bokeh && conda clean -yt
74-
# RUN $CONDA_DIR/envs/python2/bin/python $CONDA_DIR/envs/python2/bin/ipython kernelspec install-self --user
75-
# RUN source activate python2 && pip install quantecon && source deactivate python2
11+
#-Add Notebooks-#
12+
ADD notebooks/ /home/jovyan/work/
7613

77-
# R packages
78-
RUN conda config --add channels r
79-
RUN conda install --yes r-irkernel r-plyr r-devtools r-rcurl r-dplyr r-ggplot2 r-caret rpy2 r-tidyr r-shiny r-rmarkdown r-forecast r-stringr r-rsqlite r-reshape2 r-nycflights13 r-randomforest && conda clean -yt
80-
81-
# IJulia and Julia packages
82-
RUN julia -e 'Pkg.add("IJulia")'
83-
# RUN julia -e 'Pkg.add("PyPlot")' && julia -e 'Pkg.add("Distributions")' && julia -e 'Pkg.add("KernelEstimator")'
84-
# julia -e 'Pkg.add("Gadfly")' && julia -e 'Pkg.add("RDatasets")' &&
85-
86-
#Add Templates
87-
USER root
88-
ADD profile_default /home/econ/.ipython/profile_default
14+
#-Add Templates-#
15+
ADD jupyter_notebook_config.py /home/jovyan/.jupyter/
8916
ADD templates/ /srv/templates/
9017
RUN chmod a+rX /srv/templates
91-
USER econ
9218

93-
# Convert notebooks to the current format
94-
RUN find /home/. -name '*.ipynb' -exec ipython nbconvert --to notebook {} --output {} \;
95-
RUN find /home/. -name '*.ipynb' -exec ipython trust {} \;
19+
#-Convert notebooks to the current format-#
20+
RUN find /home/. -name '*.ipynb' -exec jupyter nbconvert --to notebook {} --output {} \;
21+
RUN find /home/. -name '*.ipynb' -exec jupyter trust {} \;
9622

97-
CMD ipython notebook
23+
USER jovyan

‎jupyter_notebook_config.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Modified to include custom template
2+
# Copyright (c) Jupyter Development Team.
3+
from jupyter_core.paths import jupyter_data_dir
4+
import subprocess
5+
import os
6+
import errno
7+
import stat
8+
9+
PEM_FILE = os.path.join(jupyter_data_dir(), 'notebook.pem')
10+
11+
c = get_config()
12+
c.NotebookApp.ip = '*'
13+
c.NotebookApp.port = 8888
14+
c.NotebookApp.open_browser = False
15+
16+
# Include our extra templates
17+
c.NotebookApp.extra_template_paths = ['/srv/templates/']
18+
19+
# Set a certificate if USE_HTTPS is set to any value
20+
if 'USE_HTTPS' in os.environ:
21+
if not os.path.isfile(PEM_FILE):
22+
# Ensure PEM_FILE directory exists
23+
dir_name = os.path.dirname(PEM_FILE)
24+
try:
25+
os.makedirs(dir_name)
26+
except OSError as exc: # Python >2.5
27+
if exc.errno == errno.EEXIST and os.path.isdir(dir_name):
28+
pass
29+
else: raise
30+
# Generate a certificate if one doesn't exist on disk
31+
subprocess.check_call(['openssl', 'req', '-new',
32+
'-newkey', 'rsa:2048', '-days', '365', '-nodes', '-x509',
33+
'-subj', '/C=XX/ST=XX/L=XX/O=generated/CN=generated',
34+
'-keyout', PEM_FILE, '-out', PEM_FILE])
35+
# Restrict access to PEM_FILE
36+
os.chmod(PEM_FILE, stat.S_IRUSR | stat.S_IWUSR)
37+
c.NotebookApp.certfile = PEM_FILE
38+
39+
# Set a password if PASSWORD is set
40+
if 'PASSWORD' in os.environ:
41+
from IPython.lib import passwd
42+
c.NotebookApp.password = passwd(os.environ['PASSWORD'])
43+
del os.environ['PASSWORD']

‎scripts/run-local.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export TOKEN=$( head -c 30 /dev/urandom | xxd -p )
33
docker run --net=host -d -e CONFIGPROXY_AUTH_TOKEN=$TOKEN --name=proxy jupyter/configurable-http-proxy --default-target http://127.0.0.1:9999
44
docker run --net=host -d -e CONFIGPROXY_AUTH_TOKEN=$TOKEN \
55
-v /var/run/docker.sock:/docker.sock \
6-
jupyter/tmpnb python orchestrate.py --image='sanguineturtle/econometrics' --command="ipython notebook --NotebookApp.base_url={base_path} --ip=0.0.0.0 --port {port}"
6+
jupyter/tmpnb python orchestrate.py --image='sanguineturtle/econometrics' --command="jupyter notebook --NotebookApp.base_url={base_path} --ip=0.0.0.0 --port {port}"

‎scripts/run.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export TOKEN=$( head -c 30 /dev/urandom | xxd -p )
66
docker run --net=host -d -e CONFIGPROXY_AUTH_TOKEN=$TOKEN --name=proxy jupyter/configurable-http-proxy --default-target http://127.0.0.1:9999
77
docker run --net=host -d -e CONFIGPROXY_AUTH_TOKEN=$TOKEN \
88
-v /var/run/docker.sock:/docker.sock \
9-
jupyter/tmpnb python orchestrate.py --image='sanguineturtle/econometrics' --command="ipython notebook --NotebookApp.base_url={base_path} --ip=0.0.0.0 --port {port}"
9+
jupyter/tmpnb python orchestrate.py --image='sanguineturtle/econometrics' --command="jupyter notebook --NotebookApp.base_url={base_path} --ip=0.0.0.0 --port {port}"
10+

‎scripts/setup-aws.sh

+1-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,4 @@ sudo yum install -y docker
44
sudo service docker start
55
sudo usermod -a -G docker ec2-user
66

7-
#LogOut-LogIn
8-
9-
docker pull jupyter/tmpnb
10-
docker pull jupyter/configurable-http-proxy
11-
docker pull sanguineturtle/econometrics
12-
export TOKEN=$( head -c 30 /dev/urandom | xxd -p )
13-
docker run --net=host -d -e CONFIGPROXY_AUTH_TOKEN=$TOKEN --name=proxy jupyter/configurable-http-proxy --default-target http://127.0.0.1:9999
14-
docker run --net=host -d -e CONFIGPROXY_AUTH_TOKEN=$TOKEN \
15-
-v /var/run/docker.sock:/docker.sock \
16-
jupyter/tmpnb python orchestrate.py --image='sanguineturtle/econometrics' --command="ipython notebook --NotebookApp.base_url={base_path} --ip=0.0.0.0 --port {port}"
7+
# Run ./scripts/run-local.sh

0 commit comments

Comments
 (0)