mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-10 11:32:57 +00:00
Fix conda hook to work in both terminal and Jupyter Notebook (#2047)
* Fix conda hook to work in both terminal and Jupyter Notebook * Fix hook for Jupyter Terminals * Rename startup hook to have order of precedence * Try to increase sleep * Comment making env_name default in custom_environment
This commit is contained in:
@@ -28,17 +28,16 @@ RUN "${CONDA_DIR}/envs/${env_name}/bin/python" -m ipykernel install --user --nam
|
|||||||
RUN "${CONDA_DIR}/envs/${env_name}/bin/pip" install --no-cache-dir \
|
RUN "${CONDA_DIR}/envs/${env_name}/bin/pip" install --no-cache-dir \
|
||||||
'flake8'
|
'flake8'
|
||||||
|
|
||||||
# Creating a startup hook, which will activate our custom environment by default in Jupyter Notebook
|
# Uncomment this section to activate custom environment by default
|
||||||
# More info about startup hooks: https://jupyter-docker-stacks.readthedocs.io/en/latest/using/common.html#startup-hooks
|
# Note: uncommenting this section makes "${env_name}" default both for Jupyter Notebook and Terminals
|
||||||
# You can comment this section to keep the default environment in Jupyter Notebook
|
# More information here: https://github.com/jupyter/docker-stacks/pull/2047
|
||||||
USER root
|
# USER root
|
||||||
RUN activate_custom_env_script=/usr/local/bin/before-notebook.d/activate_custom_env.sh && \
|
# RUN \
|
||||||
echo "#!/bin/bash" > ${activate_custom_env_script} && \
|
# # This changes a startup hook, which will activate our custom environment for the process
|
||||||
echo "eval \"$(conda shell.bash activate "${env_name}")\"" >> ${activate_custom_env_script} && \
|
# echo conda activate "${env_name}" >> /usr/local/bin/before-notebook.d/10activate-conda-env.sh && \
|
||||||
chmod +x ${activate_custom_env_script}
|
# # This makes the custom environment default in Jupyter Terminals for all users which might be created later
|
||||||
|
# echo conda activate "${env_name}" >> /etc/skel/.bashrc && \
|
||||||
|
# # This makes the custom environment default in Jupyter Terminals for already existing NB_USER
|
||||||
|
# echo conda activate "${env_name}" >> "/home/${NB_USER}/.bashrc"
|
||||||
|
|
||||||
USER ${NB_UID}
|
USER ${NB_UID}
|
||||||
|
|
||||||
# Making this environment default in Terminal
|
|
||||||
# You can comment this line to keep the default environment in a Terminal
|
|
||||||
RUN echo "conda activate ${env_name}" >> "${HOME}/.bashrc"
|
|
||||||
|
8
images/docker-stacks-foundation/10activate-conda-env.sh
Executable file
8
images/docker-stacks-foundation/10activate-conda-env.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (c) Jupyter Development Team.
|
||||||
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
|
# This registers the initialization code for the conda shell code
|
||||||
|
# It also activates default environment in the end, so we don't need to activate it manually
|
||||||
|
# Documentation: https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/activation.html
|
||||||
|
eval "$(conda shell.bash hook)"
|
@@ -59,8 +59,9 @@ RUN chmod a+rx /usr/local/bin/fix-permissions
|
|||||||
# Enable prompt color in the skeleton .bashrc before creating the default NB_USER
|
# Enable prompt color in the skeleton .bashrc before creating the default NB_USER
|
||||||
# hadolint ignore=SC2016
|
# hadolint ignore=SC2016
|
||||||
RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc && \
|
RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc && \
|
||||||
# Add call to conda init script see https://stackoverflow.com/a/58081608/4413446
|
# More information in: https://github.com/jupyter/docker-stacks/pull/2047
|
||||||
echo 'eval "$(command conda shell.bash hook 2> /dev/null)"' >> /etc/skel/.bashrc
|
# and docs: https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/activation.html
|
||||||
|
echo 'eval "$(conda shell.bash hook)"' >> /etc/skel/.bashrc
|
||||||
|
|
||||||
# Create NB_USER with name jovyan user with UID=1000 and in the 'users' group
|
# Create NB_USER with name jovyan user with UID=1000 and in the 'users' group
|
||||||
# and make sure these dirs are writable by the `users` group.
|
# and make sure these dirs are writable by the `users` group.
|
||||||
@@ -135,6 +136,8 @@ USER root
|
|||||||
RUN mkdir /usr/local/bin/start-notebook.d && \
|
RUN mkdir /usr/local/bin/start-notebook.d && \
|
||||||
mkdir /usr/local/bin/before-notebook.d
|
mkdir /usr/local/bin/before-notebook.d
|
||||||
|
|
||||||
|
COPY 10activate-conda-env.sh /usr/local/bin/before-notebook.d/
|
||||||
|
|
||||||
# Switch back to jovyan to avoid accidental container runs as root
|
# Switch back to jovyan to avoid accidental container runs as root
|
||||||
USER ${NB_UID}
|
USER ${NB_UID}
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ def test_start_notebook(
|
|||||||
ports={"8888/tcp": host_port},
|
ports={"8888/tcp": host_port},
|
||||||
)
|
)
|
||||||
# sleeping some time to let the server start
|
# sleeping some time to let the server start
|
||||||
time.sleep(1)
|
time.sleep(2)
|
||||||
logs = running_container.logs().decode("utf-8")
|
logs = running_container.logs().decode("utf-8")
|
||||||
LOGGER.debug(logs)
|
LOGGER.debug(logs)
|
||||||
# checking that the expected command is launched
|
# checking that the expected command is launched
|
||||||
|
Reference in New Issue
Block a user