docker-stacks
docker-stacks copied to clipboard
cannot start docker container after changing user name
What docker image(s) are you using?
base-notebook
OS system and architecture running docker image
Alpine Linux v3.11/amd64
What Docker command are you running?
See the reproducing steps
How to Reproduce the problem?
- Create a Dockerfile, and fill with these following content (change the default user name)
FROM jupyter/base-notebook:lab-3.3.0
ENV NEW_NB_USER="jupyter"
ENV NB_USER=$NEW_NB_USER \
HOME=/home/$NEW_NB_USER
USER root
RUN cd / \
&& usermod -md /home/$NB_USER -l $NB_USER jovyan
WORKDIR $HOME
USER $NB_UID
- Use this Dockerfile to build a new docker image
docker build . -t "jupyter-base-notebook-with-new-user-name"
- Start a new docker container with this docker image
docker run --net=host jupyter-base-notebook-with-new-user-name
Command output
Entered start.sh with args: jupyter lab
Expected behavior
Jupyterlab should be started successfully (like using the image jupyter/base-notebook:lab-3.2.0
)
Actual behavior
There are no error message after executing docker run
, and jupyterlab would no start.
Anything else?
I have submit a pr (#1649) before, fix the problem this issue metions. In that pr, @consideRatio mentions some questions, I try to explain them.
In the #1546 pr, the start.sh
script have add some code to check whether there are some problems with current user, group or home folder. The script would get the user id / group id of jovyan
via id
command (see the code in the below screenshot)
Then, the following code (see the code in the below screenshot) would check whether the
jovyan
user / group id equals to the current user.
But the
id
command would return a non-zero value when user name does not exist, and then the script would exit. So the following checking code would never execute, and the warn log would not be output too. I think it should ensure that the user / group id of jovyan
can be obtained. So in #1649 I have add two additional function to call id
command to avoid the main process geting a non-zero value and ensure the remain code can be executed successfully.
We actually have a way to change the username to the desired one: https://jupyter-docker-stacks.readthedocs.io/en/latest/using/common.html?highlight=NB_USER#user-related-configurations
Could you please try this?
We actually have a way to change the username to the desired one: https://jupyter-docker-stacks.readthedocs.io/en/latest/using/common.html?highlight=NB_USER#user-related-configurations
Could you please try this?
I have read this doc before, but you must use root
user to start docker container.
I think if the way I use is forbidden, there should be an error message, but now there are no error message and the jupyterlab cannot start either. This is why I think it's a bug.
In addition, in the older version, I can modify user name via the method I mentions in the issue and the jupyterlab can start successfully. But I cannot do this in the latest version.
Ok, I think you have a valid point we should either support this (and it would be nice to test it), or have a clear error message.
My quick patch for this is to have sed 's/jovyan 2/$NB_USER 2/g' -i /usr/local/bin/start.sh
in your Dockerfile
https://github.com/jupyter/docker-stacks/commit/c772e98ac794173d6ed83a08ec249038b27ca3be is probabbly the commit that broke it.
Unfortunately, our start.sh
assumes the image was built with jovyan
user.
So, I think @csurett suggestion is nice and reasonable and it should work even if we change something in start.sh.
I'm sorry it's not a beautiful solution, but our start.sh
is complicated enough (we could have created NB_BUILD_USER, then use it in start.sh in some places, but that's creating another level of complexity).