docker-stacks icon indicating copy to clipboard operation
docker-stacks copied to clipboard

Fall back on symlink if moving home directory fails with NB_USER is set

Open stevenstetzler opened this issue 6 years ago • 1 comments

I'm wondering if a change can be made to fall back on using a symlink when changing the name of the home directory in the docker container. The image to be changed would be jupyter/base-notebook, which would propagate along every other image to the one I am interested in jupyter/scipy-notebook.

When starting the container as root with the environment variable NB_USER set to something other than jovyan, the container will attempt to move the home directory from /home/jovyan to /home/$NB_USER in the start-up script start.sh (https://github.com/jupyter/docker-stacks/blob/master/base-notebook/start.sh#L64-L77).

This usually works, but I've run into issues running on Kubernetes on AWS (with zero-to-jupyterhub) where the home directory is mounted from an EBS-backed volume. If the above mv command gets run, it will fail with the message:

Set username to: stevenstetzler
Relocating home dir to /home/stevenstetzler
mv: cannot move '/home/jovyan' to '/home/stevenstetzler': Device or resource busy

This can be fixed by having the command fall back on doing a symlink if the move fails. https://github.com/jupyter/docker-stacks/blob/master/base-notebook/start.sh#L69 get's changed from:

mv /home/jovyan "/home/$NB_USER"

to

mv /home/jovyan "/home/$NB_USER" || ln -s /home/jovyan "/home/$NB_USER"

I haven't run into any issues with this, functionality of the docker container remains identical, there will just be two files: /home/jovyan and /home/stevenstetzler which points back there.

I am wondering if this change can be upstreamed for others who might run into this issue, or if an alternative suggestion can be made. I can open a PR if that would help.

stevenstetzler avatar Dec 13 '19 04:12 stevenstetzler

@stevenstetzler Symlinking sounds like a reasonable fallback if mv fails. If you'd like to submit a PR, we can get it reviewed and tested to merge. Thanks!

parente avatar Jan 20 '20 04:01 parente

I think this was actually fixed in https://github.com/jupyter/docker-stacks/pull/995, just forgot to close the issue.

mathbunnyru avatar Aug 20 '23 23:08 mathbunnyru