如何 运行 使用奇点图像的 jupyter notebook?

How to run a jupyter notebook using a singularity image?

我构建了一个包含最新 anaconda 版本的奇点图像 (jupyter.sif),我想将其用于 运行 jupyter notebook。

我想要运行这样的东西:

singularity exec \
  --bind /path/outside/image/:/path/inside/image/ \
  jupyter.sif jupyter notebook \
    --notebook-dir=/path/to/dir --no-browser --ip=127.0.0.1

本质上,只需启动一个普通的 jupyter notebook,它将使用 python 版本和安装在奇点图像中的软件包。理想情况下,notebook 将读取和写入图像外的文件(因此我指定绑定路径的原因)。

但是,当我 运行 执行上述命令时,出现以下错误:

> Traceback (most recent call last):   File
> "/opt/conda/lib/python3.7/site-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 "/opt/conda/bin/jupyter-notebook", line 11, in <module>
>     sys.exit(main())
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/jupyter_core/application.py",
> line 266, in launch_instance
>     return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/config/application.py",
> line 657, in launch_instance
>     app.initialize(argv)
> 
>   File "<decorator-gen-7>", line 2, in initialize
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/config/application.py",
> line 87, in catch_config_error
>     return method(app, *args, **kwargs)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/notebook/notebookapp.py", line
> 1626, in initialize
>     self.init_configurables()
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/notebook/notebookapp.py", line
> 1319, in init_configurables
>     connection_dir=self.runtime_dir,
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/traitlets.py", line
> 556, in __get__
>     return self.get(obj, cls)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/traitlets.py", line
> 535, in get
>     value = self._validate(obj, dynamic_default())
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/jupyter_core/application.py",
> line 99, in _runtime_dir_default
>     ensure_dir_exists(rd, mode=0o700)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/jupyter_core/utils/__init__.py",
> line 13, in ensure_dir_exists
>     os.makedirs(path, mode=mode)
> 
>   File "/opt/conda/lib/python3.7/os.py", line 211, in makedirs
>     makedirs(head, exist_ok=exist_ok)
> 
>   File "/opt/conda/lib/python3.7/os.py", line 211, in makedirs
>     makedirs(head, exist_ok=exist_ok)
> 
>   File "/opt/conda/lib/python3.7/os.py", line 221, in makedirs
>     mkdir(name, mode)
> 
> OSError: [Errno 30] Read-only file system: '/run/user'

我认为这是因为笔记本正试图在图像中写入内容,因为我不 运行 将图像作为 sudo(我不想这样做)而且我也不想执行图像时指定--writable(也不想这样做),它抱怨无法在图像内写入。

有没有办法“告诉”图像在我的主目录而不是图像内部读写文件?

谢谢

我刚遇到同样的问题,这似乎已经解决了我的问题:将容器内的 /run/user 映射到外部的工作目录(或您选择的目录)。对于您的情况,可能意味着:

singularity exec --bind /path/outside/image/:/path/inside/image/ --bind $PWD:/run/user jupyter.sif jupyter notebook --notebook-dir=/path/to/dir --no-browser --ip=127.0.0.1

当 运行 像这样时,在我的例子中创建了一个文件夹 1000

这适用于奇点实例,例如:

   singularity instance.start --writable --contain --bind shared:/shared sandbox/ jupyter

有效,但这是另一种不需要绑定安装的解决方案。 运行 unset XDG_RUNTIME_DIR 在 运行 jupyter notebook 之前,这个错误就会消失。