如何使用Jupyter Notebook的docker映像安装本地文件夹?

时间:2019-05-08 09:52:36

标签: docker jupyter-notebook

我在下面使用docker映像: https://hub.docker.com/r/gw000/keras-full

效果很好;但是,我想挂载本地文件夹,以便可以保存和使用本地笔记本文件。我在下面使用命令:

docker run -d -p 8888:8888 -v c:/Jupyter:/srv gw000/keras-full

命令成功运行;但是,我无法创建新的笔记本,因为在下面出现错误消息:

  

权限被拒绝:Untitled.ipynb

我尝试了以下操作:

  • 我已授予Jupter文件夹(“所有人”用户)“完全”访问权限
  • 我已经尝试过从提交的第一个答案中获取命令
  • 我已经尝试过使用普通和管理模式的Firefox和Edge浏览器

Docker映像要求使用密码“ keras”,如下所示:

docker run -d -p 8888:8888 -v $(pwd):/srv gw000/keras-full

我无法弄清楚如何同时使用映射文件夹和密码。

我的环境:

  • Windows 10专业版
  • Docker桌面

Docker日志:

[I 10:35:10.240 NotebookApp] Writing notebook server cookie secret to /home/user/.local/share/jupyter/runtime/notebook_cookie_secret
[W 10:35:10.844 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 10:35:13.007 NotebookApp] jupyter_tensorboard extension loaded.
[I 10:35:13.009 NotebookApp] Serving notebooks from local directory: /srv
[I 10:35:13.009 NotebookApp] 0 active kernels
[I 10:35:13.009 NotebookApp] The Jupyter Notebook is running at:
[I 10:35:13.009 NotebookApp] http://[all ip addresses on your system]:8888/?token=...
[I 10:35:13.009 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 10:35:18.003 NotebookApp] 302 GET / (172.17.0.1) 0.50ms
[I 10:35:18.015 NotebookApp] 302 GET /tree? (172.17.0.1) 0.97ms
[I 10:35:21.563 NotebookApp] 302 POST /login?next=%2Ftree%3F (172.17.0.1) 1.40ms
[I 10:35:26.118 NotebookApp] Creating new notebook in
[I 10:35:26.151 NotebookApp] Writing notebook-signing key to /home/user/.local/share/jupyter/notebook_secret
[W 10:35:26.166 NotebookApp] 403 POST /api/contents (172.17.0.1): Permission denied: Untitled.ipynb
[W 10:35:26.166 NotebookApp] Permission denied: Untitled.ipynb
[W 10:35:26.167 NotebookApp] 403 POST /api/contents (172.17.0.1) 49.41ms referer=http://localhost:8880/tree?
[I 10:36:38.981 NotebookApp] 302 GET /tree (172.17.0.1) 1.66ms
[I 10:36:42.373 NotebookApp] 302 POST /login?next=%2Ftree (172.17.0.1) 1.12ms
[I 10:36:45.459 NotebookApp] Creating new notebook in
[W 10:36:45.475 NotebookApp] 403 POST /api/contents (172.17.0.1): Permission denied: Untitled.ipynb
[W 10:36:45.476 NotebookApp] Permission denied: Untitled.ipynb
[W 10:36:45.476 NotebookApp] 403 POST /api/contents (172.17.0.1) 18.42ms referer=http://localhost:8880/tree
[I 10:37:19.390 NotebookApp] Creating new notebook in
[W 10:37:19.410 NotebookApp] 403 POST /api/contents (172.17.0.1): Permission denied: Untitled.ipynb
[W 10:37:19.410 NotebookApp] Permission denied: Untitled.ipynb
[W 10:37:19.411 NotebookApp] 403 POST /api/contents (172.17.0.1) 21.50ms referer=http://localhost:8880/tree

2 个答案:

答案 0 :(得分:1)

一种选择是使用-u例如将您的本地用户映射到docker用户

docker run -u $(id -u):$(id -u) ... 

答案 1 :(得分:0)

第一:

docker run -d -p 8888:8888 -v $(pwd):/srv gw000/keras-full

以上命令是使用“ pwd ” Linux命令(如打印当前目录中的“ pwd ”)将当前目录挂载到文件夹“ / srv ”)。与更改密码无关。

其次:

在我看来,您正在使用文件夹“ c:/ Jupyter ”将其装入容器文件夹。您可能需要以管理员身份运行Docker,或者可以从不需要管理员权限的其他驱动器进行挂载,例如d:/。 因此,您可以尝试:

docker run -d -p 8888:8888 -v d:/Jupyter:/srv gw000/keras-full


https://hub.docker.com/r/gw000/keras-full/dockerfile看到 Dockerfile 后,我认为您的Docker正在将 / srv 挂载为“ root ”用户,并且该服务是在用户“ 用户”下运行,因此您必须通过docker exec -it <name_or_id_of_container> bash执行到容器中并运行chown -R user:user /home/user /srv