thomas
March 4, 2021, 11:33am
1
I am trying to install a base image from docker-stacks and add some extensions on top of it , so that all users have the extensions available. In this regard I created a simple docker file for testing the concept
FROM jupyter/base-notebook
USER root
RUN apt update
RUN apt install --yes git
RUN jupyter labextension install @jupyterlab /git
RUN pip install jupyterlab-git==0.30.0b1
RUN jupyter server extension enable --py jupyterlab_git
USER $NB_USER
EXPOSE 8888
ENTRYPOINT [“jupyter”, “lab”,“–ip=0.0.0.0”,“–allow-root”]
Running the image for user1 and user2 I am able to point to their respective mount location but when I try terminal in the JupyterLab it is always ‘jovyan’ (if --user root not given) or ‘root’.
(base) jovyan@17657cc83f3d:/home/user1$ whoami
jovyan
Is it possible to switch to “user1” and “user2” when running the containers.
I have tried the following command but NB_USER does not seem to apply .
docker run
–rm
-it
–name user1
-p 8888:8888
-w /home/user1
-v ~/work:/home/user1
-e NB_USER=user1
-e CHOWN_HOME=yes
–user root
testimg/jupyter-basic:latest
The user1 and user2 are actual unix users (useradd) on an AWS EC2 instance. I would like to have users1 pointed (user, mount etc) to when running the container is executed for user1 and similarly for user2.
Edit
One thing I noticed is that if I directly run docker stack image (https://github.com/jupyter/docker-stacks ) passing the -e NB_USER=user1 I am seeing NB_USER in the terminal.
Appreciate the help.
regards
manics
March 6, 2021, 7:17pm
2
You’ve setup an ENTRYPOINT
which will override the default startup scripts that amongst other things handle renaming the user:
We also have a corresponding issue in the docker-stacks repo.
opened 01:18PM - 12 Nov 21 UTC
type:Enhancement
**What docker images this feature is applicable to?**
- `jupyter/base-noteboo… k`
- Notebooks that use startup hooks to configure the environment
**What changes do you propose?**
Split `start-notebook.sh` or `start.sh` into a script that does the environment setup in an ENTRYPOINT, and a script that does the actual notebook startup in CMD.
Originally suggested in https://github.com/jupyterhub/zero-to-jupyterhub-k8s/pull/2138#issuecomment-828291826
**How does this change will affect users?**
`start-notebook.sh` calls `start.sh` which handles a lot of setup in the Jupyter environment, including:
- Running setup hooks such as for setting environment variables
https://github.com/jupyter/docker-stacks/blob/8dfdbfd3a3370ec138a7b85ae42422de8da3ca1b/base-notebook/start.sh#L44
- Customising user names and IDs when started as root
https://github.com/jupyter/docker-stacks/blob/8dfdbfd3a3370ec138a7b85ae42422de8da3ca1b/base-notebook/start.sh#L46-L51
Since `start-notebook.sh` is set as the CMD if someone passes any arguments when running the Docker container all this setup is ignored. For example
`docker run -e NB_UID=12345 -u 0 jupyter/base-notebook jupyter-lab --debug`
should change the UID from the default `1000` to `12345`, but since the startup scripts aren't run this leads to an error (can't be run as root). Instead you must run
`docker run -e NB_UID=12345 -u 0 jupyter/base-notebook start.sh jupyter-lab --debug`
A concrete example of where this is a problem for users is in the pyspark notebook- it isn't obvious to a user that the pyspark environment is setup by a startup script rather than being baked into the Dockerfile.
- https://github.com/jupyter/docker-stacks/blob/8dfdbfd3a3370ec138a7b85ae42422de8da3ca1b/pyspark-notebook/Dockerfile#L48
- https://discourse.jupyter.org/t/pyspark-library-is-missing-from-jupyter-pyspark-notebook-when-running-with-jupyterhub-zero-to-jupyterhub-k8s/8450
Note we're working around this in JupyterHub 2.0 and Z2JH 2.0 with a breaking change: https://github.com/jupyterhub/zero-to-jupyterhub-k8s/pull/2449
Instead of specifying `jupyterhub-singleuser` as the CMD when running the image we'll use the image's default CMD, but I think this change is still generally helpful.
If you want to improve our images, it would be an awesome contribution, because I’ve seen many people overriding CMD and then having similar issues.