Skip to content

Commit dd9c644

Browse files
authored
Merge pull request #1078 from romainx/#1077
Fix #1077
2 parents c76996e + 5519470 commit dd9c644

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

base-notebook/test/test_container_options.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33
import time
4+
import logging
45

56
import pytest
67

8+
LOGGER = logging.getLogger(__name__)
9+
710

811
def test_cli_args(container, http_client):
912
"""Container should respect notebook server command line args
@@ -61,6 +64,37 @@ def test_gid_change(container):
6164
assert 'groups=110(jovyan),100(users)' in logs
6265

6366

67+
def test_nb_user_change(container):
68+
"""Container should change the user name (`NB_USER`) of the default user."""
69+
nb_user = "nayvoj"
70+
running_container = container.run(
71+
tty=True,
72+
user="root",
73+
environment=[f"NB_USER={nb_user}",
74+
"CHOWN_HOME=yes"],
75+
working_dir=f"/home/{nb_user}",
76+
command=['start.sh', 'bash', '-c', 'sleep infinity']
77+
)
78+
79+
LOGGER.info(f"Checking if the user is changed to {nb_user} by the start script ...")
80+
output = running_container.logs(stdout=True).decode("utf-8")
81+
assert f"Set username to: {nb_user}" in output, f"User is not changed to {nb_user}"
82+
83+
LOGGER.info(f"Checking {nb_user} id ...")
84+
command = "id"
85+
expected_output = f"uid=1000({nb_user}) gid=100(users) groups=100(users)"
86+
cmd = running_container.exec_run(command, user=nb_user)
87+
output = cmd.output.decode("utf-8").strip("\n")
88+
assert output == expected_output, f"Bad user {output}, expected {expected_output}"
89+
90+
LOGGER.info(f"Checking if {nb_user} owns his home folder ...")
91+
command = f'stat -c "%U %G" /home/{nb_user}/'
92+
expected_output = f"{nb_user} users"
93+
cmd = running_container.exec_run(command)
94+
output = cmd.output.decode("utf-8").strip("\n")
95+
assert output == expected_output, f"Bad owner for the {nb_user} home folder {output}, expected {expected_output}"
96+
97+
6498
def test_chown_extra(container):
6599
"""Container should change the UID/GID of CHOWN_EXTRA."""
66100
c = container.run(

docs/using/common.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ docker run -d -p 8888:8888 jupyter/base-notebook start-notebook.sh --NotebookApp
2323
You may instruct the `start-notebook.sh` script to customize the container environment before launching
2424
the notebook server. You do so by passing arguments to the `docker run` command.
2525

26-
* `-e NB_USER=jovyan` - Instructs the startup script to change the default container username from `jovyan` to the provided value. Causes the script to rename the `jovyan` user home folder. For this option to take effect, you must run the container with `--user root` and set the working directory `-w /home/$NB_USER`. This feature is useful when mounting host volumes with specific home folder.
26+
* `-e NB_USER=jovyan` - Instructs the startup script to change the default container username from `jovyan` to the provided value. Causes the script to rename the `jovyan` user home folder. For this option to take effect, you must run the container with `--user root`, set the working directory `-w /home/$NB_USER` and set the environment variable `-e CHOWN_HOME=yes` (see below for detail). This feature is useful when mounting host volumes with specific home folder.
2727
* `-e NB_UID=1000` - Instructs the startup script to switch the numeric user ID of `$NB_USER` to the given value. This feature is useful when mounting host volumes with specific owner permissions. For this option to take effect, you must run the container with `--user root`. (The startup script will `su $NB_USER` after adjusting the user ID.) You might consider using modern Docker options `--user` and `--group-add` instead. See the last bullet below for details.
2828
* `-e NB_GID=100` - Instructs the startup script to change the primary group of`$NB_USER` to `$NB_GID` (the new group is added with a name of `$NB_GROUP` if it is defined, otherwise the group is named `$NB_USER`). This feature is useful when mounting host volumes with specific group permissions. For this option to take effect, you must run the container with `--user root`. (The startup script will `su $NB_USER` after adjusting the group ID.) You might consider using modern Docker options `--user` and `--group-add` instead. See the last bullet below for details. The user is added to supplemental group `users` (gid 100) in order to allow write access to the home directory and `/opt/conda`. If you override the user/group logic, ensure the user stays in group `users` if you want them to be able to modify files in the image.
2929
* `-e NB_GROUP=<name>` - The name used for `$NB_GID`, which defaults to `$NB_USER`. This is only used if `$NB_GID` is specified and completely optional: there is only cosmetic effect.

0 commit comments

Comments
 (0)