Commit f6224d9e authored by Quentin Yeche's avatar Quentin Yeche
Browse files

fixed incorrect handling of conda environments

No related merge requests found
Showing with 13 additions and 46 deletions
+13 -46
...@@ -8,39 +8,22 @@ ARG env_name=rs-notebooks ...@@ -8,39 +8,22 @@ ARG env_name=rs-notebooks
ADD *.ipynb /notebooks/ ADD *.ipynb /notebooks/
ADD sample.geojson /notebooks/ ADD sample.geojson /notebooks/
SHELL ["/bin/bash", "-l", "-c"]
# creating environment # creating environment
ADD environment_jupyterlab.yml ${dest_yml} ADD environment_jupyterhub_lite.yml ${dest_yml}
# this only seems to work when overring CMD with /bin/bash when runing docker run
# or with shells spawned afterwards (e.g. from jupyterlab itself)
# does not work for further RUN commands in the Dockerfile despite having used SHELL earlier
RUN conda init bash
RUN mamba init bash
RUN mamba env create --file ${dest_yml} --name ${env_name} RUN mamba env create --file ${dest_yml} --name ${env_name}
# leads to "your shell has not been properly configured despite having RUN conda init" # setting up shell to run in the correct environment
RUN echo "conda activate ${env_name}" >> ~/.bashrc SHELL ["conda", "run", "-n", "rs-notebooks", "/bin/bash", "-c"]
RUN echo "conda activate ${env_name}" >> ~/.profile
ENV ENV_NAME ${env_name}
# HOW DOES THIS TRANSFER TO JUPYTERHUB?
# setting up jupyter lab to use bash as a terminal # setting up jupyter lab to use bash as a terminal
# this ensures that the right environment is activated in the terminal # this ensures that the right environment is activated in the terminal
# should allow users to run pip installs from notebooks/jupyter lab terminal # should allow users to run pip installs from notebooks/jupyter lab terminal
# without encountering issues with different environments # without encountering issues with different environments
RUN /opt/conda/envs/${env_name}/bin/jupyter lab --generate-config && \ #RUN /opt/conda/envs/rs-notebooks/bin/jupyter lab --generate-config && \
echo 'c.NotebookApp.terminado_settings = { "shell_command": ["/bin/bash"] }' >> /root/.jupyter/jupyter_lab_config.py #RUN jupyter lab --generate-config && \
# echo 'c.NotebookApp.terminado_settings = { "shell_command": ["/bin/bash"] }' >> /root/.jupyter/jupyter_lab_config.py
# setting up default landing folder # setting up default landing folder
WORKDIR /notebooks WORKDIR /notebooks
# this should work but doesn't. conda activate from .bashrc/.profile fails CMD jupyterhub-singleuser
# so /opt/conda/envs/${ENV_NAME}/bin is not in $PATH
#CMD jupyterhub-singleuser
# this works but bypasses the conda activate issue for CMD by going into the path directly
CMD /opt/conda/envs/${ENV_NAME}/bin/jupyterhub-singleuser
...@@ -8,38 +8,22 @@ ARG env_name=rs-notebooks ...@@ -8,38 +8,22 @@ ARG env_name=rs-notebooks
ADD *.ipynb /notebooks/ ADD *.ipynb /notebooks/
ADD sample.geojson /notebooks/ ADD sample.geojson /notebooks/
SHELL ["/bin/bash", "-l", "-c"]
# creating environment # creating environment
ADD environment_jupyterlab.yml ${dest_yml} ADD environment_jupyterlab.yml ${dest_yml}
#this only seems to work when overring CMD with /bin/bash when runing docker run
#or with shells spawned afterwards (e.g. from jupyterlab itself)
# does not work for further RUN commands in the Dockerfile despite having used SHELL earlier
RUN conda init bash
RUN mamba init bash
RUN mamba env create --file ${dest_yml} --name ${env_name} RUN mamba env create --file ${dest_yml} --name ${env_name}
# leads to "your shell has not been properly configured" despite having RUN conda init # setting up shell to run in the correct environment
RUN echo "conda activate ${env_name}" >> ~/.bashrc SHELL ["conda", "run", "-n", "rs-notebooks", "/bin/bash", "-c"]
RUN echo "conda activate ${env_name}" >> ~/.profile
ENV ENV_NAME ${env_name}
# setting up jupyter lab to use bash as a terminal # setting up jupyter lab to use bash as a terminal
# this ensures that the right environment is activated in the terminal # this ensures that the right environment is activated in the terminal
# should allow users to run pip installs from notebooks/jupyter lab terminal # should allow users to run pip installs from notebooks/jupyter lab terminal
# without encountering issues with different environments # without encountering issues with different environments
RUN /opt/conda/envs/${env_name}/bin/jupyter lab --generate-config && \ #RUN /opt/conda/envs/rs-notebooks/bin/jupyter lab --generate-config && \
echo 'c.NotebookApp.terminado_settings = { "shell_command": ["/bin/bash"] }' >> /root/.jupyter/jupyter_lab_config.py RUN jupyter lab --generate-config
RUN echo 'c.NotebookApp.terminado_settings = { "shell_command": ["/bin/bash"] }' >> /root/.jupyter/jupyter_lab_config.py
# setting up default landing folder # setting up default landing folder
WORKDIR /notebooks WORKDIR /notebooks
# this should work but doesn't. conda activate from .bashrc/.profile fails CMD jupyter lab --ip 0.0.0.0 --no-browser --allow-root
# so /opt/conda/envs/${ENV_NAME}/bin is not in $PATH
#CMD jupyter lab --ip 0.0.0.0 --no-browser --allow-root
# this works but bypasses the conda activate issue for CMD by going into the path directly
CMD /opt/conda/envs/${ENV_NAME}/bin/jupyter lab --ip 0.0.0.0 --no-browser --allow-root
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment