Docker-stacks: NB_USER is not applied in docker run

Created on 26 Aug 2018  路  6Comments  路  Source: jupyter/docker-stacks

What docker image you are using?

jupyter/scipy-notebook

What complete docker command do you run to launch the container (omitting sensitive values)?

docker run \
--rm \
-it \
--name jupyter \
-p 8888:8888 \
-e NB_USER=marc \
jupyter/scipy-notebook:latest

What steps do you take once the container is running to reproduce the issue?

  1. docker run to power the container:
docker run \
--rm \
-it \
--name jupyter \
-p 8888:8888 \
-e NB_USER=marc \
jupyter/scipy-notebook:latest

The console output:
1

  1. docker exec -it jupyter /bin/bash
    console output:
    2

  2. env

console ouput:
3

  1. docker run with root user:
docker run \
--rm \
-it \
--name jupyter \
-p 8888:8888 \
-e NB_USER=marc \
--user root \
jupyter/scipy-notebook:latest

console output:
4

  1. docker exec -it jupyter /bin/bash

console output:
5

What do you expect to happen?

The user marc should be changed by joyan as documentation says.
6

What actually happens?

The start script does not apply NB_USER. I don't know if I understood something wrong reading the documentation, but I thought that something was wrong with start script and permissions set up.

Documentation Bug

Most helpful comment

Thanks @parente for your tip to specify the working directory. This was really helpful. I too could not use a custom name for NB_USER initially. But with the specification of -w flag, I can confirm that the custom user is now working for me.

Custom user
If I used a custom user (not jovyan) with the specification of the working directory

...-w /home/<myuser> jupyter

as suggested above, then it works for me. It set my working directory to /home/<myuser> and the jupyter tree opens directly at /home/<myuser>.

Mounting volumes to custom user's home
Then I also tried to mount a volume to the custom user's home by specifying the -v flag

...-w /home/<myuser> -v ~/work:/home/<myuser> jupyter

and this also worked as expected - I could see all the contents of ~/work (on my local host) inside the docker container at /home/<myuser>.

All 6 comments

The documentation is missing the key sentence that appears next to the NB_UID and other options that modify the default user:

For this option to take effect, you must run the container with --user root.

Sorry for the trouble. Happy to take a PR to update that bullet in the docs if you'd like to contribute the fix. If not, we'll get to it!

Thanks for response @parente , but if you see the point 5, If I run the the image with this:

docker run \
--rm \
-it \
--name jupyter \
-p 8888:8888 \
-e NB_USER=marc \
--user root \
jupyter/scipy-notebook:latest

then, I cannot access to the container.
Do I forget something? For me seems a bug, but I am not sure if I forget any additional config.

All of this has arisen because my goal is:

  • Run the docker image with NB_USER with the _hostname_host_.
  • Mount a directory: -v ~/myHome/directory:/home/hostname_host/work

Ah, sorry, I missed the --user root in the command before the exec. The problem with the exec in step #5 is that because the user name has changed, the working directory configured in the Dockerfile is no longer valid.

This command will work:

docker exec -it -w /home/marc jupyter /bin/bash

The start-notebook.sh script avoids this problem by adjusting the working dir for the notebook server when handling the NB_USER change, but that has no effect on the container configuration itself or other shells/ commands launched in that container.

Thanks @parente for your tip to specify the working directory. This was really helpful. I too could not use a custom name for NB_USER initially. But with the specification of -w flag, I can confirm that the custom user is now working for me.

Custom user
If I used a custom user (not jovyan) with the specification of the working directory

...-w /home/<myuser> jupyter

as suggested above, then it works for me. It set my working directory to /home/<myuser> and the jupyter tree opens directly at /home/<myuser>.

Mounting volumes to custom user's home
Then I also tried to mount a volume to the custom user's home by specifying the -v flag

...-w /home/<myuser> -v ~/work:/home/<myuser> jupyter

and this also worked as expected - I could see all the contents of ~/work (on my local host) inside the docker container at /home/<myuser>.

thanks @edesz! I tried only for execute the docker exec command and it works, but I didn't try with the run command. I think that this could be a good use case to make the PR to docs.

Docs updated by PR #723. Closing this out.

Was this page helpful?
0 / 5 - 0 ratings