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


ENTRYPOINT [“jupyter”, “lab”,"–ip=","–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

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
–name user1
-p 8888:8888
-w /home/user1
-v ~/work:/home/user1
-e NB_USER=user1
–user root

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.

One thing I noticed is that if I directly run docker stack image ( passing the -e NB_USER=user1 I am seeing NB_USER in the terminal.

Appreciate the help.


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