I am trying to add jupyter-lab to one of my existing docker image (with R, python, and work-specific libraries) for interactive tests.
A working example is this Dockefile:
FROM my_existing_image
# Install jupyter lab (assuming python3 and pip3 already installed)
RUN pip3 install jupyterlab
# Declare port used by jupyter-lab
EXPOSE 8888
# Set default command
CMD ["jupyter", "lab", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
However, we have a shared NFS drive which we mount on all users machine in /mnt/NAS
. To access shared folders from docker containers with correct permissions, we typically start them with the following flags:
docker run -u $(id -u ${USER}):$(id -g ${USER}) -v /mnt:/mnt my_image
However, the -u
( --user
) option prevents juyter-lab to start properly and I get this error message:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py", line 528, in get
value = obj._trait_values[self.name]
KeyError: 'runtime_dir'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/jupyter-lab", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/dist-packages/jupyter_core/application.py", line 270, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py", line 663, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 1766, in initialize
self.init_configurables()
File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 1380, in init_configurables
connection_dir=self.runtime_dir,
File "/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py", line 556, in __get__
return self.get(obj, cls)
File "/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "/usr/local/lib/python3.7/dist-packages/jupyter_core/application.py", line 100, in _runtime_dir_default
ensure_dir_exists(rd, mode=0o700)
File "/usr/local/lib/python3.7/dist-packages/jupyter_core/utils/__init__.py", line 13, in ensure_dir_exists
os.makedirs(path, mode=mode)
File "/usr/lib/python3.7/os.py", line 211, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/usr/lib/python3.7/os.py", line 211, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/usr/lib/python3.7/os.py", line 211, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/usr/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.local'
I could not figure a proper way to configure my Dockerfile to get access to the drive and jupyter-lab working. We often use Rocker/Rstudio containers in the same way without any problem.
Would you have suggestions? Thank you for your help.
I got the same error message, because the container's $HOME variable was the root /
, which is not writable without sudo
.
So, for me, the solution was to set $HOME pointing to a writable directory. For example,
mkdir ./.home # make a virtual home directory
docker run \
-u $(id -u):$(id -g) -v $(pwd):$(pwd) -w $(pwd) -e HOME=$(pwd)/.home \
-it --rm --init -p 8888:8888 your_image \
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.