diff --git a/Dockerfile b/Dockerfile index be719e1..ba2bc3d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,94 @@ -FROM jupyter/base-notebook +## Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +## +## 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +## +## 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +## +## 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## +## Portions of this Dockerfile were copied from [jupyter/base-notebook](https://github.com/jupyter/docker-stacks/blob/master/base-notebook/Dockerfile) +## +FROM debian@sha256:52af198afd8c264f1035206ca66a5c48e602afb32dc912ebf9e9478134601ec4 MAINTAINER mtucker502 USER root -# Install prereqs for pyez -RUN apt-get update && \ - apt-get install -yq build-essential \ - libssl-dev - -# Install pyez -RUN pip install junos-eznc - -# Setup Python2 environment -RUN apt-get install -y \ +# Install all OS dependencies for notebook server that starts but lacks all +# features (e.g., download as all possible file formats) +ENV DEBIAN_FRONTEND noninteractive +RUN REPO=http://cdn-fastly.deb.debian.org \ + && echo "deb $REPO/debian jessie main\ndeb $REPO/debian-security jessie/updates main" > /etc/apt/sources.list \ + && apt-get update && apt-get -yq dist-upgrade \ + && apt-get install -yq --no-install-recommends \ + wget \ + bzip2 \ + ca-certificates \ + sudo \ + locales \ + build-essential \ + libssl-dev \ python \ python-dev \ python-lxml \ libssl-dev \ libffi-dev \ - libzmq-dev + libzmq-dev \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ + locale-gen + +# Install Tini +RUN wget --quiet https://github.com/krallin/tini/releases/download/v0.10.0/tini && \ + echo "1361527f39190a7338a0b434bd8c88ff7233ce7b9a4876f3315c22fce7eca1b0 *tini" | sha256sum -c - && \ + mv tini /usr/local/bin/tini && \ + chmod +x /usr/local/bin/tini + +# Configure environment +ENV CONDA_DIR /opt/conda +ENV PATH $CONDA_DIR/bin:$PATH +ENV SHELL /bin/bash +ENV NB_USER jovyan +ENV NB_UID 1000 +ENV HOME /home/$NB_USER +ENV LC_ALL en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US.UTF-8 + +# Create jovyan user with UID=1000 and in the 'users' group +RUN useradd -m -s /bin/bash -N -u $NB_UID $NB_USER && \ + mkdir -p $CONDA_DIR && \ + chown $NB_USER $CONDA_DIR + +USER $NB_USER + +# Setup jovyan home directory +RUN mkdir /home/$NB_USER/work && \ + mkdir /home/$NB_USER/.jupyter && \ + echo "cacert=/etc/ssl/certs/ca-certificates.crt" > /home/$NB_USER/.curlrc + +# Install conda as jovyan +RUN cd /tmp && \ + mkdir -p $CONDA_DIR && \ + wget --quiet https://repo.continuum.io/miniconda/Miniconda3-4.2.12-Linux-x86_64.sh && \ + echo "c59b3dd3cad550ac7596e0d599b91e75d88826db132e4146030ef471bb434e9a *Miniconda3-4.2.12-Linux-x86_64.sh" | sha256sum -c - && \ + /bin/bash Miniconda3-4.2.12-Linux-x86_64.sh -f -b -p $CONDA_DIR && \ + rm Miniconda3-4.2.12-Linux-x86_64.sh && \ + $CONDA_DIR/bin/conda config --system --add channels conda-forge && \ + $CONDA_DIR/bin/conda config --system --set auto_update_conda false && \ + conda clean -tipsy + +# Install Jupyter Notebook and Hub +RUN conda install --quiet --yes \ + 'notebook=4.3*' \ + jupyterhub=0.7 \ + && conda clean -tipsy + +USER root # Python 2 pip is currently broken in the repos. Install with get-pip.py RUN wget https://bootstrap.pypa.io/get-pip.py; python2 get-pip.py @@ -36,12 +105,20 @@ RUN pip2 install junos-eznc junos-netconify jxmlease jsnapy ansible # Install Juniper's Ansible modules RUN ansible-galaxy install Juniper.junos +EXPOSE 8888 +WORKDIR /home/$NB_USER/work -# Change owner so Notebook notebook can write to it -RUN chown -R jovyan:users /home/jovyan/.* - -# Kludge because .ansible/tmp ends up corrupted during the install -RUN rm -fr /home/jovyan/.ansible* +# Configure container startup +ENTRYPOINT ["tini", "--"] +CMD ["start-notebook.sh"] +VOLUME ["/home/$NB_USER/work"] +# Add local files as late as possible to avoid cache busting +COPY start.sh /usr/local/bin/ +COPY start-notebook.sh /usr/local/bin/ +COPY start-singleuser.sh /usr/local/bin/ +COPY jupyter_notebook_config.py /home/$NB_USER/.jupyter/ +RUN chown -R $NB_USER:users /home/$NB_USER/.jupyter +# Switch back to jovyan to avoid accidental container runs as root USER $NB_USER