docker-stacks
docker-stacks copied to clipboard
jupyter/base-notebook: Hardcoded PATH Environment Variable in Dockerfile
Some developers need to change the PATH Environment Variable (e.g. create their own virtual environments and registrate/add their private notebooks) You can create virtual environments (conda create ...; python -m venv ...) but the activation will fail due to the hardcoded PATH environment variable.
Solution: Remove Line 'ENV PATH=$CONDA_DIR/bin:$PATH' from Dockerfile But this will cause several problems:
- tini will not be found in ENTRYPOINT command line
- conda/jupyter commands will not be found in RUN command lines
- jupyter command will not be found during startup sequence
Workarounds:
-
Install tini from Ubuntu repository (same Version as from conda) and remove lines <'tini=0.18.0' && > and <conda list tini | grep tini | tr -s ' ' | cut -d ' ' -f 1,2 >> $CONDA_DIR/conda-meta/pinned && > from Dockerfile
-
Add <export PATH=$CONDA_DIR/bin:$PATH && > to the corresponding RUN statement sections in Dockerfile
-
Regarding the 'run-hooks /usr/local/bin/before-notebook.d' command in the start.sh script: Place a script conda_path.sh in directory /usr/local/bin/before-notebook.d containing the command 'export PATH=$CONDA_DIR/bin:$PATH'
Diff Dockerfile:
49,50d48
< build-essential binutils binfmt-support \
< tini \
70c68,69
< ENV HOME=/home/$NB_USER \
---
> ENV PATH=$CONDA_DIR/bin:$PATH \
> HOME=/home/$NB_USER \
112d110
< export PATH=$CONDA_DIR/bin:$PATH && \
120c118,119
< 'pip' && \
---
> 'pip' \
> 'tini=0.18.0' && \
121a121
> conda list tini | grep tini | tr -s ' ' | cut -d ' ' -f 1,2 >> $CONDA_DIR/conda-meta/pinned && \
133,134c133
< RUN export PATH=$CONDA_DIR/bin:$PATH && \
< conda install --quiet --yes \
---
> RUN conda install --quiet --yes \
159,163d157
<
< RUN mkdir -p /usr/local/bin/before-notebook.d && \
< printf '#!/bin/bash\n\nexport PATH=$CONDA_DIR/bin:$PATH\n\n' > \
< /usr/local/bin/before-notebook.d/conda_path.sh && \
< chmod 777 /usr/local/bin/before-notebook.d/conda_path.sh
Hello @lima4658,
Good remark and also good suggestions!
-
Install tini from Ubuntu repository (same Version as from conda) and remove lines [...]
Definitely a very good idea, I've drafted the PR #1308 to implement this change, I think it's a simplification.
-
Add <export PATH=$CONDA_DIR/bin:$PATH && > to the corresponding RUN statement sections in Dockerfile
Not sure it's a good solution, it would add too much noise in the Dockerfiles -> we have to think of a better option.
-
Regarding the 'run-hooks /usr/local/bin/before-notebook.d' command in the start.sh script: Place a script conda_path.sh in directory /usr/local/bin/before-notebook.d containing the command 'export PATH=$CONDA_DIR/bin:$PATH'
It could do the job in a cleaner way, however need to fix the problem of the conda
path in the Dockerfiles first.
Thanks.
Using a login shell could also be a solution.
Needed modifications in Dockerfile:
All notebooks:
- SHELL ["/bin/bash", "-o", "pipefail", "-l", "-c"]
Base notebook only:
-
CMD ["/bin/bash", "-l", "start-notebook.sh"]
-
Place desired flexible environment variables (CONDA_DIR, PATH, SHELL, LC_ALL, LANG, LANGUAGE ...) in a file (e.g. 00-base-notebook.sh) in directory /etc/profile.d.
Due to using a login shell the changes will be recognized.
@lima4658 I thought about this issue for a few day.
You can create virtual environments (conda create ...; python -m venv ...) but the activation will fail due to the hardcoded PATH environment variable.
Could you please give us an explicit example which doesn't work for you?
I believe some solutions won't work for us:
-
PATH=$CONDA_DIR/bin:$PATH
I agree with @romainx it adds too much noise. What's worse, it will break all dependent images. - I currently think using login shell won't work well for jupyterhub users, where they don't have access to the host machine. https://github.com/jupyter/docker-stacks/pull/1935#issuecomment-1650684172
On the other hand, does your issue happen during build time or runtime?
- If it happens during a build time, then you can set
ENV PATH
to the default value. It's a bit of hardcode, but I don't think the default path is likely to change. - If it happens during runtime, I think you can use our Startup Hooks where you can manipulate PATH as you wish.
Please, let me tell, what you think about this.
@lima4658 please, comment or reopen this issue if you still have an issue. I think having PATH changed in the Dockerfile is best for most of the users, so I don't think we'll be able to change this. I also proposed two solutions for how you can change PATH in your case.