Bootstrap: library
From: debian:9

%environment
  JUP_PORT=8888
  JUP_IPNAME=localhost
  export JUP_PORT JUP_IPNAME

%help

    Container with Anaconda 2 (Conda 4.5.11 Canary) and Jupyter Notebook 5.6.0 for Debian 9.x (Stretch).
    This installation is based on Python 2.7.15

%setup

    #Create the .condarc file where the environments/channels from conda are specified, these are pulled with preference to root
    cd /
    touch .condarc

%post

    #Installing all dependencies

    apt-get update && apt-get -y upgrade
    apt-get -y install \
    build-essential \
    wget \
    bzip2 \
    ca-certificates \
    libglib2.0-0 \
    libxext6 \
    libsm6 \
    libxrender1 \
    git

   rm -rf /var/lib/apt/lists/*
   apt-get clean

  #Installing Anaconda 2 and Conda 4.5.11

  wget -c https://repo.continuum.io/archive/Anaconda2-5.3.0-Linux-x86_64.sh
    /bin/bash Anaconda2-5.3.0-Linux-x86_64.sh -bfp /usr/local

  #Conda configuration of channels from .condarc file

  conda config --file /.condarc --add channels defaults
  conda config --file /.condarc --add channels conda-forge
  conda update conda

  #List installed environments
  conda list

%startscript

  PORT=""
  if [ -n "$JUP_PORT" ]; then
    PORT="--port=${JUP_PORT}"
  fi

  IPNAME=""
  if [ -n "$JUP_IPNAME" ]; then
    IPNAME="--ip=${JUP_IPNAME}"
  fi

  exec jupyter notebook --allow-root ${PORT} ${IPNAME}
