Custom docker image from docker-stacks image

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

You’ve setup an ENTRYPOINT which will override the default startup scripts that amongst other things handle renaming the user: