11ARG python_version="3.11"
2- FROM quay.io/jupyter/base -notebook:python-${python_version}
2+ FROM quay.io/jupyter/minimal -notebook:python-${python_version}
33
44ARG python_version
5- ARG arcgis_version="2.3.1 "
5+ ARG arcgis_version="2.4.0 "
66ARG sampleslink="https://github.com/Esri/arcgis-python-api/releases/download/v${arcgis_version}/samples.zip"
77ARG githubfolder="arcgis-python-api"
8- ENV DOCKER_STACKS_JUPYTER_CMD= "notebook"
8+ ARG env_name=arcgis
99
1010LABEL org.opencontainers.image.authors=
"[email protected] " 11- LABEL org.opencontainers.image.description="Jupyter Notebook with the latest version of the ArcGIS API for Python and its Linux dependencies preinstalled "
11+ LABEL org.opencontainers.image.description="Jupyter environment preconfigured for ArcGIS API for Python"
1212LABEL org.opencontainers.image.licenses=Apache
1313LABEL org.opencontainers.image.source=https://github.com/Esri/arcgis-python-api
1414
15- USER root
16-
17- RUN apt-get update --yes && \
18- apt-get install --yes --no-install-recommends unzip && \
19- apt-get clean && rm -rf /var/lib/apt/lists/*
20-
2115USER ${NB_UID}
2216
2317# Install Python API from Conda
24- RUN conda install - c esri arcgis=${arcgis_version} -y \
18+ RUN conda create -n ${env_name} - c esri -c defaults arcgis=${arcgis_version} python=${python_version} -y --quiet --override-channels \
2519 && conda clean --all -f -y \
2620 && find /opt/conda -name __pycache__ -type d -exec rm -rf {} +
2721
22+ # Install arcgis-mapping if arcgis_version >= 2.4.0
23+ RUN (dpkg --compare-versions $arcgis_version ge 2.4.0 \
24+ && conda install -n ${env_name} -c esri -c defaults arcgis-mapping -y --quiet --override-channels \
25+ && conda clean --all -f -y \
26+ && find /opt/conda -name __pycache__ -type d -exec rm -rf {} +;) \
27+ || echo "[INFO] Skipped installing arcgis-mapping for version $arcgis_version (>= 2.4.0 required for arcgis-mapping)"
28+
2829# Fetch and extract samples from GitHub
2930RUN mkdir /home/${NB_USER}/$githubfolder && \
3031 wget -O samples.zip $sampleslink \
@@ -36,7 +37,34 @@ RUN mkdir /home/${NB_USER}/$githubfolder && \
3637 work/ \
3738 talks/ \
3839 environment.yml\
40+ # remove .DS_Store and __MACOSX from home directory:
41+ && find /home/${NB_USER} -name ".DS_Store" -delete \
42+ && rm -rf /home/${NB_USER}/__MACOSX \
3943 && fix-permissions /home/${NB_USER}
4044
41- RUN rm /opt/conda/lib/python${python_version}/site-packages/notebook/static/base/images/logo.png
42- COPY --chown=${NB_USER}:users jupyter_esri_logo.png /opt/conda/lib/python${python_version}/site-packages/notebook/static/base/images/logo.png
45+ # See https://jupyter-docker-stacks.readthedocs.io/en/latest/using/recipes.html#add-a-custom-conda-environment-and-jupyter-kernel
46+ # Create Python kernel and link it to jupyter
47+ RUN "${CONDA_DIR}/envs/${env_name}/bin/python" -m ipykernel install --user --name="${env_name}" && \
48+ fix-permissions "${CONDA_DIR}" && \
49+ fix-permissions "/home/${NB_USER}"
50+
51+
52+ # More information here: https://github.com/jupyter/docker-stacks/pull/2047
53+ USER root
54+
55+ # Set DOCKER_STACKS_JUPYTER_CMD to "notebook" for versions less than 2.4.0
56+ RUN \
57+ (dpkg --compare-versions $arcgis_version lt 2.4.0 \
58+ && echo 'DOCKER_STACKS_JUPYTER_CMD="notebook"' >> /etc/environment \
59+ && echo "[INFO] Set DOCKER_STACKS_JUPYTER_CMD to notebook for arcgis < 2.4.0" ) \
60+ || echo "[INFO] Using default DOCKER_STACKS_JUPYTER_CMD (lab) for arcgis >= 2.4.0"
61+
62+ RUN \
63+ # This changes a startup hook, which will activate the custom environment for the process
64+ echo conda activate "${env_name}" >> /usr/local/bin/before-notebook.d/10activate-conda-env.sh && \
65+ # This makes the custom environment default in Jupyter Terminals for all users which might be created later
66+ echo conda activate "${env_name}" >> /etc/skel/.bashrc && \
67+ # This makes the custom environment default in Jupyter Terminals for already existing NB_USER
68+ echo conda activate "${env_name}" >> "/home/${NB_USER}/.bashrc"
69+
70+ USER ${NB_UID}
0 commit comments