Skip to content

Commit

Permalink
Merge pull request #1421 from rigzba21/fix-volumes-deleted-when-enter…
Browse files Browse the repository at this point in the history
…ing-container

Fix: volumes/files deleted when bind mount to /home/jovyan
  • Loading branch information
mathbunnyru committed Aug 24, 2021
2 parents 709f675 + c7cb929 commit d782e78
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base-notebook/start.sh
Expand Up @@ -53,8 +53,9 @@ if [ "$(id -u)" == 0 ] ; then
# changing username, make sure homedir exists
# (it could be mounted, and we shouldn't create it if it already exists)
if [[ ! -e "/home/${NB_USER}" ]]; then
echo "Relocating home dir to /home/${NB_USER}"
mv /home/jovyan "/home/${NB_USER}" || ln -s /home/jovyan "/home/${NB_USER}"
echo "Copying home dir to /home/${NB_USER}"
mkdir "/home/${NB_USER}"
cp -R /home/jovyan "/home/${NB_USER}" || ln -s /home/jovyan "/home/${NB_USER}"
fi
# if workdir is in /home/jovyan, cd to /home/${NB_USER}
if [[ "${PWD}/" == "/home/jovyan/"* ]]; then
Expand Down
26 changes: 26 additions & 0 deletions base-notebook/test/test_container_options.py
Expand Up @@ -187,3 +187,29 @@ def test_group_add(container, tmpdir):
assert rv == 0 or rv["StatusCode"] == 0
logs = c.logs(stdout=True).decode("utf-8")
assert "uid=1010 gid=1010 groups=1010,100(users)" in logs


def test_container_not_delete_bind_mount(container, tmp_path):
"""Container should not delete host system files when using the (docker)
-v bind mount flag and mapping to /home/jovyan.
"""
d = tmp_path / "data"
d.mkdir()
p = d / "foo.txt"
p.write_text("some-content")

c = container.run(
tty=True,
user="root",
working_dir="/home/",
environment=[
"NB_USER=user",
"CHOWN_HOME=yes",
],
volumes={d: {"bind": "/home/jovyan/data", "mode": "rw"}},
command=["start.sh", "ls"],
)
rv = c.wait(timeout=5)
assert rv == 0 or rv["StatusCode"] == 0
assert p.read_text() == "some-content"
assert len(list(tmp_path.iterdir())) == 1

0 comments on commit d782e78

Please sign in to comment.